1 28 29 package com.idaremedia.antx.flowcontrol.call; 30 31 import java.util.Iterator ; 32 import java.util.Map ; 33 34 import org.apache.tools.ant.BuildException; 35 import org.apache.tools.ant.Project; 36 import org.apache.tools.ant.Task; 37 import org.apache.tools.ant.taskdefs.Ant; 38 import org.apache.tools.ant.taskdefs.CallTarget; 39 import org.apache.tools.ant.taskdefs.Property; 40 import org.apache.tools.ant.types.PropertySet; 41 42 import com.idaremedia.antx.parameters.FixturePassthru; 43 44 61 62 public class AnyTargetCaller extends CallTarget implements TargetCaller 63 { 64 69 public AnyTargetCaller(OnceTask from, String targetName) 70 { 71 setTaskName("call"); 72 setProject(from.getProject()); 73 setOwningTarget(from.getOwningTarget()); 74 setLocation(from.getLocation()); 75 init(from,from.getPassthruOption()); 76 setTarget(targetName); 77 } 78 79 80 81 88 public AnyTargetCaller(Project project, String targetName) 89 { 90 setProject(project); 91 setTaskName("call"); 92 setTarget(targetName); 93 } 94 95 96 97 104 public void init() 105 { 106 super.init(); 107 if (m_targetName!=null) { 108 super.setTarget(m_targetName); 109 } 110 } 111 112 113 114 122 public void init(Task from, FixturePassthru fixturecontrol) 123 { 124 setProject(from.getProject()); 125 setOwningTarget(from.getOwningTarget()); 126 setLocation(from.getLocation()); 127 128 switch (fixturecontrol.getIndex()) { 129 case FixturePassthru.ALL_INDEX: { 130 setInheritRefs(true); 131 setInheritAll(true); 132 break; 133 } 134 case FixturePassthru.PROPERTIES_INDEX: { 135 setInheritAll(true); 136 break; 137 } 138 case FixturePassthru.REFERENCES_INDEX: { 139 setInheritRefs(true); 140 break; 141 } 142 case FixturePassthru.NONE_INDEX: { 143 setInheritRefs(false); 144 setInheritAll(false); 145 break; 146 } 147 } 148 } 149 150 151 154 public void setTarget(String targetName) 155 { 156 super.setTarget(targetName); 157 m_targetName = targetName; } 159 160 161 164 public String getTargetName() 165 { 166 return m_targetName; 167 } 168 169 170 173 public final void setStepName(String stepName) 174 { 175 m_stepName = stepName; 176 } 177 178 179 182 public final String getStepName() 183 { 184 return m_stepName; 185 } 186 187 188 191 public Property createProperty() 192 { 193 return createParam(); 194 } 195 196 197 202 public PropertySet createPropertySet() 203 { 204 PropertySet properties = new PropertySet(); 205 properties.setProject(getProject()); 206 addPropertyset(properties); 207 return properties; 208 } 209 210 211 215 public Ant.Reference createReference() 216 { 217 Ant.Reference r = new Ant.Reference(); 218 addReference(r); 219 return r; 220 } 221 222 223 226 public void run() 227 throws BuildException 228 { 229 maybeConfigure(); 230 execute(); 231 } 232 233 234 242 public final void run(String property, String value) 243 throws BuildException 244 { 245 Property p= this.createProperty(); 246 p.setName(property); 247 p.setValue(value); 248 run(); 249 } 250 251 252 259 public final void run(Map properties) 260 throws BuildException 261 { 262 if (!properties.isEmpty()) { 263 Iterator itr = properties.entrySet().iterator(); 264 while (itr.hasNext()) { 265 Map.Entry item = (Map.Entry )itr.next(); 266 Property p= this.createProperty(); 267 p.setName(item.getKey().toString()); 268 p.setValue(item.getValue().toString()); 269 } 270 } 271 run(); 272 } 273 274 275 281 public final void run(TargetCaller.Prep prep) 282 throws BuildException 283 { 284 prep.prepare(this); 285 run(); 286 } 287 288 289 private String m_targetName, m_stepName=""; 290 } 291 292 293 | Popular Tags |