For my site antlib, I am currently using a task <onceonly>
which may be usefull to have as a std ant task (or ant-contrib task).
The idea is that the task will only be run once, even if
called multiple times (via ant, antcall, subant - indirectly
via import).
For example:
<project default="caller">
<onceonly>
<echo>Initializing Project</echo>
<!-- some complicated list of initializing tasks -->
</onceonly>
<target name="caller">
<echo>In call</echo>
<antcall target="callee"/>
</target>
<target name="callee">
<echo>In callee</echo>
</target>
<project>
Peter
package net.sf.antextra;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
import org.apache.tools.ant.taskdefs.Sequential;
/**
* Ant task to run a sequence of tasks only
* once.
* Usefull for setting up stuff in files that may
* be called a number of times (via ant or import
* for example).
*/
public class OnceOnly extends Sequential {
private static Set locations = new HashSet();
/**
* Execute the list of nested tasks by calling
* super.execute() if this location has not been
* seen before.
*/
public void execute() {
String location = getLocation().toString();
synchronized(locations) {
if (locations.contains(location)) {
return; // Do nothing, action already done
}
locations.add(location);
}
super.execute();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]