ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Antoine Levy-Lambert" <levylamb...@tiscali-dsl.de>
Subject Re: Can i call execute() on a std task from within a custom task?
Date Sat, 12 Apr 2003 17:22:53 GMT
Hi,

> For example, in my product, i have a list of jar files that i need to
> create: say "a.jar", "b.jar", and "c.jar".
>
> I could do something like this...
>
>     <target name="makejars">
>         <jar destfile="a.jar">
>             <fileset dir="${build.classdir}" includes="files_for_a_jar"/>
>         </jar>
>         <jar destfile="b.jar">
>             <fileset dir="${build.classdir}" includes="files_for_b_jar"/>
>         </jar>
>         <jar destfile="c.jar">
>             <fileset dir="${build.classdir}" includes="files_for_c_jar"/>
>         </jar>
>     </target>
>
> However, i'm creating a build pattern/system for multiple products in my
> company, so at build time, i the definition of what jar files are to be
> created is defined in a custom configuration file (that i already wrote a
> custom parser for since it's not in anything "standard").  The jars i'm
> creating are completly based in the configuration.  It could be anything
> such as "a.jar", "b.jar", and "c.jar" like above...but it also could be
> "a.jar", "c.jar", and d.jar...or even just "a.jar".
>

I wonder whether it is not possible to what you want without custom tasks.
One possibility (untested) would be using the ant-contrib
http://sourceforge.net/projects/ant-contrib/ on top of ant.
There is there a foreach task. If you write the list of jarfiles that you
want to generate in a property file in a format which is
recognized as list by foreach, then you could just run antcall on a generic
jar target passing the name of the jar file and the files to be included as
parameters.
If there is a limitative list of jar files that you may want to create in
your build, you can also make normal ant targets for each of a, b, c and
d.jar and create properties such as a.jar.desired, b.jar.desired,
c.jar.desired, d.jar.desired in your property file
Your build file would then look like this

<property file="desired.jars.properties"/>
<!-- desired.jar.properties looks like that
a.jar.desired=1
#b.jar is not desired, so it is omitted
#c.jar is also not desired
d.jar.desired=1
-->
<target name="all" depends="a.jar,b.jar,c.jar,d.jar"/>
<target name="a.jar" if="a.jar.desired">
<!-- instructions to create a.jar -->
</target>
<target name="b.jar" if="b.jar.desired">
<!-- instructions to create b.jar -->
</target>
<target name="c.jar" if="c.jar.desired">
<!-- instructions to create c.jar -->
</target>
<target name="d.jar" if="d.jar.desired">
<!-- instructions to create d.jar -->
</target>

this is even better, because this solution only relies on normal core ant
distribution.

> Is it legal to call the Java API "execute()" method on a standard task
> from within a custom task?
>
Yes this is legal
grep in ant for getProject().createTask() to see how this is done

here an example from an optional task


org.apache.tools.ant.taskdefs.optional.ejb.BorlandDeploymentTool.java

           org.apache.tools.ant.taskdefs.ExecTask execTask = null;
            execTask = (ExecTask) getTask().getProject().createTask("exec");
            execTask.setDir(new File("."));
            execTask.setExecutable("iastool");
            //classpath
            if (getCombinedClasspath() != null)  {
                execTask.createArg().setValue("-VBJclasspath");

execTask.createArg().setValue(getCombinedClasspath().toString());
            }

            if (java2iiopdebug) {
                execTask.createArg().setValue("-debug");
            }
            execTask.createArg().setValue("-verify");
            execTask.createArg().setValue("-src");
            // ejb jar file to verfiy
            execTask.createArg().setValue(sourceJar.getPath());
            log("Calling iastool", Project.MSG_VERBOSE);
            execTask.execute();

Antoine


Mime
View raw message