1 19 package org.netbeans.nbbuild; 20 21 import java.io.File ; 22 import java.lang.String ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import java.util.StringTokenizer ; 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.taskdefs.Ant; 28 import org.apache.tools.ant.Task; 29 30 36 public class ForEach extends Task { 37 private static final boolean DEBUG = false; 38 private static final boolean ECHO = true; 39 40 private List <String > locations; 41 private String target; 42 private String startdir; 43 44 48 public ForEach () { 49 } 50 51 55 56 public void setLocations (String s) { 57 if ( DEBUG ) log ("SET locations = " + s); 58 59 StringTokenizer tok = new StringTokenizer (s, ","); 60 locations = new ArrayList <String >(); 61 while ( tok.hasMoreTokens() ) { 62 locations.add (tok.nextToken().trim()); 63 } 64 } 65 66 69 public void setTarget (String s) { 70 if ( DEBUG ) log ("SET target = " + s); 71 72 target = s; 73 } 74 75 77 public void setStartdir (String s) { 78 if ( DEBUG ) log ("SET startdir = " + s); 79 80 startdir = s; 81 } 82 83 84 public void execute () throws BuildException { 85 if (locations == null) { 86 throw new BuildException("You must set at least one location!", getLocation()); 87 } 88 89 if ( target == null ) { 90 target = this.getOwningTarget().getName(); 91 92 if ( DEBUG ) log ("EXECUTE owningTarget = " + this.getOwningTarget()); 93 } 94 File baseDir; 95 if ( startdir == null ) { 96 baseDir = getProject().getBaseDir(); 97 } else { 98 baseDir = new File (getProject().getBaseDir(), startdir); 99 } 100 101 for (String dirName : locations) { 102 if ( ECHO ) log ("Process '" + dirName + "' location with '" + target + "' target ..."); 103 104 Ant ant = (Ant) getProject().createTask("ant"); 105 ant.init(); 106 ant.setLocation(getLocation()); 107 108 File dir = new File (baseDir, dirName); 109 ant.setDir (dir); 110 ant.setTarget (target); 111 112 if ( DEBUG ) log ("--> next [ " + target + " ] " + dir.getAbsolutePath()); 113 114 ant.execute(); 115 } 116 } 117 118 } 119 | Popular Tags |