1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.nuxeo.build.ant;
20
21 import java.util.Hashtable;
22
23 import org.apache.tools.ant.BuildException;
24 import org.apache.tools.ant.ExitStatusException;
25 import org.apache.tools.ant.Project;
26 import org.apache.tools.ant.Target;
27 import org.apache.tools.ant.Task;
28 import org.apache.tools.ant.UnknownElement;
29 import org.apache.tools.ant.taskdefs.Exit;
30 import org.apache.tools.ant.taskdefs.condition.Condition;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 public class ExitTask extends Exit {
58
59 private final class False implements Condition {
60 @Override
61 public boolean eval() throws BuildException {
62 return false;
63 }
64 }
65
66 private False falseCondition = new False();
67
68 @Override
69
70
71
72
73
74
75
76
77
78
79
80
81
82 public void execute() throws BuildException {
83 String exitMsg = null;
84 try {
85 super.execute();
86
87 return;
88 } catch (ExitStatusException e) {
89 if (e.getStatus() > 0) {
90 throw e;
91 } else {
92 exitMsg = e.getMessage();
93 }
94 } catch (BuildException e) {
95 exitMsg = e.getMessage();
96 }
97 exit(exitMsg);
98 }
99
100 protected void exit(String message) {
101 Task doNothing = new Task() {
102 };
103 getProject().log(message, Project.MSG_INFO);
104 Target owningTarget = getOwningTarget();
105 Hashtable<String, Target> targets = getProject().getTargets();
106 for (Target eachTarget : targets.values()) {
107 eachTarget.setIf(falseCondition);
108 if (eachTarget == owningTarget) {
109 for (Task task : eachTarget.getTasks()) {
110 getProject().log("Invalidating tasks from " + eachTarget,
111 Project.MSG_DEBUG);
112 try {
113 if (task instanceof UnknownElement) {
114 UnknownElement currentTask = (UnknownElement) task;
115 if (currentTask.getRealThing() == this) {
116 continue;
117 }
118 getProject().log(
119 "Invalidated " + currentTask.getTaskName(),
120 Project.MSG_DEBUG);
121 currentTask.setRealThing(doNothing);
122 } else {
123 getProject().log(
124 "Not an UnknownElement: "
125 + task.getTaskName(),
126 Project.MSG_DEBUG);
127 }
128 } catch (SecurityException | IllegalArgumentException e) {
129 throw new BuildException(e);
130 }
131 }
132 }
133 }
134 }
135
136 }