I am trying to add a few folders to the classpath in our ant build file.
<dirset dir="${env.WT_HOME}/codebase/com/lcs/wc/">
<include name="flexbom flexQuerySpec flextype foundation material util moa" />
</dirset>
All these folders (i.e. 'flexbom' 'flexQuerySpec'...) are inside codebase/com/lcs/wc folder. Each folder has several class files. I want to add all these class files to the path.
Above script doesn't seem to be working. I am still getting class not found for these folder/packages.
Nested <include> elements in a <fileset> or <dirset> specify matching patterns, one pattern per element, rather than lists.
An alternative is to use the includes attribute instead like this:
<dirset dir="${env.WT_HOME}/codebase/com/lcs/wc/"
includes="flexbom flexQuerySpec flextype foundation material util moa" />
Or multiple include elements:
<dirset dir="${env.WT_HOME}/codebase/com/lcs/wc/">
<include name="flexbom" />
<include name="flexQuerySpec" />
<include name="flextype" />
<include name="foundation" />
<include name="material" />
<include name="util" />
<include name="moa" />
</dirset>
Related
This seems like something that should be obvious, but I don't think it is. Given:
a space-delimited list of files (or comma-delimited, etc.)
a <patternset> of whitelisted patterns
How do I come up with a <fileset> that contains all of the files in the list that match the whitelisted pattern?
Getting a list of files from the list is easy enough:
<patternset id="the-patternset" includes="${list.of.files}" />
<fileset id="the-fileset" dir="${basedir}">
<patternset refid="the-patternset" />
</fileset>
<pathconvert pathsep="${line.separator}" property="the-filelist" refid="the-fileset"/>
<echo>fileset: ${the-filelist}</echo>
…will happily produce a fileset with all of the files in ${list.of.files}. But adding a filter of sorts:
<patternset id="the-filter">
<include name="includeme/**/*.java" />
<exclude name="excludeme/**/*.java" />
</patternset>
<patternset id="the-patternset" includes="${list.of.files}" />
<fileset id="the-fileset" dir="${basedir}">
<patternset refid="the-patternset" />
<patternset refid="the-filter" />
</fileset>
<pathconvert pathsep="${line.separator}" property="the-filelist" refid="the-fileset"/>
<echo>fileset: ${the-filelist}</echo>
…will list a union of the patternsets—i.e., all files that match either the-filter or the-patternset.
How do I produce a fileset containing files that are in ${list.of.files} and match the-patternset?
Here's a potted example. Create two filesets (or perhaps filelists) one from each of your patternsets. I'll just use fixed lists here:
<property name="list.1" value="a,b,c" />
<property name="list.2" value="b,c,d" />
<fileset dir="." id="set.1" includes="${list.1}" />
<fileset dir="." id="set.2" includes="${list.2}" />
Then use the <intersect> resource collection to get the required 'overlap' set:
<intersect id="intersect">
<resources refid="set.1"/>
<resources refid="set.2"/>
</intersect>
Most Ant tasks will allow you to use a resource collection in place of a simple fileset.
We are currently generating a zip file using multiple targets as follows.
<zipfile>
<zipfileset dir="alpha" prefix="alpha" />
<zipfileset dir="beta" prefix="alpha" excludes="*.bar" />
<zipfileset dir="gamma/G" prefix="gamma" />
</zipfile>
A requirement has come up in that we need to generate (and include) a list of the included files and their corresponding MD5 checksum values.
If we use a <fileset>/<patternset>/<pathconvert> combination, I can get a text file containing all the files, and generate from there. However, I can't seem to find a way to do this with <zipfileset /> targets.
Is there a way to do a 'dry-run' and obtain a list of the targets that will be included? Or is there a (simple) method of extracting the required information from the generated ZIP itself?
If you have already generated file (with checksum) you can just add it with help of another fileset.
The sample:
<target name="ziptest">
<zip destfile="${src}\output.zip">
<fileset dir="${src}">
<include name="dir1\*"/>
<include name="dir2\fileprefix*"/>
</fileset>
<fileset dir="${src}">
<!-- You have property with filename: file.name.checksum-->
<include name="${file.name.checksum}"/>
</fileset>
</zip>
</target>
So I defined iajc task for my project that does intertype declarations just fine, then there is a separate jar task that creates a project.jar.
Then there is iajc task for junit test target, this task references the project.jar with the goal of weaving its ITDs into test classes like so:
<aspectpath>
<pathelement path="${dist}/project.jar"/>
<fileset dir="${lib.aspect}">
<include name="**/*.jar" />
<include name="**/*.zip" />
</fileset>
</aspectpath>
That does not work - compiler produces errors like class "com....Foo" has to implement method doThings() defined in interface Bar
Then I change the <aspectpath> to this:
<aspectpath>
<pathelement location="${build.dir}"/>
<fileset dir="${lib.aspect}">
<include name="**/*.jar" />
<include name="**/*.zip" />
</fileset>
</aspectpath>
which is basically using the intermediate class files generated by the compiler and it works great.
Then I find that if I use the outjar option instead of destdir in my iajc task then that jar can be used in <aspectpath>.
So a question and a comment then:
Q. is there some parameter that would make it work with the regular <jar> task?
C. the fact that I have to use outjar is not documented at all - the option to output a jar is mentioned but nowhere does it say that that is the only way to produce a jar that will work.
I want to create an Ant target that copies files in a directory to a destination directory with the same folder structure, plus one more subfolder appended.
For example, the source is:
a/b/c/foo.pdf
d/e/f/bar.pdf
I want the destination to be:
a/b/c/x/foo.pdf
d/e/f/x/bar.pdf
Here is my target so far, but it doesn't appear to be doing anything:
<copy todir="${dest.dir}">
<fileset dir="${src.dir}" casesensitive="yes">
<include name="**${file.separator}foo.pdf" />
</fileset>
<mapper type="glob"
from="foo.pdf" to="x${file.separator}foo.pdf" />
</copy>
What am I missing?
You could use a regexp mapper:
<copy todir="${dest.dir}">
<fileset dir="${src.dir}" casesensitive="yes">
<include name="**/*.pdf"/>
</fileset>
<mapper type="regexp" from="^(.*)/(.*\.pdf)" to="\1/x/\2" />
</copy>
I've used hard-coded file.separators to shorten. Basically, you split the path to the input file (from) into directory and filename (capture \1 and \2) and then insert the \x extra element between them (to).
I'm not clear on your example - it looks like you want to match 'bar.pdf' and rename it to 'foo.pdf', as well as changing the directory. If you need to do that, you might consider chaining a couple of simpler regexp mappers, rather than trying to cook up one complex one:
<copy todir="${dest.dir}">
<fileset dir="${src.dir}" casesensitive="yes">
<include name="**/*.pdf"/>
</fileset>
<chainedmapper>
<mapper type="regexp" from="^(.*)/(.*\.pdf)" to="\1/x/\2" />
<mapper type="regexp" from="^(.*)/(.*\.pdf)" to="\1/foo.pdf" />
</chainedmapper>
</copy>
When using a glob mapper, you need to specify one wildcard * in the from field:
Both to and from are required and
define patterns that may contain at
most one *. For each source file that
matches the from pattern, a target
file name will be constructed from the
to pattern by substituting the * in
the to pattern with the text that
matches the * in the from pattern.
Source file names that don't match the
from pattern will be ignored.
So something like this might work:
<mapper type="glob" from="*/foo.pdf" to="*/x/foo.pdf" />
I have a directory structure like this
client/lib
a.jar
b-4.3.jar
c-1.2.jar
d-4.3.jar
e.jar
I need to copy the jars - some without version, and some with.
The only information that I have is version number, and that is stored in a variable.
The version number I have is in a property, and has three fields - '4.3.1'
The version that the jars have is just the first two fields from the property value (i.e. 4.3 in this case).
I need all jars that starting with two digits that my property has, and some of the jars without version.
For example, from above directory structure I need:
b-4.3.jar
d-4.3.jar
e.jar
How can I do that?
You might consider using the antcontrib propertyregex task. Perhaps something like this:
<property name="version" value="4.3.1" />
<propertyregex override="yes" property="version2" input="${version}"
regexp="(.*).([^.]+)"
replace="\1" />
<fileset id="my_jars" dir="client/lib">
<include name="*${version2}.jar" />
<include name="e.jar" />
</fileset>
<copy todir="to_dir">
<fileset refid="my_jars" />
</copy>