ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Allan <ste...@wrq.com>
Subject RE: Passing targets to subprojects with ant using javascript
Date Fri, 29 Mar 2002 01:18:32 GMT
After reading the antlist archive a little better, I found a thread from
January that matched my situation in which Peter showed a way which is much
better.  Turns out I was trying to do it backwards.  Instead of having my
subproj script be a dependency for my targets, it's much more natural to
have the targets call the script.  As Peter suggested:

<target name = "clean">
 <antcall target = "call">
  <param name = "script.target" value = "clean"/>
 </antcall>
</target>

Then all references in the javascript are to "call", instead of the target
I'm trying to pass.  Don't know what the heck I was thinking before!

My modified example is included below just to complete the thread - critique
is always welcome.

Thanks.

-- Steve

  <!-- clean target -->
  <target name = "clean">
   <antcall target = "dosubproj">
    <param name = "target" value = "clean"/>
   </antcall>
  </target>

  <!-- dosubproj target calls ant in each subproject and passes target -->
  <target name="dosubproj">
   <script language="javascript"><![CDATA[
      // Add new subprojects to this array.  They'll be built
      // in the order they appear in the array.
      var subproj = new Array(
	list snipped to save space
	);
      for (i = 0; i < subproj.length; i++) {
         target = new java.io.File(testproj.getProperty("target"));
         build = testproj.createTask('ant');
         build.setAntfile("build.xml");
         build.setDir(new java.io.File(testproj.getProperty("basedir") + "/"
+ subproj[i]));
         build.setInheritAll(false);
         // Pass the target name unless it's the default target
         if(target != "") {
            build.setTarget(target);
         }
         dosubproj.addTask(build);
      }]]> </script></target>


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


Mime
View raw message