Reputation: 33
I am using a third party build script creates minified js files with the minified file called 'someFile.js' and an unminified version called 'someFile.js.uncompressed.js'. I need one of my tasks in the build.xml to copy only the js files that have a partner '.uncompressed.js' file to another location. For example, given a directory structure like this:
- rootDirectory
- minified.js
- minified.js.uncompressed
- unminified.js
- anotherDirectory
- anotherMinified.js
- anotherMinified.js.uncompressed.js
- unminified.js
- anotherUnminified.js
the destination directory should end up like this:
- rootDirectory
- minified.js
- anotherDirectory
- anotherMinified.js
Is there any way to accomplish this with ant? I am using ant 1.8.1.
Thanks in advance for any help!
Upvotes: 2
Views: 755
Reputation: 78115
You can use an Ant <present>
selector to do this. For example:
<copy todir="dest">
<fileset dir="src">
<present targetdir="src">
<mapper type="glob" from="*" to="*.uncompressed.js" />
</present>
</fileset>
</copy>
In this case the targetdir
in the selector is the same as the root directory of the fileset.
What this does is copy any file in the src
directory tree where a file with the same name, with .uncompressed.js
appended also present.
Upvotes: 3
Reputation: 77971
You could use a custom scriptselector for your fileset.
├── build.xml
├── src
│ └── rootDirectory
│ ├── anotherDirectory
│ │ ├── anotherMinified.js
│ │ ├── anotherMinified.js.uncompressed
│ │ ├── anotherUnminified.js
│ │ └── unminified.js
│ ├── minified.js
│ ├── minified.js.uncompressed
│ └── unminified.js
└── target
└── rootDirectory
├── anotherDirectory
│ └── anotherMinified.js
└── minified.js
<project name="demo" default="copy-files">
<target name="copy-files">
<copy todir="target">
<fileset dir="src">
<scriptselector language="javascript">
importClass(java.io.File);
var testForFile = new File("src/" + filename + ".uncompressed");
self.setSelected(testForFile.exists());
</scriptselector>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="target"/>
</target>
</project>
Notes:
Upvotes: 1