| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package net.sf.antcontrib.logic; |
| 18 |
|
| 19 |
import org.apache.tools.ant.BuildException; |
| 20 |
import org.apache.tools.ant.Task; |
| 21 |
import org.apache.tools.ant.TaskContainer; |
| 22 |
|
| 23 |
import java.util.Iterator; |
| 24 |
import java.util.Vector; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class Relentless extends Task implements TaskContainer { |
| 34 |
|
| 35 |
|
| 36 |
private Vector taskList = new Vector(); |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
private boolean terse = false; |
| 41 |
|
| 42 |
|
| 43 |
public Relentless() { |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public void execute() throws BuildException { |
| 49 |
int failCount = 0; |
| 50 |
int taskNo = 0; |
| 51 |
if ( taskList.size() == 0 ) { |
| 52 |
throw new BuildException( "No tasks specified for <relentless>." ); |
| 53 |
} |
| 54 |
log("Relentlessly executing: " + this.getDescription()); |
| 55 |
Iterator iter = taskList.iterator(); |
| 56 |
while ( iter.hasNext() ) { |
| 57 |
Task t = (Task) iter.next(); |
| 58 |
taskNo++; |
| 59 |
String desc = t.getDescription(); |
| 60 |
if ( desc == null ) { |
| 61 |
desc = "task " + taskNo; |
| 62 |
} |
| 63 |
if (!terse) log("Executing: " + desc); |
| 64 |
try { |
| 65 |
t.perform(); |
| 66 |
} catch (BuildException x) { |
| 67 |
log("Task " + desc + " failed: " + x.getMessage()); |
| 68 |
failCount++; |
| 69 |
} |
| 70 |
} |
| 71 |
if ( failCount > 0 ) { |
| 72 |
throw new BuildException( "Relentless execution: " + failCount + " of " + taskList.size() + " tasks failed." ); |
| 73 |
} |
| 74 |
else { |
| 75 |
log("All tasks completed successfully."); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public void addTask(org.apache.tools.ant.Task task) { |
| 82 |
taskList.add(task); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public void setTerse(boolean terse) { |
| 88 |
this.terse = terse; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public boolean isTerse() { |
| 94 |
return terse; |
| 95 |
} |
| 96 |
|
| 97 |
} |