NAnt include/exclude pattern to include root bin folder but not child bin folders - nant

How can I craft up a NAnt include/exclude pattern to include the root /bin directory and its files, but exclude bin directories that are children of other directories?
<target name="createArtifacts">
<copy todir="${destdir}" includeemptydirs="false">
<fileset basedir="${sourcedir}">
<include name="**" /> <!-- this will get the root \bin folder -->
<exclude name="**\bin\*.pdb" />
<exclude name="**\bin\*.xml" />
...
</fileset>
</copy>
</target>
I want this to exclude any bin folder that is not the root bind folder:
<exclude name="\**\bin\" />
But it ends up removing the root bin as well.

You have been very close to the answer. You should just add an asterisk as a very first character in the exclude pattern. Taking your sample, this will loot like this:
<target name="createArtifacts">
<copy todir="${destdir}" includeemptydirs="false">
<fileset basedir="${sourcedir}">
<include name="**" />
<exclude name="*\**\bin\*.pdb" />
<exclude name="*\**\bin\*.xml" />
...
</fileset>
</copy>
</target>
That first asterisk basically means "we don't want to take first-level folder into consideration".

Related

How do I delete a folders that match pattern in phing

I have a build_ folders in my directory like build_10320 or build_10321.
I need to write a target clean that deletes such a folder.
I am trying doing this
<target name="clean">
<echo msg="clean directory ./build_" />
<delete includeemptydirs="true" verbose="true" failonerror="false" >
<fileset dir="./">
<include name="./build_*" />
</fileset>
</delete>
</target>
But this doesn't work. Kindly help.
Phing still doesn't have the <dirset> feature working (which would be the natural choice). You can however make this work using <exec> & the relevant command for deleting files from your operating system.
For linux:
<exec command = "rm -rf ./build_*" passthru = "true" />
A <fileset> returns, as the name suggests, only files.
There is an undocumented <dirset> type that unfortunately cannot be used with <delete> at the moment.
With Phing 3.x you can use <dirset> inside the <delete> task.
<project name="delete-with-dirset" default="clean" basedir=".">
<target name="clean">
<echo msg="clean directory ./build_" />
<delete includeemptydirs="true" verbose="true" failonerror="false">
<dirset dir="./">
<include name="./build_*" />
</dirset>
</delete>
</target>
</project>

Creating an ant task interleaving .java and .class files in a .jar?

I created the java project in Eclipse with separate src and bin folders. Now I want a .jar which has them combined in the same folder, just like .jardesc does. I created an ant script which looks like this:
<project name="build-jar" default="build-jar" basedir=".">
<target name="build-jar">
<jar destfile="test.jar"
basedir="."
includes="**/*.java **/*.class"
update="true"
/>
</target>
</project>
But this will create a .jar with bin/ and src/ folders. I want the top level folders all to be the actual packages already and the .class files interleaved with the .java files. How can I achieve that?
EDIT: Current non-working, modified version:
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-jar" default="build-jar">
<target name="build-jar">
<jar destfile="test.jar" update="true">
<fileset dir="src">
<include name="**/*.java"/>
</fileset>
<fileset dir="bin">
<include name="**/*.class"/>
</fileset>
</jar>
</target>
</project>
How about jar up both directories at once using fileset?
<jar destfile="test.jar" update="true">
<fileset dir="src">
<include name="**/*.java"/>
</fileset>
<fileset dir="bin">
<include name="**/*.class"/>
</fileset>
</jar>

How to compile GWT project to jar file and add it to another GWT project?

