Ant copy problem

J

James Westby

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
 
R

Rhino

See remarks interspersed below.

James Westby said:
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
 
D

Daniel Dyer

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.
 
J

James Westby

Rhino said:
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
 
J

James Westby

James said:
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
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top