Grinvald, Edward wrote:
> Since i can't seem to be able to get perl to work with <script>,
 > and javascript (luckily) can't access local filesystems (and is
 > therefore not a good substituion to perl), i am in a bit of confusion
 > as to how to do the following:
> I have a larget number 20+ of subprojects that i'd need to compile/build
 > /dist/etc. they are all under one src directory. Is there a way
 > for me to go that directory, get the listing, and then using antcall 
call
 > one function that will do everything (function already written) for
 > all the subdirectories/projects in that src directory, in one loop.

Both JavaScript (Rhino) and Java scripts (BeanShell) can use any Java 
class (including those of Ant), and so can perform any operation 
what-so-ever (it could be argued that Ant should use policy-based 
security for tasks and scripts, but such is not - yet - the case).

Anyhow, Rhino is easier to use than BeanShell since the configuration is 
simply drop-in the jar files, whereas BeanShell needs a line to added to 
a BSF (Bean Scripting Framework) configuration file.

Also, as the Dianne and Dominique say, adding custom tasks in Java is a 
simple thing.

Since this is an Ant FAQ, I've attached a sample that uses BeanShell. 
It should help you get started (converting to Rhino is pretty trivial, 
but this is some old code and I don't have time to test right now).

In this example, a <path> element is used to find all the "build.xml" 
files in sibling directories whose names match "plugin_*" and call a 
given target in each.  The name of each such directory is also <echo>'ed.

jim
<?xml version="1.0"?>
<project name="project" default="help" basedir=".">
   <path id="plugin-buildfiles">
     <fileset dir="..">
        <include name="plugin_*/build.xml"/>
     </fileset>
   </path>
   
   <target name="plugin-do">
      <script language="beanshell"><![CDATA[
         Object plugin_paths = project.getReferences().get("plugin-buildfiles");
         
         if (partner_paths == null) {
            Object failTask = project.createTask("fail");
            failTask.setMessage("The path 'plugin-buildfiles' is missing!");
            failTask.execute();
         }
         
         String[] buildfiles = plugin_paths.list();
         
         for (int i = 0; i < buildfiles.length; ++i) {
            String buildfilename = buildfiles[i];
            
            File buildfile = new File(buildfilename);
            File builddir = buildfile.getParentFile();
            
            Object echoTask = project.createTask("echo");
            echoTask.setMessage("Including plugin: " + builddir.getName());
            echoTask.execute();

            Object antTask = project.createTask("ant");
            antTask.setAntfile(buildfile.getName());
            antTask.setDir(builddir);
            
            String what = project.getProperty("what");
            
            if (what != null)
                antTask.setTarget(what);
            
            antTask.execute();
         }
      ]]></script>
   </target>

   <target name="plugins-build">
      <antcall target="plugin-do">
         <param name="what" value="build"/>
      </antcall>
   </target>
   
   <target name="plugins-clean">
      <antcall target="plugin-do">
         <param name="what" value="clean"/>
      </antcall>
   </target>

</project>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to