Ant - Safe reusable lists of files?

Discussion in 'Java' started by robin, Sep 14, 2007.

  1. robin

    robin Guest

    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
     
    robin, Sep 14, 2007
    #1
    1. Advertising

  2. robin

    Roedy Green Guest

    On Fri, 14 Sep 2007 00:33:27 -0000, robin <> wrote,
    quoted or indirectly quoted someone who said :

    >
    >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.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Sep 14, 2007
    #2
    1. Advertising

  3. robin

    robin Guest

    On Sep 14, 4:26 am, Roedy Green <>
    wrote:
    > On Fri, 14 Sep 2007 00:33:27 -0000, robin <> wrote,
    > quoted or indirectly quoted someone who said :
    >
    >
    >
    > >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.
    > --
    > Roedy Green Canadian Mind Products
    > The Java Glossaryhttp://mindprod.com


    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.
     
    robin, Sep 14, 2007
    #3
  4. robin

    Zig Guest

    As

    On Thu, 13 Sep 2007 20:33:27 -0400, robin <> wrote:

    > 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
     
    Zig, Sep 14, 2007
    #4
  5. robin

    robin Guest

    On Sep 14, 3:26 pm, Zig <> wrote:
    > As
    >
    > On Thu, 13 Sep 2007 20:33:27 -0400, robin <> wrote:
    > > 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


    Thanks - I'll give that a try.
     
    robin, Sep 16, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Bedford
    Replies:
    6
    Views:
    2,273
  2. john martin
    Replies:
    2
    Views:
    2,244
    john martin
    Apr 7, 2005
  3. Replies:
    1
    Views:
    543
    Larry
    Mar 7, 2006
  4. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    435
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  5. Replies:
    6
    Views:
    906
Loading...

Share This Page