|
|
@@ -331,5 +331,61 @@ Finally we use the <code><echo></code> task for producing the output. The |
|
|
its execute() method, because the perform() method (implemented in Task itself) does the |
|
|
its execute() method, because the perform() method (implemented in Task itself) does the |
|
|
appropriate logging before and after invoking execute(). |
|
|
appropriate logging before and after invoking execute(). |
|
|
</p> |
|
|
</p> |
|
|
|
|
|
<p> |
|
|
|
|
|
Here is an example of using beanshell to create an ant |
|
|
|
|
|
task. This task will add filesets and paths to a referenced |
|
|
|
|
|
path. If the path does not exist, it will be created. |
|
|
|
|
|
</p> |
|
|
|
|
|
<blockquote><pre> |
|
|
|
|
|
<!-- |
|
|
|
|
|
Define addtopath task |
|
|
|
|
|
--> |
|
|
|
|
|
<script language="beanshell"> |
|
|
|
|
|
import org.apache.tools.ant.Task; |
|
|
|
|
|
import org.apache.tools.ant.types.Path; |
|
|
|
|
|
import org.apache.tools.ant.types.FileSet; |
|
|
|
|
|
public class AddToPath extends Task { |
|
|
|
|
|
private Path path; |
|
|
|
|
|
public void setRefId(String id) { |
|
|
|
|
|
path = getProject().getReference(id); |
|
|
|
|
|
if (path == null) { |
|
|
|
|
|
path = new Path(getProject()); |
|
|
|
|
|
getProject().addReference(id, path); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
public void add(Path c) { |
|
|
|
|
|
path.add(c); |
|
|
|
|
|
} |
|
|
|
|
|
public void add(FileSet c) { |
|
|
|
|
|
path.add(c); |
|
|
|
|
|
} |
|
|
|
|
|
public void execute() { |
|
|
|
|
|
// Do nothing |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
project.addTaskDefinition("addtopath", AddToPath.class); |
|
|
|
|
|
</script> |
|
|
|
|
|
</pre></blockquote> |
|
|
|
|
|
<p> |
|
|
|
|
|
An example of using this task to create a path |
|
|
|
|
|
from a list of directories (using antcontrib's |
|
|
|
|
|
<a href="http://ant-contrib.sourceforge.net/tasks/tasks/for.html"> |
|
|
|
|
|
<for></a> task) follows: |
|
|
|
|
|
</p> |
|
|
|
|
|
<blockquote><pre> |
|
|
|
|
|
<path id="main.path"> |
|
|
|
|
|
<fileset dir="build/classes"/> |
|
|
|
|
|
</path> |
|
|
|
|
|
<ac:for param="ref" list="commons,fw,lps" |
|
|
|
|
|
xmlns:ac="antlib:net.sf.antcontrib"> |
|
|
|
|
|
<sequential> |
|
|
|
|
|
<addtopath refid="main.path"> |
|
|
|
|
|
<fileset dir="${dist.dir}/@{ref}/main" |
|
|
|
|
|
includes="**/*.jar"/> |
|
|
|
|
|
</addtopath> |
|
|
|
|
|
</sequential> |
|
|
|
|
|
</ac:for> |
|
|
|
|
|
</pre></blockquote> |
|
|
|
|
|
|
|
|
</body> |
|
|
</body> |
|
|
</html> |
|
|
</html> |