ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rubun Tang <rt...@algorithmics.com>
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>
		</antcall>
</target>

<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');
          main.addTask(echoIt);
          echoIt.setMessage("Building " + moduleNames[i]);

          buildIt = safari.createTask('ant');
          main.addTask(buildIt);
          buildIt.setAntfile("build.xml");
          buildIt.setDir(new
java.io.File(safari.getProperty("basedir") + "/src/" + moduleNames[i]));
          buildIt.setTarget("${action}");
          buildIt.setInheritAll(false);
      }
  ]]></script>
</target>

-----Original Message-----
From: Peter Mularien [mailto:pmularien@deploy.com]
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(
          "framework",
          "viewer",
          "importer",
          "printer"
          );
      var i=0;
      for(i=0; i<moduleNames.length; i++) {
          echoIt = Framework.createTask('echo');
          call.addTask(echoIt);
          echoIt.setMessage("Building " + moduleNames[i]);

          buildIt = Framework.createTask('ant');
          call.addTask(buildIt);
          buildIt.setAntfile("build.xml");
          buildIt.setDir(new
java.io.File(Framework.getProperty("basedir") + "/" + moduleNames[i]));
          buildIt.setTarget("build-one-project");
          buildIt.setInheritAll(false);
      }
  ]]></script>

... 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)
   /Logging/build.xml
   /Common/build.xml
   ... etc.

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

HTH
Peter


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>
[snip]

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

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