Ant copy problem

Discussion in 'Java' started by James Westby, Jan 10, 2006.

  1. James Westby

    James Westby Guest

    Hi,

    I realise this isn't a Java language problem, but I can't find an ant
    ng, and I assume that some people here use ant, so could anyone help me
    with this problem. I have the following task, (slightly edited)

    <target name="srcdist" description="Packages all the source files together
    so they can be distributed">
    <delete dir="${distribution.directory}/${package}"/>
    <mkdir dir="${distribution.directory}/${package}"/>
    <copy todir="${distribution.directory}/${package}">
    <fileset dir="." defaultexcludes="false">
    <include name="**"/>
    <exclude name="bin/**"/>
    <exclude name="${build.directory}/**"/>
    <exclude name="${distribution.directory}/**"/>
    <exclude name="${results.directory}/*.*"/>
    <exclude name="**/.project"/>
    <exclude name="**/.classpath"/>
    <exclude name="**/.cvsignore"/>
    <exclude name="**/.checkstyle"/>
    <exclude name="**/.svn/**"/>
    <exclude name=".externalToolBuilders/**"/>
    </fileset>
    </copy>
    </target>

    which copies all source type files to a new directory tree within the
    project so they can be put in a zip file (zip task removed).

    It behaves as I would like for most of it, e.g. removing all .svn dirs
    from the tree, but there is one problem.

    I have a directory that the output of several tasks goes in to, the
    ${results.directory}, these all have the form q1.xml q1.txt q1.eps or
    output.log. As these are all generated files I don't want them included,
    however the fileset copies them over every time. I have tried playing
    with things a little, and using echo to display various properties to
    confirm that they are how i expect.

    I am using ant 1.6.5.

    Any help would be greatly appreciated.

    James
     
    James Westby, Jan 10, 2006
    #1
    1. Advertising

  2. James Westby

    Rhino Guest

    See remarks interspersed below.

    "James Westby" <> wrote in message
    news:0YNwf.110051$...
    > Hi,
    >
    > I realise this isn't a Java language problem, but I can't find an ant ng,
    > and I assume that some people here use ant, so could anyone help me with
    > this problem.


    You're right, there is no Ant newsgroup. But there _is_ an Ant mailing list;
    that's where most questions like yours should usually go. You can subscribe
    to the list - you'll want the User list - or inspect the archive at
    http://ant.apache.org/mail.html.

    > I have the following task, (slightly edited)
    >
    > <target name="srcdist" description="Packages all the source files together
    > so they can be distributed">
    > <delete dir="${distribution.directory}/${package}"/>
    > <mkdir dir="${distribution.directory}/${package}"/>
    > <copy todir="${distribution.directory}/${package}">
    > <fileset dir="." defaultexcludes="false">
    > <include name="**"/>
    > <exclude name="bin/**"/>
    > <exclude name="${build.directory}/**"/>
    > <exclude name="${distribution.directory}/**"/>
    > <exclude name="${results.directory}/*.*"/>
    > <exclude name="**/.project"/>
    > <exclude name="**/.classpath"/>
    > <exclude name="**/.cvsignore"/>
    > <exclude name="**/.checkstyle"/>
    > <exclude name="**/.svn/**"/>
    > <exclude name=".externalToolBuilders/**"/>
    > </fileset>
    > </copy>
    > </target>
    >
    > which copies all source type files to a new directory tree within the
    > project so they can be put in a zip file (zip task removed).
    >
    > It behaves as I would like for most of it, e.g. removing all .svn dirs
    > from the tree, but there is one problem.
    >
    > I have a directory that the output of several tasks goes in to, the
    > ${results.directory}, these all have the form q1.xml q1.txt q1.eps or
    > output.log. As these are all generated files I don't want them included,
    > however the fileset copies them over every time. I have tried playing with
    > things a little, and using echo to display various properties to confirm
    > that they are how i expect.
    >

    I think the answer to your problem probably involves patternsets. Have a
    look at the PatternSet article in the Ant manual; see the Concepts and Types
    page, then look for PatternSet amongst the "Core Types".

    Here's a quick _untested_ illustration of what I mean. First, define your
    patternset so that it identifies includes all of the files that you want to
    copy and excludes all the files you don't want to copy:

    ----------------------------------------------------------------------------------------------
    <patternset id="ps.resume.misc" description="The resume generator.">
    <include name="${resume.pkg}\misc\*.*"/>
    <exclude name="${resume.pkg}\misc\ResumeAscii.*"/>
    <exclude name="${resume.pkg}\misc\ResumeHtml.*"/>
    <exclude name="${resume.pkg}\misc\ResumePdf.*"/>
    <exclude name="${resume.pkg}\misc\ResumeReferencesPdf.*"/>
    </patternset>

    ----------------------------------------------------------------------------------------------

    Then, when you want to copy the files in that PatternSet, do this, noting
    that the 'todir' parameter indicates the directory to which you are copying
    and the 'dir' parameter in the fileset indicates the directory which
    contains the files that are being copied:

    ----------------------------------------------------------------------------------------------
    <copy todir="${local.resume.dir}" failonerror="false"
    description="Copy files to the local file system.">
    <fileset dir="${resume.html.dir}">
    <patternset refid="ps.resume.misc">
    </fileset>
    </copy>

    ----------------------------------------------------------------------------------------------

    In other words, the PatternSet itself does not define where the files are
    relative to the file system or another computer; it just indicates the files
    and directories you want relative to a directory which you will specify at a
    later time, via the 'dir' parameter of the fileset.

    That means you can then copy the copied files from ${local.resume.dir} to
    some other directory in a later target. For example:

    ----------------------------------------------------------------------------------------------
    <copy todir="${remote.resume.dir}" failonerror="false"
    description="Copy files to the local file system.">
    <fileset dir="${local.resume.dir}">
    <patternset refid="ps.resume.misc">
    </fileset>
    </copy>
    ----------------------------------------------------------------------------------------------

    This second copy has copied the first set of copies from the local
    directory, which was the target of the first copy, to a remote directory.
    You didn't need to define another PatternSet; you simply reused the existing
    one but had a different starting point for the files for the second copy.

    > I am using ant 1.6.5.
    >
    > Any help would be greatly appreciated.
    >

    I hope this helps; if not, try the Ant user mailing list.

    Rhino
     
    Rhino, Jan 10, 2006
    #2
    1. Advertising

  3. James Westby

    Daniel Dyer Guest

    On Tue, 10 Jan 2006 21:31:28 -0000, Rhino
    <> wrote:

    > You're right, there is no Ant newsgroup. But there _is_ an Ant mailing
    > list;
    > that's where most questions like yours should usually go. You can
    > subscribe
    > to the list - you'll want the User list - or inspect the archive at
    > http://ant.apache.org/mail.html.
    >


    Or use the comp.lang.java.softwaretools group.

    Dan.

    --
    Daniel Dyer
    http://www.dandyer.co.uk
     
    Daniel Dyer, Jan 10, 2006
    #3
  4. James Westby

    James Westby Guest

    Rhino wrote:
    >
    > You're right, there is no Ant newsgroup. But there _is_ an Ant mailing list;
    > that's where most questions like yours should usually go. You can subscribe
    > to the list - you'll want the User list - or inspect the archive at
    > http://ant.apache.org/mail.html.
    >
    >
    >
    > I think the answer to your problem probably involves patternsets. Have a
    > look at the PatternSet article in the Ant manual; see the Concepts and Types
    > page, then look for PatternSet amongst the "Core Types".
    >
    > Here's a quick _untested_ illustration of what I mean. First, define your
    > patternset so that it identifies includes all of the files that you want to
    > copy and excludes all the files you don't want to copy:
    >
    > ----------------------------------------------------------------------------------------------
    > <patternset id="ps.resume.misc" description="The resume generator.">
    > <include name="${resume.pkg}\misc\*.*"/>
    > <exclude name="${resume.pkg}\misc\ResumeAscii.*"/>
    > <exclude name="${resume.pkg}\misc\ResumeHtml.*"/>
    > <exclude name="${resume.pkg}\misc\ResumePdf.*"/>
    > <exclude name="${resume.pkg}\misc\ResumeReferencesPdf.*"/>
    > </patternset>
    >
    > ----------------------------------------------------------------------------------------------
    >
    > Then, when you want to copy the files in that PatternSet, do this, noting
    > that the 'todir' parameter indicates the directory to which you are copying
    > and the 'dir' parameter in the fileset indicates the directory which
    > contains the files that are being copied:
    >
    > ----------------------------------------------------------------------------------------------
    > <copy todir="${local.resume.dir}" failonerror="false"
    > description="Copy files to the local file system.">
    > <fileset dir="${resume.html.dir}">
    > <patternset refid="ps.resume.misc">
    > </fileset>
    > </copy>
    >
    > ----------------------------------------------------------------------------------------------
    >
    > In other words, the PatternSet itself does not define where the files are
    > relative to the file system or another computer; it just indicates the files
    > and directories you want relative to a directory which you will specify at a
    > later time, via the 'dir' parameter of the fileset.
    >
    > That means you can then copy the copied files from ${local.resume.dir} to
    > some other directory in a later target. For example:
    >
    > ----------------------------------------------------------------------------------------------
    > <copy todir="${remote.resume.dir}" failonerror="false"
    > description="Copy files to the local file system.">
    > <fileset dir="${local.resume.dir}">
    > <patternset refid="ps.resume.misc">
    > </fileset>
    > </copy>
    > ----------------------------------------------------------------------------------------------
    >
    > This second copy has copied the first set of copies from the local
    > directory, which was the target of the first copy, to a remote directory.
    > You didn't need to define another PatternSet; you simply reused the existing
    > one but had a different starting point for the files for the second copy.
    >
    >
    > I hope this helps; if not, try the Ant user mailing list.
    >
    > Rhino
    >
    >


    Thanks for replying. I'm not sure that defining explicit pattern sets is
    going to solve the problem, as the fileset builds an implicit
    patternset. I managed to work around the problem by substituting
    "results" for "${results.directory}", which does imply there is some
    sort of path problem going on, but i can't see what it is. I'll give
    your suggestion a try.

    Thanks,

    James
     
    James Westby, Jan 10, 2006
    #4
  5. James Westby

    James Westby Guest

    James Westby wrote:
    > Rhino wrote:
    >

    [snip]
    > Thanks for replying. I'm not sure that defining explicit pattern sets is
    > going to solve the problem, as the fileset builds an implicit
    > patternset. I managed to work around the problem by substituting
    > "results" for "${results.directory}", which does imply there is some
    > sort of path problem going on, but i can't see what it is. I'll give
    > your suggestion a try.
    >
    > Thanks,
    >
    > James



    Hi,

    I have solved the problem (well worked it out anyway).

    I was defining my directories like

    <property name="results.directory" location="results"/>

    as suggested on

    http://java.sun.com/developer/Quizzes/misc/ant.html

    "When you set a property to a value, the string value is set into a
    property. When you set it to a location, the property is set with a file
    location that is immediately resolved relative to the base directory of
    the project. If a property is passed to a different build file in a
    different directory, the difference becomes immediately apparent... "

    But this resolving to absolute path was making the fileset not match the
    excludes, changing back to

    <property name="results.directory" value="results"/>

    Means that the excludes work correctly, as I found when I didn't use the
    property. This method is probably a little more shaky, but I'm more
    bothered about getting this task working than being able to pass paths
    around.


    James
     
    James Westby, Jan 11, 2006
    #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,247
  2. john martin
    Replies:
    2
    Views:
    2,222
    john martin
    Apr 7, 2005
  3. Replies:
    6
    Views:
    30,317
    Diplomat
    Jan 12, 2011
  4. Alex
    Replies:
    2
    Views:
    1,238
  5. Replies:
    26
    Views:
    2,123
    Roland Pibinger
    Sep 1, 2006
Loading...

Share This Page