FileDocCategorySizeDatePackage
ForeachTask.javaAPI DocApache Axis 1.47512Sat Apr 22 18:57:28 BST 2006org.apache.axis.tools.ant.foreach

ForeachTask

public class ForeachTask extends org.apache.tools.ant.Task
Call a target foreach entry in a set of parameters based on a fileset.

For Axis development; there is no support or stability associated with this task

<target name="target1">
<foreach target="target2">
<param name="param1">
<fileset refid="fset1"/>
</param>
<param name="param2">
<item value="jar" />
<item value="zip" />
</param>
</foreach>
</target>

<target name="target2">
<echo message="prop is ${param1}.${param2}" />
</target>

Really this just a wrapper around "AntCall"
Added a "type" attribute that works precisely like its equivalent in ExecuteOn. It allows the user to specify whether directories, files, or both directories and files from the filesets are included as entries in the parameter set.
ant.task
category="axis"
author
Tim Vernum
author
Davanum Srinivas

Fields Summary
private org.apache.tools.ant.taskdefs.Ant
callee
private org.apache.tools.ant.taskdefs.Java
callee2
private String
subTarget
private Vector
params
private Hashtable
properties
private boolean
inheritAll
private boolean
inheritRefs
private boolean
fork
private boolean
verbose
Constructors Summary
public ForeachTask()


      
        params = new Vector();
        properties = new Hashtable();
    
Methods Summary
private voidbuildProperty(java.lang.String propName, java.lang.String propValue)

        properties.put(propName, propValue);
    
public ParamSetcreateParam()

        ParamSet param = new ParamSet();
        params.addElement(param);
        return param;
    
public voidexecute()

        if (subTarget == null) {
            throw new BuildException("Attribute target is required.", getLocation());
        }
        executeParameters(0);
    
private voidexecuteAntTask()

        /* if (callee == null) { */
            callee = (Ant) getProject().createTask("ant");
            callee.setOwningTarget(getOwningTarget());
            callee.setTaskName(getTaskName());
            callee.init();
        /* }                     */

        callee.setAntfile(getProject().getProperty("ant.file"));
        callee.setTarget(subTarget);
        callee.setInheritAll(inheritAll);
        callee.setInheritRefs(inheritRefs);
        Enumeration keys = properties.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            String val = (String) properties.get(key);
            Property prop = callee.createProperty();
            prop.setName(key);
            prop.setValue(val);
        }
        callee.execute();
        System.gc();
        System.gc();
        System.gc();
    
private voidexecuteForkedAntTask()

        /* if (callee2 == null) { */
            callee2 = (Java) getProject().createTask("java");
            callee2.setOwningTarget(getOwningTarget());
            callee2.setTaskName(getTaskName());
            callee2.setLocation(getLocation());
            callee2.setClassname("org.apache.tools.ant.Main");
            callee2.setAppend(true);
            callee2.setFork(true);
            callee2.createJvmarg().setValue("-Xbootclasspath/p:" + System.getProperty("sun.boot.class.path"));
        /* }                      */
        String systemClassPath = System.getProperty("java.class.path");
        callee2.setClasspath(new Path(getProject(), systemClassPath));
        String args = "-buildfile " + properties.get("file");
        Commandline.Argument arguments = callee2.createArg();
        arguments.setLine(args);
        if (verbose) {
            callee2.createArg().setValue("-verbose");
        }
        callee2.createArg().setValue(subTarget);
        if (callee2.executeJava() != 0) {
            throw new BuildException("Execution of ANT Task failed");
        }
    
private voidexecuteParameters(int paramNumber)
This method is used to recursively iterate through each parameter set. It ends up being something like:
for( i=0; i< params[0].size ; i++ )
for( j=0; j < params[1].size ; j++ )
for( k=0; k < params[2].size ; k++ )
executeTarget( params[0][i], params[1][j] , params[2][k] ) ;

        if (paramNumber == params.size()) {
            executeTarget();
        } else {
            ParamSet paramSet = (ParamSet) params.elementAt(paramNumber);
            Enumeration values = paramSet.getValues(getProject());
            while (values.hasMoreElements()) {
                String val = (String) values.nextElement();
                buildProperty(paramSet.getName(), val);
                executeParameters(paramNumber + 1);
            }
        }
    
private voidexecuteTarget()

        if (subTarget == null) {
            throw new BuildException("Attribute target is required.",
                                     getLocation());
        }
        if(fork) {
            executeForkedAntTask();
        } else {
            executeAntTask();
        }
    
public voidinit()

    
public voidsetFork(boolean f)
If true, forks the ant invocation.

param
f "true|false|on|off|yes|no"

        fork = f;
    
public voidsetInheritAll(boolean inherit)
If true, pass all properties to the new Ant project. Defaults to true.

       inheritAll = inherit;
    
public voidsetInheritRefs(boolean inheritRefs)
If true, pass all references to the new Ant project. Defaults to false

param
inheritRefs new value

        this.inheritRefs = inheritRefs;
    
public voidsetTarget(java.lang.String target)
Target to execute, required.

        subTarget = target;
    
public voidsetVerbose(boolean verbose)
Enable verbose output when signing ; optional: default false

        this.verbose = verbose;