nAnt Deleting files older than 7 days old - nant

I would like to create a target that cleans log files older than 7 days old in a specific folder. I get an error when I try to put in a "date" element inside a fileset. How can I go about this?
<delete>
fileset basedir="${StageIISRoot}/MySite/App_Data/ErrorLog">
<date datetime="${datetime::now() - timespan::from-days(7)}" when="before"/>
<include name="*.xml" />
</fileset>
</delete>

I don't see any documentation for using the "date" element. You might consider something like this:
<fileset id="thelogs" basedir="${StageIISRoot}/MySite/App_Data/ErrorLog">
<include name="*.xml" />
</fileset>
And then reference that fileset later in a loop that checks the file date and deletes:
<foreach item="File" property="filename">
<in>
<items refid="thelogs" />
</in>
<do>
<if test="${timespan::get-days(datetime::now() - file::get-last-write-time(filename)) >= 7}">
<delete file="${filename}" />
</if>
</do>
</foreach>

What about something like:
<tstamp>
<format property="last.week" pattern="MM/dd/yyyy hh:mm" locale="en,UK" offset="-7" unit="day"/>
</tstamp>
<echo>Delete backups before ${last.week}</echo>
<delete>
<fileset dir="${dst.dir}">
<date datetime="${last.week}" when="before"/>
</fileset>
</delete>
It seems to work for me :-)

Related

Add Xom to managed URI In res

I am Working on ILOG.Currently I am using an Ant script for deploying ruleapp to res.My Problem is when I am deploying it is working fine but I want to add xom automatically to " ADD Managed URI" tab present in res. xom is getting attached to ruleapp but i want to get it attached to managed uri section.
Thanks in advance.
Have you tried this way - Got it from IBM Help.I have not tried it, but looks like, it should work. ( IBM ODM.8.0.1)
<target name="deployruleappwithxom">
<res-deploy hostname="${hostname}" portnumber="${portnumber}" webapp="${webapp}" userid="${userid}" password="${password}" file="my-ruleapp.jar">
<xompath rulesetpath="/MyRuleApp/MyRuleset">
<fileset dir="${lib}">
<include name="**/myxom.jar" />
</fileset>
</xompath>
<xompath rulesetpath="/AnotherRuleApp/AnotherRuleset">
<fileset dir="${otherlib}">
<include name="**/otherxom.jar" />
</fileset>
</xompath>
</res-deploy>
</target>
if you just looking for managing xomuri property, you can try this.
<target name="runloanvalidation">
<res-deploy-xom
hostname="localhost"
portnumber="9080"
webapp="res"
userid="resAdmin"
password="resAdmin"
jarMajorVersion="false"
libName="person"
outputRulesetProperty="ruleset.managedxom.uris">
<xompath>
<fileset dir="hello">
<include name="*.jar"/>
</fileset>
</xompath>
</res-deploy-xom>
<echo message="Resulting property: ${ruleset.managedxom.uris}"/>
</target>
And for more information, you can visit this.
http://www-01.ibm.com/support/knowledgecenter/#!/SSQP76_8.6.0/com.ibm.odm.dserver.rules.ref.res/ant_tasks/con_ant_res_deploy_xom.html

Ant search in text file some text expression

Ant search in text file some text expression, if it NOT found I try to delete file that txt was. So my code in Ant is down, but I don't know how put NOT correctly
<target name="ifDelete">
<if>
<length when="greater" length="0">
<fileset file="MyText.txt">
<!--containsregexp negate="true"-->
<containsregexp expression="findME" />
<!--/containsregexp-->
</fileset>
</length>
<then>
<delete includeemptydirs="true">
<fileset dir="FileIgonnaDelete">
</fileset>
</delete>
</then>
</if>
</target>
To search and delete - means seek and destroy - files in a fileset that do not contain a specific text, use something like :
<delete verbose="true">
<fileset dir="rootdir/to/search" includes="**/*.txt">
<not>
<contains text="findMe"/>
</not>
</fileset>
</delete>
you may use one or more nested resource collections (fileset, dirset ...) within delete.
see Ant manual delete, fileset and selectors for details.

