ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dominique Devienne" <DDevie...@lgc.com>
Subject RE: truncating a directory
Date Tue, 28 Sep 2004 03:47:31 GMT
> > -----Urspr√ľngliche Nachricht-----
> > Von: Greg Irvine [mailto:greg.irvine@thalesatm.com]
> > I wish to move the contents of a number of directories to a single
> > directory, using a wildcard based set.  E.g. move build/*/** test/
> >
> > i.e.  Starting with:
> > build/
> > 	dirA/
> > 		subDirA/
> > 			fileA.java
> > 	dirB/
> > 		subDirB/
> > 			fileB.java
> >
> > Ending with:
> > test/
> > 	subDirA/
> > 		fileA.java
> > 	subDirB/
> > 		fileB.java

To emulate your 'move build/*/** test/' while stripping the * part,
the most logical would be either a nested <mapper>, as Jan suggested,
or something like:

  <move todir="test">
    <dirset dir="build" includes="dir*" />
  <move>

Which would select dirA and dirB and use the default patternset of
**/*. If you wanted to use an explicit patternset, we'd need need
a new <multifileset> datatype, that accepts a <dirset> instead of
just a single 'dir' attribute.

Needless to say, all of the above isn't possible now. Many tasks
accept multiple filesets explicitly, and deal with them with an
explicit iteration in the task's code, but one's still forced to
list the filesets explicitly, instead of having them dynamically
generated to account for your use case.

That said, it sounds like you could use Ant-Contrib's excellent
<ac:for> task iterating over a path for example. And for once,
instead of pseudo-code, here's a concrete example:

D:\org_apache\antx>D:\com_lgc\cycle9\buildtools\ant\bin\ant -f movedirs.xml suite
Buildfile: movedirs.xml

setUp:
    [mkdir] Created dir: D:\org_apache\antx\build\dirA\subDir1
    [mkdir] Created dir: D:\org_apache\antx\build\dirB\subDir1
    [mkdir] Created dir: D:\org_apache\antx\build\dirB\subDir2

testMoveDirs:
     [move] Moving 1 files to D:\org_apache\antx\test
     [move] Moving 2 files to D:\org_apache\antx\test

tearDown:
   [delete] Deleting directory D:\org_apache\antx\build
     [echo] Move succeeded ;-)

suite:

BUILD SUCCESSFUL
Total time: 1 second
D:\org_apache\antx>type movedirs.xml
<?xml version="1.0" encoding="UTF-8"?>
<project>
  <target name="setUp">
    <mkdir dir="build/dirA/subDir1" />
    <echo file="build/dirA/subDir1/Alpha">Alpha</echo>

    <mkdir dir="build/dirB/subDir1" />
    <echo file="build/dirB/subDir1/Beta">Beta</echo>

    <mkdir dir="build/dirB/subDir2" />
    <echo file="build/dirB/subDir2/Gamma">Gamma</echo>
  </target>

  <target name="tearDown">
    <condition property="OK">
      <and>
        <available file="test/subDir1/Alpha" />
        <available file="test/subDir1/Beta" />
        <available file="test/subDir2/Gamma" />
      </and>
    </condition>
    <delete dir="build" />
    <fail unless="OK">Move failed :-O</fail>
    <echo>Move succeeded ;-)</echo>
  </target>

  <target name="testMoveDirs" depends="setUp">
    <mkdir dir="test" />
    <ac:for param="dir" xmlns:ac="antlib:net.sf.antcontrib">
      <path><dirset dir="build" includes="dir*" /></path>
      <sequential>
        <move todir="test">
          <fileset dir="@{dir}" />
        </move>
      </sequential>
    </ac:for>
  </target>

  <target name="suite" depends="testMoveDirs, tearDown" />
</project>

This works, and isn't even that bad looking, but I still think
we need a better way to specify files (or zip entries) that works
without having to hand code always the same boilerplate code in
the Java code. We'll get there eventually ;-) --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message