@@ -199,14 +199,14 @@ public Class<?> compile(String script) throws ScriptException {
199
199
}
200
200
201
201
// make class loader
202
- String [] paths = project .getClassPath (false ).split (
203
- File .pathSeparator );
202
+ String [] paths = project .getClassPath (false ).split (File .pathSeparator );
204
203
URL [] urls = new URL [paths .length ];
205
204
for (int i = 0 ; i < urls .length ; i ++)
206
- urls [i ] = new URL ("file:" + paths [i ]
207
- + (paths [i ].endsWith (".jar" ) ? "" : "/" ));
208
- URLClassLoader classLoader = new URLClassLoader (urls ,
209
- Thread .currentThread ().getContextClassLoader ());
205
+ urls [i ] =
206
+ new URL ("file:" + paths [i ] + (paths [i ].endsWith (".jar" ) ? "" : "/" ));
207
+ URLClassLoader classLoader =
208
+ new URLClassLoader (urls , Thread .currentThread ()
209
+ .getContextClassLoader ());
210
210
211
211
// needed for annotation processing
212
212
Thread .currentThread ().setContextClassLoader (classLoader );
@@ -250,20 +250,42 @@ public Class<?> compile(Reader reader) throws ScriptException {
250
250
}
251
251
252
252
/**
253
- * Compiles the specified {@code .java} file.
253
+ * Compiles the specified {@code .java} file. Errors are written to the
254
+ * context error writer.
254
255
*
255
256
* @param file the source code
256
- * @param errorWriter where to write the errors
257
+ * @see #compile(File, Writer)
258
+ * @see #compile(Reader)
259
+ * @see #compile(String)
260
+ */
261
+ public void compile (final File file ) {
262
+ compile (file , null );
263
+ }
264
+
265
+ /**
266
+ * Compiles the specified {@code .java} file. Errors are written to the
267
+ * specified errorWriter or if it is null, to the context error writer.
268
+ *
269
+ * @param file the source code
270
+ * @param errorWriter where to write the errors or null to use context
271
+ * errorWriter
272
+ * @see #compile(File)
273
+ * @see #compile(Reader)
274
+ * @see #compile(String)
257
275
*/
258
276
public void compile (final File file , final Writer errorWriter ) {
259
277
try {
260
- final Builder builder = new Builder (file , null , errorWriter );
278
+ final Writer writer =
279
+ (errorWriter == null ) ? getContext ().getErrorWriter () : errorWriter ;
280
+ final Builder builder = new Builder (file , null , writer );
261
281
try {
262
282
builder .project .build ();
263
- } finally {
283
+ }
284
+ finally {
264
285
builder .cleanup ();
265
286
}
266
- } catch (Throwable t ) {
287
+ }
288
+ catch (Throwable t ) {
267
289
printOrThrow (t , errorWriter );
268
290
}
269
291
}
0 commit comments