1
|
|
/*
|
2
|
|
* The Apache Software License, Version 1.1
|
3
|
|
*
|
4
|
|
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
|
5
|
|
* reserved.
|
6
|
|
*
|
7
|
|
* Redistribution and use in source and binary forms, with or without
|
8
|
|
* modification, are permitted provided that the following conditions
|
9
|
|
* are met:
|
10
|
|
*
|
11
|
|
* 1. Redistributions of source code must retain the above copyright
|
12
|
|
* notice, this list of conditions and the following disclaimer.
|
13
|
|
*
|
14
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
15
|
|
* notice, this list of conditions and the following disclaimer in
|
16
|
|
* the documentation and/or other materials provided with the
|
17
|
|
* distribution.
|
18
|
|
*
|
19
|
|
* 3. The end-user documentation included with the redistribution, if
|
20
|
|
* any, must include the following acknowlegement:
|
21
|
|
* "This product includes software developed by the
|
22
|
|
* Apache Software Foundation (http://www.apache.org/)."
|
23
|
|
* Alternately, this acknowlegement may appear in the software itself,
|
24
|
|
* if and wherever such third-party acknowlegements normally appear.
|
25
|
|
*
|
26
|
|
* 4. The names "Ant" and "Apache Software
|
27
|
|
* Foundation" must not be used to endorse or promote products derived
|
28
|
|
* from this software without prior written permission. For written
|
29
|
|
* permission, please contact apache@apache.org.
|
30
|
|
*
|
31
|
|
* 5. Products derived from this software may not be called "Apache"
|
32
|
|
* nor may "Apache" appear in their names without prior written
|
33
|
|
* permission of the Apache Group.
|
34
|
|
*
|
35
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
36
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
37
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
38
|
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
39
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
40
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
41
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
42
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
43
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
44
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
45
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
46
|
|
* SUCH DAMAGE.
|
47
|
|
* ====================================================================
|
48
|
|
*
|
49
|
|
* This software consists of voluntary contributions made by many
|
50
|
|
* individuals on behalf of the Apache Software Foundation. For more
|
51
|
|
* information on the Apache Software Foundation, please see
|
52
|
|
* <http://www.apache.org/>.
|
53
|
|
*/
|
54
|
|
package org.apache.tools.ant;
|
55
|
|
|
56
|
|
import java.io.PrintStream;
|
57
|
|
import java.io.PrintWriter;
|
58
|
|
|
59
|
|
/**
|
60
|
|
* Signals an error condition during a build
|
61
|
|
*
|
62
|
|
* @author James Duncan Davidson
|
63
|
|
*/
|
64
|
|
public class BuildException extends RuntimeException {
|
65
|
|
|
66
|
|
/** Exception that might have caused this one. */
|
67
|
|
private Throwable cause;
|
68
|
|
|
69
|
|
/** Location in the build file where the exception occured */
|
70
|
|
private Location location = Location.UNKNOWN_LOCATION;
|
71
|
|
|
72
|
|
/**
|
73
|
|
* Constructs a build exception with no descriptive information.
|
74
|
|
*/
|
75
|
0
|
public BuildException() {
|
76
|
0
|
super();
|
77
|
|
}
|
78
|
|
|
79
|
|
/**
|
80
|
|
* Constructs an exception with the given descriptive message.
|
81
|
|
*
|
82
|
|
* @param message A description of or information about the exception.
|
83
|
|
* Should not be <code>null</code>.
|
84
|
|
*/
|
85
|
412
|
public BuildException(String message) {
|
86
|
412
|
super(message);
|
87
|
|
}
|
88
|
|
|
89
|
|
/**
|
90
|
|
* Constructs an exception with the given message and exception as
|
91
|
|
* a root cause.
|
92
|
|
*
|
93
|
|
* @param message A description of or information about the exception.
|
94
|
|
* Should not be <code>null</code> unless a cause is specified.
|
95
|
|
* @param cause The exception that might have caused this one.
|
96
|
|
* May be <code>null</code>.
|
97
|
|
*/
|
98
|
12
|
public BuildException(String message, Throwable cause) {
|
99
|
12
|
super(message);
|
100
|
12
|
this.cause = cause;
|
101
|
|
}
|
102
|
|
|
103
|
|
/**
|
104
|
|
* Constructs an exception with the given message and exception as
|
105
|
|
* a root cause and a location in a file.
|
106
|
|
*
|
107
|
|
* @param msg A description of or information about the exception.
|
108
|
|
* Should not be <code>null</code> unless a cause is specified.
|
109
|
|
* @param cause The exception that might have caused this one.
|
110
|
|
* May be <code>null</code>.
|
111
|
|
* @param location The location in the project file where the error
|
112
|
|
* occurred. Must not be <code>null</code>.
|
113
|
|
*/
|
114
|
9
|
public BuildException(String msg, Throwable cause, Location location) {
|
115
|
9
|
this(msg, cause);
|
116
|
9
|
this.location = location;
|
117
|
|
}
|
118
|
|
|
119
|
|
/**
|
120
|
|
* Constructs an exception with the given exception as a root cause.
|
121
|
|
*
|
122
|
|
* @param cause The exception that might have caused this one.
|
123
|
|
* Should not be <code>null</code>.
|
124
|
|
*/
|
125
|
29
|
public BuildException(Throwable cause) {
|
126
|
29
|
super(cause.toString());
|
127
|
29
|
this.cause = cause;
|
128
|
|
}
|
129
|
|
|
130
|
|
/**
|
131
|
|
* Constructs an exception with the given descriptive message and a
|
132
|
|
* location in a file.
|
133
|
|
*
|
134
|
|
* @param message A description of or information about the exception.
|
135
|
|
* Should not be <code>null</code>.
|
136
|
|
* @param location The location in the project file where the error
|
137
|
|
* occurred. Must not be <code>null</code>.
|
138
|
|
*/
|
139
|
60
|
public BuildException(String message, Location location) {
|
140
|
60
|
super(message);
|
141
|
60
|
this.location = location;
|
142
|
|
}
|
143
|
|
|
144
|
|
/**
|
145
|
|
* Constructs an exception with the given exception as
|
146
|
|
* a root cause and a location in a file.
|
147
|
|
*
|
148
|
|
* @param cause The exception that might have caused this one.
|
149
|
|
* Should not be <code>null</code>.
|
150
|
|
* @param location The location in the project file where the error
|
151
|
|
* occurred. Must not be <code>null</code>.
|
152
|
|
*/
|
153
|
0
|
public BuildException(Throwable cause, Location location) {
|
154
|
0
|
this(cause);
|
155
|
0
|
this.location = location;
|
156
|
|
}
|
157
|
|
|
158
|
|
/**
|
159
|
|
* Returns the nested exception, if any.
|
160
|
|
*
|
161
|
|
* @return the nested exception, or <code>null</code> if no
|
162
|
|
* exception is associated with this one
|
163
|
|
*/
|
164
|
24
|
public Throwable getException() {
|
165
|
24
|
return cause;
|
166
|
|
}
|
167
|
|
|
168
|
|
/**
|
169
|
|
* Returns the nested exception, if any.
|
170
|
|
*
|
171
|
|
* @return the nested exception, or <code>null</code> if no
|
172
|
|
* exception is associated with this one
|
173
|
|
*/
|
174
|
7
|
public Throwable getCause() {
|
175
|
7
|
return getException();
|
176
|
|
}
|
177
|
|
|
178
|
|
/**
|
179
|
|
* Returns the location of the error and the error message.
|
180
|
|
*
|
181
|
|
* @return the location of the error and the error message
|
182
|
|
*/
|
183
|
13
|
public String toString() {
|
184
|
13
|
return location.toString() + getMessage();
|
185
|
|
}
|
186
|
|
|
187
|
|
/**
|
188
|
|
* Sets the file location where the error occurred.
|
189
|
|
*
|
190
|
|
* @param location The file location where the error occurred.
|
191
|
|
* Must not be <code>null</code>.
|
192
|
|
*/
|
193
|
87
|
public void setLocation(Location location) {
|
194
|
87
|
this.location = location;
|
195
|
|
}
|
196
|
|
|
197
|
|
/**
|
198
|
|
* Returns the file location where the error occurred.
|
199
|
|
*
|
200
|
|
* @return the file location where the error occurred.
|
201
|
|
*/
|
202
|
156
|
public Location getLocation() {
|
203
|
156
|
return location;
|
204
|
|
}
|
205
|
|
|
206
|
|
/**
|
207
|
|
* Prints the stack trace for this exception and any
|
208
|
|
* nested exception to <code>System.err</code>.
|
209
|
|
*/
|
210
|
0
|
public void printStackTrace() {
|
211
|
0
|
printStackTrace(System.err);
|
212
|
|
}
|
213
|
|
|
214
|
|
/**
|
215
|
|
* Prints the stack trace of this exception and any nested
|
216
|
|
* exception to the specified PrintStream.
|
217
|
|
*
|
218
|
|
* @param ps The PrintStream to print the stack trace to.
|
219
|
|
* Must not be <code>null</code>.
|
220
|
|
*/
|
221
|
0
|
public void printStackTrace(PrintStream ps) {
|
222
|
0
|
synchronized (ps) {
|
223
|
0
|
super.printStackTrace(ps);
|
224
|
0
|
if (cause != null) {
|
225
|
0
|
ps.println("--- Nested Exception ---");
|
226
|
0
|
cause.printStackTrace(ps);
|
227
|
|
}
|
228
|
|
}
|
229
|
|
}
|
230
|
|
|
231
|
|
/**
|
232
|
|
* Prints the stack trace of this exception and any nested
|
233
|
|
* exception to the specified PrintWriter.
|
234
|
|
*
|
235
|
|
* @param pw The PrintWriter to print the stack trace to.
|
236
|
|
* Must not be <code>null</code>.
|
237
|
|
*/
|
238
|
7
|
public void printStackTrace(PrintWriter pw) {
|
239
|
7
|
synchronized (pw) {
|
240
|
7
|
super.printStackTrace(pw);
|
241
|
7
|
if (cause != null) {
|
242
|
2
|
pw.println("--- Nested Exception ---");
|
243
|
2
|
cause.printStackTrace(pw);
|
244
|
|
}
|
245
|
|
}
|
246
|
|
}
|
247
|
|
}
|
248
|
|
|