ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rubun Tang <>
Subject RE: looping in ant
Date Fri, 25 Jan 2002 19:45:53 GMT
Hi Peter,

This is exactly what I want to do - a master build file called
sub-components' build file in subdirectory.

I've got the script working. However, instead of calling a target statically
in the sub-component build.xml (in this case "build-one-project"), I want to
make this as a property with various property. To be precise, it's nice to
have something like this;

<target name="clean">
		<antcall target="subbuild">
			<param name="action" value="clean"></param>

<target name="subbuild">
		<script language="javascript"><![CDATA[
      	var moduleNames=new Array("helper","jtas","name","rg", "ctrl",
"octl", "tas","tr");
      var i=0;
      for(i=0; i<moduleNames.length; i++) {
          echoIt = safari.createTask('echo');
          echoIt.setMessage("Building " + moduleNames[i]);

          buildIt = safari.createTask('ant');
          buildIt.setDir(new"basedir") + "/src/" + moduleNames[i]));

-----Original Message-----
From: Peter Mularien []
Sent: Friday, January 25, 2002 10:13 AM
To: Ant Users List
Subject: Re: looping in ant

Alternatively, you could use script, and do something like:

  <!-- adding a new module is really simple - just add it to  -->
  <!-- the list of moduleNames in JavaScript below!           -->
  <!-- note that the modules are executed in the order they   -->
  <!-- appear in the array, so watch out!                     -->
  <script language="javascript"><![CDATA[
      var moduleNames=new Array(
      var i=0;
      for(i=0; i<moduleNames.length; i++) {
          echoIt = Framework.createTask('echo');
          echoIt.setMessage("Building " + moduleNames[i]);

          buildIt = Framework.createTask('ant');
          buildIt.setDir(new"basedir") + "/" + moduleNames[i]));

... where Framework in the for loop is the name of your project (name
attribute of top-level project element). This example assumes you're
calling separate build files (took it from our build) but you can
definitely also createTask('antcall') and do things you want that way.
It's a little trickier with antcall because you need to figure out how
to pass parameters.

We had separated each of our components into separate build files, so
they could all be built independently, like this:

 Framework/build.xml (from whence that code was taken)
   ... etc.

Maybe a refactor like that would make a few things easier for you


Scott Ellsworth wrote:
> I would love to be able to say:
>    <property name="comtargets" value="framework,viewer,importer,printer"/>
> I would love to write:
>    <target name="build-all-projects" description="Build all defined
> projects">
>         <echo message="Building com projects"/>
>      <foreach project in build.projects>
>        <antcall target="build-one-project">
>          <param name="build.project" value="${project}"/>
>        </antcall>
>      </foreach>
>    </target>
> rather than
>    <target name="build-all-projects" description="Build all defined
> projects">
>         <echo message="Building com projects"/>
>      <antcall target="build-one-project">
>        <param name="build.project" value="framework"/>
>      </antcall>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message