Hi,
I'm creating a custom ANT task that is supposed to
read a set of files (all files having a .xml suffix).
Does anyone have an example where they create an
includes tag for a custom ANT task.
As in
<mytask includes="**/*.xml"/>
Thanks
gimme_this_gimme_that@yahoo.com - 22 Apr 2005 00:59 GMT
For those who might be interested the trick is to know to use
ANTs directory scanner.
package com.*.*.ant.task;
/*
<target name="main"
depends="declare-idupdate,create-base-component.xml">
<idupdate
includes="**/c.xml"
excludes="*sv*/**/c.xml"
dir="../.."
/>
</target>
*/
import java.io.File;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Path;
public class BuildComponentXML extends Task {
private static String includes; // included component.xml files
private static String excludes; // excluded component.xml files
private static Path dir;
public void setDir(org.apache.tools.ant.types.Path dir) {
BuildComponentXML.dir = dir;
}
public void setIncludes(String includes) {
BuildComponentXML.includes=includes;
}
public void setExcludes(String excludes) {
BuildComponentXML.excludes=excludes;
}
public void execute() throws BuildException {
System.out.println("dir is : " + BuildComponentXML.dir);
DirectoryScanner ds = new DirectoryScanner();
String[] a = {includes};
ds.setIncludes(a);
String[] b = {excludes};
ds.setExcludes(b);
ds.setBasedir(BuildComponentXML.dir.toString());
ds.setCaseSensitive(true);
ds.scan();
System.out.println("FILES:");
String[] files = ds.getIncludedFiles();
for (int i = 0; i < files.length; i++) {
System.out.println(files[i]);
}
}
}