Can ant replace task just deal with files after a timestamp? - ant

The ant replace task is not like copy task which have a overwrite property, copy task can copy files that modifytime is changed.
How can I make replace task just deal with files be changed in copy task?
or save a timestamp somewhere, let replace task just deal with files which modifytime is after the timestamp.

Try this :
<replace dir="${dir}" value="that" token="this">
<include name="**/*.txt"/>
<date datetime="${timestamp}" when="before"/>
</replace>
More infos :
http://ant.apache.org/manual/Types/fileset.html
http://ant.apache.org/manual/Types/selectors.html#dateselect
http://ant.apache.org/manual/Tasks/replace.html

Related

How to search for a file in a directory and read its names and print out largest numbered file using Ant?

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

Need to run Jtest by using an ant script...any example?

Need to run Jtest by using an ant script...any example ?
I have done this so far
<target name="test">
<jtest config="/Carts Static Analysis.properties" localsettings="/ApplicationCore.jtest/scripts/build.properties"
publish="false" showdetails="false" nobuild="true"
report="c:/reports" workspace="C:/">
<resource name="EC"/>
</jtest>
</target>
</project>
But I get an error that "Failed to create task or type jtest. Any suggestions ?
Did you check Parasoft web page :
http://build.parasoft.com/docs/overview.html ?

How to list a directory using ANT's SCP task over SFTP?

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")

Removing comment in ini file writen by ant when updating the ini file

I have an ant file which updates the data in ant file due this ini file gets updated and at the top it has a comment as follows
#Thu, 07 Jul 2011 06:54:54 -0500
I don't want this comment as i am accessing this file by php using parse_ini. Due to this comment i get an failure
Comments starting with '#' are deprecated in build.ini on line 1
so is there any way so that i will not get the comment in ini file.
Thanks.
EDIT:
<propertyfile file="build.ini">
<entry key="build-number" type="int" operation="+" value="1" />
</propertyfile>
this updates my ini file build-number by +1
Martin's comment points you to a way to remove comments using replaceregexp. (I was about to show you a similar idea but using move, filterchain and striplinecomments. But the replaceregexp is more compact.)
The other suggestion I have is that since you are editing ini files, maybe you should use a task dedicated to that, rather than using the PropertyFile task. There is an IniFile taks in ant-contrib might do the job.
If the replaceregexp doesn't work for you because your file has other # comments in it and you only want to remove that top line, then try this:
<target name="test">
<propertyfile file="test.properties">
<entry key="key" value="value"/>
</propertyfile>
<move file="test.properties" tofile="test.properties.tmp">
<filterchain>
<headfilter lines="-1" skip="1"/>
</filterchain>
</move>
<move file="test.properties.tmp" tofile="test.properties"/>
</target>
Output:
$ cat test.properties
one=1
# existing comment
$ ant
Buildfile: C:\tmp\ant\build.xml
test:
[propertyfile] Updating property file: C:\tmp\ant\test.properties
[move] Moving 1 file to C:\tmp\ant
[move] Moving 1 file to C:\tmp\ant
BUILD SUCCESSFUL
Total time: 0 seconds
$ cat test.properties
one=1
# existing comment
key=value

liquibase future rollback error with sqlFile tag: File not found

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.

Resources