Author: peterreilly Date: Fri Jun 8 08:29:04 2007 New Revision: 545532 URL: http://svn.apache.org/viewvc?view=rev&rev=545532 Log: add another example to <script>
Modified: ant/core/trunk/docs/manual/OptionalTasks/script.html Modified: ant/core/trunk/docs/manual/OptionalTasks/script.html URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/OptionalTasks/script.html?view=diff&rev=545532&r1=545531&r2=545532 ============================================================================== --- ant/core/trunk/docs/manual/OptionalTasks/script.html (original) +++ ant/core/trunk/docs/manual/OptionalTasks/script.html Fri Jun 8 08:29:04 2007 @@ -331,5 +331,61 @@ its execute() method, because the perform() method (implemented in Task itself) does the appropriate logging before and after invoking execute(). </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> </html> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]