Phing: get a filename without the extension

Given a Phing loop such as this
<target name="lessc">
<exec command="lessc ${absolute-filename}" logoutput="false" output="${project.basedir}/public/assets/css/libraries/${filename}" />
</target>
<target name="build-in-loop">
<foreach param="filename" absparam="absolute-filename" target="lessc">
<fileset dir="${project.basedir}/assets/less/libraries/">
<include name="*.less"/>
</fileset>
</foreach>
</target>
In target lessc, how can I extract the file name without extension from the variable absolute-filename? In the example above, the output file will have the extension .less - obviously not what I need.
I know there is a task made for less, and that I could extend Phing to support this specific operation, but I would like to know first if Phing basically allows simple string manipulation on variables.
Found the answer, not sure if it's the best solution, but works for me:
just need to use the mapper tag
<mapper type="glob" from="*.less" to="*"/>
in the foreach loop, like this:
<target name="build-in-loop">
<foreach param="filename" absparam="absolute-filename" target="lessc">
<fileset dir="${project.basedir}/assets/less/libraries/">
<include name="*.less"/>
</fileset>
</foreach>
</target>
At this point, in the variable ${filename} in the target task there will be the filename without extension.

run nunit tests with TestCase Attribute from nant

i was using this nant task for my nunit tests.
<nunit2 failonerror="false">
<formatter usefile="true"
outputdir="build"
type="Xml"
extension=".xml"/>
<test>
<assemblies>
<include name="Build/*.Tests.dll"/>
</assemblies>
<references >
<include name="Tools/**/*.dll"/>
<include name="Build/*.dll"/>
</references>
</test>
</nunit2>
It had the nice benefit that I could use it in multiple projects without changing anything. The problem is that it seems to be ignoring the TestCase and ExpectectException attributes on some of my tests causing them to fail. I've seen the suggestion to use the exec task to call nunit-console.exe, but then I have to specify all of the test dll's individually. Which means I can no longer use it in all of my projects without having to edit it. I'd all so have to edit it any time I add a test project to one of my solutions.
Is there any way to get the best of both worlds?
You can use <foreach> to run your tests:
<foreach item="File" property="test-assembly">
<in>
<items>
<include name="${binaries-dir}/*" />
</items>
</in>
<do>
<exec program="${nunit.exe}" workingdir="${binaries-dir}"
managed="true">
<arg value="/nologo" />
<arg value="${test-assembly}" />
</exec>
</do>
</foreach>

In nant, how to delete contents of a directory, but not the directory itself?

Suppose I were scripting a deployment using nant on a Windows server to a file share: \\server\share. I want a nant script to delete all files from the share then copy in new files.
I have this code to delete the files, but I'm getting an error that it can't delete "\server\share". But I didn't want to delete the share, just the contents in it.
<delete>
<fileset basedir="\\server\share">
<include name="**/**" />
</fileset>
</delete>
Output:
BUILD FAILED
D:\code\xxx\xxx.deploy(177,8):
Cannot delete directory '\\server\share'.
Access to the path '\\server\share' is denied.
If I modified it to instead delete contents of a directory in the share, say \\server\share\somedir, it'll delete "somedir" without error. But still, I didn't want to delete the dir, just the contents. Is there a way?
This works for me - no workarounds required:
<delete>
<fileset basedir="\\server\share">
<include name="**\*" />
</fileset>
</delete>
You could introduce an "exclude" tag and exclude a dummy file. That'll leave the root folder intact.
I'm using the following:
<target name="clean">
<delete>
<fileset basedir="${DeployTo}">
<include name="**/*" />
<exclude name="**/aspnet_client/**" />
</fileset>
</delete>
</target>
Taking cue from nsr81, I was able to come up with this workaround that works for me:
<touch file="${DeployTo}/deleteme" />
<delete>
<fileset basedir="${DeployTo}">
<include name="**/**" />
<exclude name="deleteme" />
</fileset>
</delete>
<delete file="${DeployTo}/deleteme" />