ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark McMillan <mark.mcmil...@engineous.com>
Subject RE: Dependency analysis
Date Tue, 18 Dec 2001 13:46:55 GMT
No, that is not the same thing.  That does not allow me to run just the 
'borland' target.  Your dependency list will also cause 'all' to run when I 
run "ant borland".  I want the reverse -- when "ant all" is run, all 
targets should build.  It could almost be done with dependencies alone, but 
not if the 'all' target has some processing it must do before the dependent 
targets run.

Just for grins, I wrote a new task called "DO" which works just like 
ANTCALL except that it recursively runs dependencies and keeps a static 
list of already-run targets.  In the dependency analysis it skips targets 
that have already run.  So my code now looks like:

   <target name="all" depends="init, compile">
     ... do some prep work here...
     <do target="borland"/>
     <do target="weblogic"/>
   </target>

The code is almost trivial... just a little recursion and a static hash table:

public class Do extends Task {
	private String targetName;
	private static Hashtable hasRunList = new Hashtable();

   public Do() {
   }
   public void setTarget(String targetName) {
     this.targetName = targetName;
   }
   public void execute() throws BuildException {
     // Get the target property
     if (targetName == null) {
       throw new BuildException("Missing 'target' parameter.", location);
     }
     runTarget(targetName);
   }

   private void runTarget(String targetName) throws BuildException {
     Target t = (Target)project.getTargets().get(targetName);
     if (t == null) {
       throw new BuildException("Target '"+targetName+"' not found.", 
location);
     }

     // Run all dependencies (that have not yet been run) before running
     // the requested target.
     Enumeration enum = t.getDependencies();
     while (enum.hasMoreElements()) {
       String depName = (String)enum.nextElement();
       if (hasRunList.get(depName) == null) { // This target has never been run
         runTarget(depName); // Recursive call to run the dependent target
       }
     }

     // Now run the requested target
     t.performTasks();

     // Add to list of targets that have been run
     hasRunList.put(targetName, t);
   }
}


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


Mime
View raw message