Ant - Safe reusable lists of files?

R

robin

Hi,

Can anyone help me with what is hopefully a simple ant related
question? I think I may need to write a custom task, but what I am
trying to do seems simple and I may be overlooking a built-in
solution.

I am working with an ant based build system that packages a list of
resources into a jar file at build time. These consist of a number of
properties files and a certificates.

The build system creates builds for developer workstations, test
systems, and production systems. The location of the resource files
differs depending on which of these are being built, and where the
build is happening. I want to be able to specify the list of files
explicitly, naming each file rather than using wild-cards primarily so
that if files are missing the build can break.

I only want to specify the list of names once because otherwise people
will inevitably fail to update some of the places where the names are
repeated leading to wasted developer time.

I don't seem to be able to use <copy> with a <fileset> because that
won't fail if some of the files aren't found, and the base directory
must be specified, so I can't reuse the list in the different
contexts.

Currently the system uses just a comma separated list combined with a
<for> task and a <copy>. This is functional however the list cannot
have any whitespace in it and so leads to a very long and hard to read
line, or a very clumsy construction of a bigger properties list out of
a list of smaller lists.

At the moment, it seems to me that I need to extend with a 'lexical
list' or 'name list' kind of data structure, and a new kind of copy
task that can construct real paths from such a list by combining the
names with a path.

Do any ant experts out there have any opinions on this?

Thanks in advance.

-Robin
 
R

Roedy Green

I only want to specify the list of names once because otherwise people
will inevitably fail to update some of the places where the names are
repeated leading to wasted developer time.

I handle this sort of problem by writing a STOMP program in Java that
cranks out all my ant scripts. That way I can be sure all my scripts
are consistently done. I can ensure a name in consistently spelled
throughout. I can use Java to compute constants rather than having to
use ant's convoluted techniques.
 
R

robin

I handle this sort of problem by writing a STOMP program in Java that
cranks out all my ant scripts. That way I can be sure all my scripts
are consistently done. I can ensure a name in consistently spelled
throughout. I can use Java to compute constants rather than having to
use ant's convoluted techniques.

Thanks for the suggestion. I find it rather depressing that code
generation is th e only way to solve what seems like it should be a
common build problem. I think I'm going to go ahead and write the
custom task and type if I can.
 
Z

Zig

As

Currently the system uses just a comma separated list combined with a
<for> task and a <copy>. This is functional however the list cannot
have any whitespace in it and so leads to a very long and hard to read
line, or a very clumsy construction of a bigger properties list out of
a list of smaller lists.

One note: the Properties file format does allow you to break a logical
line into several by adding a '\' as the last character on a line. So, you
should be able to do something like

pkg1_base_dir=../over/there
pkg1_files=file1.dat, \
file2.dat, \
file3.dat
At the moment, it seems to me that I need to extend with a 'lexical
list' or 'name list' kind of data structure, and a new kind of copy
task that can construct real paths from such a list by combining the
names with a path.

You should be able to get this behavior by using a FileList:

http://ant.apache.org/manual/CoreTypes/filelist.html

Note that a filelist accepts whitespace as a valid delimiter, so you
should be able to make your properties file into something like:

pkg1_base_dir=../over/there
pkg1_list_file=pkg1_files.txt

Then your pkg1_files.txt could be a simple plain text file:

file1.dat
file2.dat
file3.dat

which you could put all together with something like:

<property file="build.properties" />
<loadfile
srcfile="${pkg1_list_file}"
property="pkg1_files"
/>

<copy todir="${output}">
<filelist
dir="${pkg1_base_dir}"
files="${pkg1_files}"
/>
</copy>

(untested)

HTH,

-Zig
 
R

robin

As



One note: the Properties file format does allow you to break a logical
line into several by adding a '\' as the last character on a line. So, you
should be able to do something like

pkg1_base_dir=../over/there
pkg1_files=file1.dat, \
file2.dat, \
file3.dat




You should be able to get this behavior by using a FileList:

http://ant.apache.org/manual/CoreTypes/filelist.html

Note that a filelist accepts whitespace as a valid delimiter, so you
should be able to make your properties file into something like:

pkg1_base_dir=../over/there
pkg1_list_file=pkg1_files.txt

Then your pkg1_files.txt could be a simple plain text file:

file1.dat
file2.dat
file3.dat

which you could put all together with something like:

<property file="build.properties" />
<loadfile
srcfile="${pkg1_list_file}"
property="pkg1_files"
/>

<copy todir="${output}">
<filelist
dir="${pkg1_base_dir}"
files="${pkg1_files}"
/>
</copy>

(untested)

HTH,

-Zig

Thanks - I'll give that a try.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top