62
62
import java .util .LinkedHashMap ;
63
63
import java .util .List ;
64
64
import java .util .Map ;
65
+ import java .util .Map .Entry ;
65
66
import java .util .Properties ;
66
67
import java .util .Set ;
67
68
import java .util .StringTokenizer ;
@@ -190,6 +191,17 @@ public CompilerResult performCompile( CompilerConfiguration config )
190
191
if (! propFile .exists () || ! propFile .isFile ())
191
192
throw new IllegalArgumentException ("Properties file " + propFile + " does not exist" );
192
193
}
194
+
195
+ for (Entry <String , String > entry : extras .entrySet ()) {
196
+ String opt = entry .getKey ();
197
+ if (! opt .startsWith ("-" ))
198
+ opt = "-" + opt ; // This is beyond sad
199
+ args .add (opt );
200
+ String value = entry .getValue ();
201
+ if (null != value && ! value .isEmpty ())
202
+ args .add (value );
203
+ }
204
+
193
205
//settings.putAll( extras );
194
206
195
207
//if ( settings.containsKey( "properties" ) )
@@ -220,9 +232,12 @@ public CompilerResult performCompile( CompilerConfiguration config )
220
232
// }
221
233
//}
222
234
235
+ // Output path
236
+ args .add ("-d" );
237
+ args .add (config .getOutputLocation ());
238
+
223
239
// Annotation processors defined?
224
240
List <String > extraSourceDirs = new ArrayList <>();
225
-
226
241
if (!isPreJava16 (config )) {
227
242
//now add jdk 1.6 annotation processing related parameters
228
243
String [] annotationProcessors = config .getAnnotationProcessors ();
@@ -247,27 +262,26 @@ public CompilerResult performCompile( CompilerConfiguration config )
247
262
File generatedSourcesDir = config .getGeneratedSourcesDirectory ();
248
263
if (generatedSourcesDir != null ) {
249
264
generatedSourcesDir .mkdirs ();
265
+ extraSourceDirs .add (generatedSourcesDir .getAbsolutePath ());
266
+
267
+ //-- option to specify where annotation processor is to generate its output
268
+ args .add ("-s" );
269
+ args .add (generatedSourcesDir .getAbsolutePath ());
250
270
}
251
271
if (config .getProc () != null ) {
252
272
args .add ("-proc:" + config .getProc ());
253
273
}
254
- extraSourceDirs .add (generatedSourcesDir .getAbsolutePath ());
255
274
}
256
275
}
257
276
258
- // Output path
259
- args .add ("-d" );
260
- args .add (config .getOutputLocation ());
261
-
262
277
//-- Write .class files even when error occur, but make sure methods with compile errors do abort when called
263
278
//args.add("-proceedOnError:Fatal"); probably not a good plan as it will cause incremental compile to not work
264
279
265
280
//-- classpath
266
- List <String > classpathEntries = config .getClasspathEntries ();
267
- if (classpathEntries .size () != 0 ) {
268
- args .add ("-classpath" );
269
- args .add (getPathString (classpathEntries ));
270
- }
281
+ List <String > classpathEntries = new ArrayList <>(config .getClasspathEntries ());
282
+ classpathEntries .add (config .getOutputLocation ());
283
+ args .add ("-classpath" );
284
+ args .add (getPathString (classpathEntries ));
271
285
272
286
// ----------------------------------------------------------------------
273
287
// Compile!
@@ -298,13 +312,13 @@ public CompilerResult performCompile( CompilerConfiguration config )
298
312
return new CompilerResult (true , Collections .EMPTY_LIST );
299
313
}
300
314
301
- System .out .println (">>>> ECJ: " + args );
315
+ // System.out.println(">>>> ECJ: " + args);
302
316
303
317
StringWriter sw = new StringWriter ();
304
318
PrintWriter devNull = new PrintWriter (sw );
305
319
306
320
//BatchCompiler.compile(args.toArray(new String[args.size()]), new PrintWriter(System.err), new PrintWriter(System.out), new CompilationProgress() {
307
- boolean worked = BatchCompiler .compile (args .toArray (new String [args .size ()]), devNull , devNull , new CompilationProgress () {
321
+ BatchCompiler .compile (args .toArray (new String [args .size ()]), devNull , devNull , new CompilationProgress () {
308
322
@ Override public void begin (int i ) {
309
323
310
324
}
@@ -330,10 +344,6 @@ public CompilerResult performCompile( CompilerConfiguration config )
330
344
boolean hasError = false ;
331
345
if (errorF .length () < 80 ) {
332
346
throw new IOException ("Failed to run the ECJ compiler:\n " + sw .toString ());
333
- //messageList = new ArrayList<>();
334
- //messageList.add(new CompilerMessage("Internal compiler error"));
335
- //System.err.println(">> " + sw.toString());
336
- //return new CompilerResult(false, messageList);
337
347
}
338
348
messageList = new EcjResponseParser ().parse (errorF , errorsAsWarnings );
339
349
@@ -348,11 +358,11 @@ public CompilerResult performCompile( CompilerConfiguration config )
348
358
} catch (Exception x ) {
349
359
throw new RuntimeException (x ); // sigh
350
360
} finally {
351
- // if(null != errorF) {
352
- // try {
353
- // errorF.delete();
354
- // } catch(Exception x) {}
355
- // }
361
+ if (null != errorF ) {
362
+ try {
363
+ errorF .delete ();
364
+ } catch (Exception x ) {}
365
+ }
356
366
}
357
367
}
358
368
0 commit comments