| 1 28 29 package com.idaremedia.antx.flowcontrol.call; 30 31 import java.util.List ; 32 33 import org.apache.tools.ant.BuildException; 34 import org.apache.tools.ant.Project; 35 36 import com.idaremedia.antx.AntX; 37 import com.idaremedia.antx.AntXFixture; 38 import com.idaremedia.antx.helpers.Tk; 39 import com.idaremedia.antx.parameters.ExecutionMode; 40 import com.idaremedia.antx.parameters.FixturePassthru; 41 42 43 55 56 public abstract class OnceTask extends CallerTask 57 { 58 61 protected OnceTask() 62 { 63 super(AntX.flow+"OnceTask:"); 64 } 65 66 67 71 protected OnceTask(String iam) 72 { 73 super(iam); 74 } 75 76 80 87 public FixturePassthru getPassthruOption() 88 { 89 return FixturePassthru.PROPERTIES; 90 } 91 92 93 98 public String getStepNamesList() 99 { 100 return null; 101 } 102 103 104 108 public String getTargetNamesList() 109 { 110 return null; 111 } 112 113 114 120 public String getMacroNamesList() 121 { 122 return null; 123 } 124 125 126 127 132 public ExecutionMode getMode() 133 { 134 return ExecutionMode.ISOLATED; 135 } 136 137 138 142 146 protected int getKindOfRunnablesSpecified() 147 { 148 int N=0; 149 if (getStepNamesList()!=null) { N++; } 150 if (getTargetNamesList()!=null) { N++; } 151 if (getMacroNamesList()!=null) { N++; } 152 return N; 153 } 154 155 156 162 protected void verifyCanExecute_(String calr) 163 { 164 super.verifyCanExecute_(calr); 165 166 int Nr= getKindOfRunnablesSpecified(); 167 168 if ((Nr==0) || (Nr>1)) { String ermsg = uistrs().get("flow.targets.or.steps"); 170 log(ermsg,Project.MSG_ERR); 171 throw new BuildException(ermsg,getLocation()); 172 } 173 174 if (getMacroNamesList()!=null && getMode()!=ExecutionMode.LOCAL) { 175 String ermsg = getAntXMsg("flow.macro.islocal"); 176 log(ermsg,Project.MSG_ERR); 177 throw new BuildException(ermsg,getLocation()); 178 } 179 } 180 181 182 183 188 protected List copyOfOrderedTargetCallers() 189 throws BuildException 190 { 191 String candidateNames; 192 193 candidateNames = getStepNamesList(); 194 if (candidateNames!=null) { 195 if (getMode()==ExecutionMode.LOCAL) { 196 return createLocalTargetCallers(candidateNames,false); 197 } 198 return createStepLauncherCallers(candidateNames); 199 } 200 201 candidateNames = getTargetNamesList(); 202 if (candidateNames!=null) { 203 if (getMode()==ExecutionMode.LOCAL) { 204 return createLocalTargetCallers(candidateNames,true); 205 } 206 return createGenericTargetCallers(candidateNames); 207 } 208 209 candidateNames = getMacroNamesList(); 210 if (candidateNames!=null) { 211 return createMacroInstanceCallers(candidateNames); 212 } 213 214 return AntXFixture.newList(); 215 } 216 217 218 219 224 private List createStepLauncherCallers(String stepNames) 225 throws BuildException 226 { 227 String targetName = StepLauncherCaller.findSpecialTarget(this); 228 229 List wanted = Tk.splitList(stepNames); List actual = getFilteredStepsLike(InlineStep.class,wanted); 232 if (wanted.size()!=actual.size()) { 233 String ermsg = uistrs().get("flow.steplaunch.missing.Nsteps", 234 getOwningTarget().getName()); 235 log(ermsg, Project.MSG_ERR); 236 throw new BuildException(ermsg,getLocation()); 237 } 238 239 StepLauncherCaller caller; 240 List callers = AntXFixture.newList(wanted.size()); 241 String kindOfStep = InlineStep.class.getName(); 242 243 for (int i=0,N=wanted.size();i<N;i++) { 244 caller = StepLauncherCaller.create(this,true,targetName, 245 (String )wanted.get(i),kindOfStep, 246 2); 247 transferOverlayParameters(caller); 248 callers.add(caller); 249 } 250 251 wanted.clear(); 252 actual.clear(); 253 254 return callers; 255 } 256 257 258 259 264 private List createGenericTargetCallers(String targetNames) 265 { 266 List wanted = Tk.splitList(targetNames); 267 List callers= AntXFixture.newList(wanted.size()); 268 269 AnyTargetCaller caller; 270 String targetName; 271 272 for (int i=0,N=wanted.size();i<N;i++) { 273 targetName = (String )wanted.get(i); 274 if (!targetExists(targetName)) { 275 String ermsg = uistrs().get("flow.steplaunch.missing.target", 276 targetName, getProject().getName()); 277 log(ermsg, Project.MSG_ERR); 278 throw new BuildException(ermsg,getLocation()); 279 } 280 caller = new AnyTargetCaller(this, targetName); 281 caller.setStepName(targetName); 282 transferOverlayParameters(caller); 283 callers.add(caller); 284 } 285 286 wanted.clear(); 287 288 return callers; 289 } 290 291 292 293 300 private List createLocalTargetCallers(String nameList, boolean topLevel) 301 { 302 List l= Tk.splitList(nameList); 303 List callers= AntXFixture.newList(l.size()); 304 String tn; 305 LocalTargetCaller caller; 306 307 for (int i=0,N=l.size();i<N;i++) { 308 tn = l.get(i).toString(); 309 caller = new LocalTargetCaller(this); 310 if (topLevel) { 311 caller.setTarget(tn); 312 } else { 313 caller.setStepName(tn); 314 } 315 transferOverlayParameters(caller); 316 callers.add(caller); 317 } 318 319 return callers; 320 } 321 322 323 324 325 332 private List createMacroInstanceCallers(String nameList) 333 { 334 List l= Tk.splitList(nameList); 335 List callers= AntXFixture.newList(l.size()); 336 String tn; 337 MacroInstanceCaller caller; 338 339 for (int i=0,N=l.size();i<N;i++) { 340 tn = l.get(i).toString(); 341 caller = new MacroInstanceCaller(this); 342 caller.setTarget(tn); 343 transferOverlayParameters(caller); 344 callers.add(caller); 345 } 346 347 return callers; 348 } 349 } 350 351 | Popular Tags |