I did build derby using apache ant. So how can I create database tables which can be run using ant.
ANT's standard SQL task allows you to create tables as normal:
<target name="create-table">
<sql print="true" failOnConnectionError="true"
driver="${db.driver}"
url="${db.url}"
userid="${db.user}"
password="${db.pass}">
CREATE TABLE customer
(First_Name char(50),
Last_Name char(50),
Address char(50),
City char(50),
Country char(25),
Birth_Date datetime);
</sql>
</target>
Personally, I use liquibase to manage my database schemas:
http://www.liquibase.org/manual/ant
Related
I need to develop an ANT script that reads a directory content. The files in this directory are numbered along with its name. I have to find the largest numbered file in this directory and return its name and the number.
For example:
>> ls
patch-aaa-050.jar
patch-aaa-051.jar
patch-aaa-052.jar
patch-aaa-053.jar
patch-aaa-054.jar
patch-aaa-055.jar
I need to echo out: Latest patch is patch-aaa-055: Patched level: 55
Although this is a very easy task in Bash, PowerShell or Python. I am a bit clueless in ANT. I have checked out dirset Type and fileset Type. These types are able to list the directories but parsing the file names are overwhelming for me. The design is to run only with ANT, so I am limited to use that tool.
Thanks
Use resource collection path combined with basename and script task, f.e.:
<project>
<path id="foo">
<last>
<sort>
<fileset dir="C:/WKS/temp" includes="*.jar"/>
</sort>
</last>
</path>
<basename file="${toString:foo}" property="foobar"/>
<script language="javascript">
var a = project.getProperty('foobar').split('.')[0];
var b = project.getProperty('foobar').split('-')[2].split('.')[0];
print ('Latest patch is ' + a + ': Patched level: ' + b);
</script>
</project>
There are also other possibilities for sort, see ant manual
I have two ant files say antFile1.xml and antFile2.xml on windows and linux machine respectively.
antFile1.xml
<target name="executeOnLinux">
<sshexec
host="${remote.host.ip}"
username="${remote.user.id}"
password="${remote.user.ssh.password}"
command="ant -f antFile2.xml 'linuxAntTarget'"
trust="true"/>
</target>
antFile2.xml
<target name="linuxAntTarget">
<input message="Enter application edition number" addproperty="editionNo"/>
<echo message="${editionNo}"/>
</target>
When I execute the the target named "executeOnLinux" from antFile1.xml from my, it connects to the linux machine and starts executing the "linuxAntTarget" from antFile2.xml file. But, as soon as it reaches to the the point where user input is required keeps waiting since I am not able to pass the input. My question is how can I pass the value to it? Is this even possible or there is any other better way of doing it?
Since Ant 1.9.4, the sshexec task provides a useSystemIn attribute:
Whether to pass the current standard input to the remote process, defaults to false
You may also try the input attribute from the same task:
A file from which the executed command's standard input is taken. This attribute is mutually exclusive with the inputstring and inputproperty attributes.
When executing more than one command via commandResource, input will be read for each command. since Ant 1.8.0
I am learning build.xml and am confused by the following code:
<macrodef name="a-test">
<attribute name="port" default="${PORT}"/> #1
<junit printsummary=...
<env key="PORT" value="#{port}" /> #2
...
when I run java with commandLine including -DPORT=8080 and then in java code I get port value 8080 by calling
String port = System.getenv(PORT).
What is the above build.xml doing? So far I know $ is to represent a property while # is to represent an attribute. Besides, the above code is the only place where PORT and port appear. What happens here so that port value are finally obtained in java code? Thanks.
The other question, what is the difference btw. using "env key" and using "sysproperty"? according to http://etutorials.org/Programming/Java+extreme+programming/Chapter+3.+Ant/3.6+Passing+Arguments+to+a+Buildfile/
sysproperty can be use to parse argument -D to java code, while env key is used to do the same thing right? Thanks.
Is there any detailed document about build.xml? the one I google from internet describer things so briefly.
What you see is macrodef in ant. There will be another place in build.xml(or other build.xml) where this is called by like
<a-test port=<value> ..
The FTP task in ant allows you to list a given directory using syntax as follows:
<ftp action="list"
server="ftp.apache.org"
userid="admin"
password="${password}"
listing="c:\\temp\\listing-temp.txt">
<fileset>
<include name="response/*.zip"/>
</fileset>
</ftp>
The Groovy Syntax is:
ant.ftp(
action:"list",
server:"ftp.apache.org",
userid:"admin",
password:"$password",
verbose:false,
listing:"c:\\temp\\listing-temp.txt"){
fileset(dir:"") { include(name:"response/*.zip") }
}
The SCP Task is primarly used when needing to work over the SFTP protocol. However, I don't see any mechanism to list over SFTP using the SCP task. Is there a known technique to perform a listing using the scp task? The only alternative I have right now is to pull the files down as a 'listing'. I would really like to just list the contents and avoid the overhead of pulling the files down.
ant.scp(
file: "aUserID#sftp.apache.org:$path/*.zip",
toDir: "C:\\dev\\tmp",
password: "$password",
trust: 'true',
verbose: "false",
sftp: "true")
I've added the future-rollback tag to my ant script. What i want to do (and I think future-rollback is what Im looking for) is to generate an sql rollback script, but without executing it (rollback script must be delivered with sql scripts is the requirement from my client).
My changelog file has many changesets, some of which contain the <sqlFile> tag.
For example:
<databaseChangeLog ...>
<include file="latest/somesqlprocedure.xml" relativeToChangelogFile="true"/>
</databaseChangelog...>
Where the latest/somesqlprocedure.xml has an sqlFile tag.
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">
<sqlFile path="${changelog.dir}/latest/myprocedure.sql" splitStatements="false" />
</changeSet>
</databaseChangeLog>
When I run the ant script, I get the following error
liquibase.exception.ChangeLogParseException:
Invalid Migration File: <sqlfile
path=${changelog.dir}/latest/myprocedure.sql>
- Could not find file
Does anyone has an idea of whats going on ?
This is a snippet of the build.xml file
<target name="db-future-rollback" depends="init">
<rollbackFutureDatabase
changeLogFile="${db.changelog.file}"
driver="${database.driver}"
url="${database.url}"
username="${database.username}"
password="${database.password}"
outputfile="${database.rollback.dir}"
promptOnNonLocalDatabase="${prompt.user.if.not.local.database}"
classpathref="project.classpath"
>
</rollbackFutureDatabase>
</target>
Thanks in advance.
The problem may be coming from using an absolute path in your sqlFile, rather than a classpath-relative path. The classpath relative path was what was originally supported in liquibase and is still better tested. The absolute path option was added recently, and the futureRollbackSql code may have not been patched to support it.
Can you try the sqlFile using a relative path?
As a side note, the relative path option is generally better because the filename is used in the databasechangelog table to note which changeSets have ran. If you use an absolute path, the entire path is stored and if you try to re-run the changelog from a different path (or running against the same database from a different machine), liquibase will think it is a different changeSet and try to re-run it.