diff --git a/docs/manual/OptionalTasks/script.html b/docs/manual/OptionalTasks/script.html index d67116a4a..04838092c 100644 --- a/docs/manual/OptionalTasks/script.html +++ b/docs/manual/OptionalTasks/script.html @@ -331,5 +331,61 @@ Finally we use the <echo> task for producing the output. The its execute() method, because the perform() method (implemented in Task itself) does the appropriate logging before and after invoking execute().

+

+ 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. +

+
+<!--
+       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>
+
+

+ An example of using this task to create a path + from a list of directories (using antcontrib's + + <for> task) follows: +

+
+<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>
+
+