I have Three GWT projects. 2 common GWT(Bootstrap & Data Transfer Objects) projects, it doesnt contain any UI part. So, I want to compile these two projects and create jar and want to include it in third GWT project. I have done in Eclipse[Project->Export->Jar file]. It works fine. I want do it command line or through ant build.xml. Please if you know anyone, can you help on this.
We have a similar case and here is the target we use for building an external jar for our task engine. This will build you a jar from command line that can be included in other projects. In our case we have a large project that contains all of our domain objects and some services. We wanted to include this into our task engine.
<target name="taskengine-jar" depends="enhance">
<mkdir dir="build" />
<mkdir dir="build/META-INF"/>
<copy todir="build/META-INF">
<fileset dir="src/META-INF">
<include name="persistence.xml" />
<include name="server.properties" />
<include name="crypto.properties" />
<include name="sqlDrivers.xml" />
</fileset>
</copy>
<jar destfile="taskengine-jobs.jar">
<fileset dir="war/WEB-INF/classes">
<include name="com/hp/vf/server/**" />
<include name="com/hp/vf/shared/**" />
</fileset>
<fileset dir="build">
<include name="META-INF/**" />
</fileset>
<zipgroupfileset dir="war/WEB-INF/lib">
<include name="axis2.jar" />
<include name="javamail-1.4.4.jar" />
<include name="commons-pool-1.6.jar" />
<include name="openjpa-all-2.2.0.jar" />
<include name="commons-logging-adapters-1.1.1.jar" />
<include name="commons-logging-api-1.1.1.jar" />
<include name="commons-vfs2-2.0.jar" />
<include name="postgresql-9.0-801.jdbc4.jar" />
<include name="poi-3.8-beta5-20111217.jar"/>
<include name="poi-ooxml-schemas-3.8-beta5-20111217.jar"/>
<include name="poi-ooxml-3.8-beta5-20111217.jar"/>
<include name="itext-2.1.7.jar"/>
<include name="REngine.jar" />
<include name="Rserve.jar" />
<include name="jsoup-1.6.1.jar" />
<include name="jfreechart-1.0.13.jar" />
<include name="jcommon-1.0.16.jar" />
</zipgroupfileset>
<fileset dir="war/WEB-INF/lib">
<include name="addressing-1.1.1.mar" />
<include name="rampart-1.1.mar" />
</fileset>
</jar>
<delete dir="build" />
</target>
I think, the most easy and flexible way is to use Maven. Each project represents the separate Maven artefact which is stored in your local repository. And only one thing you should do in your main project is to add couple of dependencies to your POM file. That's it. I use this schema for a long time.

How to setup a war file with different directories in an Ant Script

Pretty new to this so bear with me. I've gotten my Ant build.xml to run and populate everything that I want, but my content (js, css, jsp, etc) is just jammed into the WAR at its topmost directory. I'm looking to put this content into the WEB-INF folder that I would need to make within the war. Here's what I have so far as a reference. If I could just see an example of how to do this I think I would be good. Tried to follow this thread, is that dist setup what I am missing??
<war warfile="${build}/${project.name}.war" webxml="${appconf}/web.xml">
<classes dir="${appconf}/classes" />
<fileset dir="${appcontent}" includes="jsp/**,js/**,images/**,css/**,tg/**" excludes="**/*.~js,**/*.~jav,**/*.java,cvs,annotation">
<patternset id="jsp_images_package">
<include name="**/*.jsp,**/*.js,**/*.gif,**/*.html,**/*.css"/>
<exclude name="**/*.~js,**/*.~jav"/>
</patternset>
</fileset>
<fileset dir="${appcontent}" includes="WEB-INF/lib/*.jar,WEB-INF/*.jar"/>
<fileset dir="${appcontent}" includes="WEB-INF/lib/*.css"/>
<fileset dir="${appcontent}" includes="docs/*.doc"/>
</war>
What you want to use in this case is <zipfileset>. It should look something like this (Your structure is weird, so I can't tell exactly where you want files).
<war warfile="${build}/${project.name}.war" webxml="${appconf}/web.xml">
<classes dir="${appconf}/classes" />
<zipfileset dir="${appcontent}/jsp" includes="**/*.jsp" prefix="WEB-INF"/>
<zipfileset dir="${appcontent}/js" includes="**/*.js" prefix="WEB-INF"/>
<zipfileset dir="${appcontent}/css" includes="**/*.css" prefix="WEB-INF"/>
<fileset dir="${appcontent}">
<include name="docs/*.doc"/>
<include name="images/**"/>
<include name="WEB-INF/*.jar"/>
<include name="WEB-INF/lib/*.jar"/>
<include name="WEB-INF/lib/*.css"/>
</fileset>
</war>

Delete dir with nAnt and exclude sub folder?

I'm looking for my build to delete the contents of a directory without touching a certain folder. Below is what I'm trying, and it even looks wrong to me...aside from the fact that it bombs when I run it. Do I need to be deleting the contents of the dir explicitly and at the same time exclude my Reports folder?
<delete includeemptydirs="true">
<fileset dir="${PublishLocation}" >
<exclude name="**Reports**"/>
</fileset>
</delete>
Cheers.
It should be:
<delete>
<fileset basedir="${PublishLocation}">
<include name="**/*"/>
<exclude name="**/Reports/**/*" />
</fileset>
</delete>
Please notice the following:
includeemptydirs="true" is default
The attribute for fileset is basedir instead of dir
if you specify <exclude name="**/Reports/**" /> instead of <exclude name="**/Reports/**/*" /> all files named Reports are kept as well