1 19 package org.netbeans.nbbuild; 20 21 import java.util.ArrayList ; 22 import java.util.List ; 23 import java.util.StringTokenizer ; 24 import org.apache.tools.ant.BuildException; 25 import org.apache.tools.ant.Project; 26 import org.apache.tools.ant.Task; 27 import org.apache.tools.ant.taskdefs.CallTarget; 28 import org.apache.tools.ant.taskdefs.Property; 29 30 36 public class Repeat extends Task { 37 38 private List <String > values; 39 private String target; 40 private String startdir; 41 private String name; 42 43 47 public Repeat() { 48 values = new ArrayList <String >(); 49 target = null; 50 } 51 52 56 57 public void setName (String s) { 58 log ("SET name = " + s, Project.MSG_DEBUG); 59 60 name = s; 61 } 62 63 64 public void setValues (String s) { 65 log ("SET values = " + s, Project.MSG_DEBUG); 66 67 StringTokenizer tok = new StringTokenizer (s, ", "); 68 values = new ArrayList <String >(); 69 while ( tok.hasMoreTokens() ) { 70 values.add (tok.nextToken().trim()); 71 } 72 } 73 74 77 public void setTarget (String s) { 78 log ("SET target = " + s, Project.MSG_DEBUG); 79 80 target = s; 81 } 82 83 84 public void execute () throws BuildException { 85 if ( values.isEmpty() ) { 86 throw new BuildException("You must set at least one value!", getLocation()); 87 } 88 89 if ( target == null ) { 90 throw new BuildException("Target must be set!", getLocation()); 91 } 92 93 for (String val : values) { 94 log ("Process '" + val + "' location with '" + target + "' target ...", Project.MSG_VERBOSE); 95 96 CallTarget antCall = (CallTarget) getProject().createTask("antcall"); 97 antCall.init(); 98 antCall.setLocation(getLocation()); 99 100 antCall.setTarget (target); 102 Property prop = antCall.createParam(); 103 prop.setName(name); 104 prop.setValue(val); 105 106 antCall.execute(); 107 } 108 } 109 110 } 111 | Popular Tags |