Debian Codegraph @

src/main/java/net/sf/antcontrib/logic/Relentless.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2004-2005 Ant-Contrib project. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 /** Relentless is an Ant task that will relentlessly execute other tasks,
27 * ignoring any failures until all tasks have completed. If any of the
28 * executed tasks fail, then Relentless will fail; otherwise it will succeed.
29 *
30 * @author Christopher Heiny
31 * @version $Id: Relentless.java 12 2006-08-09 17:48:45Z mattinger $
32 */
33 public class Relentless extends Task implements TaskContainer {
34 /** We keep the list of tasks we will execute here.
35 */
36 private Vector taskList = new Vector();
37
38 /** Flag indicating how much output to generate.
39 */
40 private boolean terse = false;
41
42 /** Creates a new Relentless task. */
43 public Relentless() {
44 }
45
46 /** This method will be called when it is time to execute the task.
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 /** Ant will call this to inform us of nested tasks.
80 */
81 public void addTask(org.apache.tools.ant.Task task) {
82 taskList.add(task);
83 }
84
85 /** Set this to true to reduce the amount of output generated.
86 */
87 public void setTerse(boolean terse) {
88 this.terse = terse;
89 }
90
91 /** Retrieve the terse property, indicating how much output we will generate.
92 */
93 public boolean isTerse() {
94 return terse;
95 }
96
97 }