ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: multiple args to java task
Date Tue, 21 Oct 2003 16:30:05 GMT
On Tuesday 21 October 2003 16:40, Dominique Devienne wrote:
> > From: peter reilly [mailto:peter.reilly@corvil.com]
> >
> > I am not too sure I understand.
> > An element to a macrodef can be optional, but if it not present, the
> > macro will simply not place it in the macro instance.
> >
> > One can emulate <apply/> for <java/> using a <foreach/> task or
**NEW** a
> > <for/> task from antcontrib.
> >
> >     <path id="xml_files">
> >         <fileset dir="." includes="**/*.xml"/>
> >     </path>
> >
> >     <for param="arg">
> >       <path refid="xml_files"/>
> >       <sequential>
> >         <java classname="Echo" classpath="classes">
> >           <arg value="${arg}"/>
> >         </java>
> >       </sequential>
> >     </for>
>
> Only in 'serial' mode Peter, and not in 'parallel' mode.
Ah, I see.
> It's enough for
> the question asked, but I'm thinking of a solution that uses <apply
> executable="java">, which should be better (leverages the full power of
> <apply>). I ever used <foreach> one time only for prototyping, before
> re-implementing the functionally in a custom task, and I always feel using
> <for> or <foreach> is the wrong route. --DD

Sometimes, for[each] is the best way - but rarely.

One could write a custom task for the parallel feature:

package task;

import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.taskdefs.Java;

public class JavaEx extends Java {
    public void addConfiguredArgPath(Path path) {
        String[] files = path.list();
        for (int i = 0; i < files.length; ++i) {
            Commandline.Argument a = createArg();
            a.setValue(files[i]);
        }
    }
}

  <target name="j2">
    <path id="xml_files">
        <fileset dir="." includes="**/*.xml"/>
    </path>
    <taskdef name="javaex" classname="task.JavaEx" classpath="classes"/>
    <javaex classname="Echo" classpath="classes">
      <argpath refid="xml_files"/>
    </javaex>
  </target>

Peter


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message