34
34
import org .codehaus .plexus .util .IOUtil ;
35
35
import org .codehaus .plexus .util .StringUtils ;
36
36
import org .eclipse .jdt .core .compiler .IProblem ;
37
+ import org .eclipse .jdt .core .compiler .batch .BatchCompiler ;
37
38
import org .eclipse .jdt .internal .compiler .ClassFile ;
38
39
import org .eclipse .jdt .internal .compiler .CompilationResult ;
39
40
import org .eclipse .jdt .internal .compiler .Compiler ;
40
41
import org .eclipse .jdt .internal .compiler .DefaultErrorHandlingPolicies ;
41
42
import org .eclipse .jdt .internal .compiler .ICompilerRequestor ;
42
43
import org .eclipse .jdt .internal .compiler .IErrorHandlingPolicy ;
43
44
import org .eclipse .jdt .internal .compiler .IProblemFactory ;
45
+ import org .eclipse .jdt .internal .compiler .apt .dispatch .BatchAnnotationProcessorManager ;
46
+ import org .eclipse .jdt .internal .compiler .batch .CompilationUnit ;
44
47
import org .eclipse .jdt .internal .compiler .classfmt .ClassFileReader ;
45
48
import org .eclipse .jdt .internal .compiler .classfmt .ClassFormatException ;
46
49
import org .eclipse .jdt .internal .compiler .env .ICompilationUnit ;
62
65
import java .util .ArrayList ;
63
66
import java .util .HashMap ;
64
67
import java .util .Iterator ;
68
+ import java .util .LinkedHashMap ;
65
69
import java .util .LinkedList ;
66
70
import java .util .List ;
67
71
import java .util .Locale ;
68
- import java .util .LinkedHashMap ;
69
72
import java .util .Map ;
70
73
import java .util .Properties ;
71
74
import java .util .Set ;
@@ -231,6 +234,55 @@ public CompilerResult performCompile( CompilerConfiguration config )
231
234
CompilerOptions options = new CompilerOptions ( settings );
232
235
Compiler compiler = new Compiler ( env , policy , options , requestor , problemFactory );
233
236
237
+ // Annotation processors defined?
238
+ if ( !isPreJava16 ( config ) )
239
+ {
240
+ //now add jdk 1.6 annotation processing related parameters
241
+
242
+
243
+ String [] annotationProcessors = config .getAnnotationProcessors ();
244
+ List <String > processorPathEntries = config .getProcessorPathEntries ();
245
+ if ((annotationProcessors != null && annotationProcessors .length > 0 ) || (processorPathEntries != null && processorPathEntries .size () > 0 ))
246
+ {
247
+ List <String > args = new ArrayList <>();
248
+ if (annotationProcessors != null && annotationProcessors .length > 0 ) {
249
+ args .add ("-processor" );
250
+ StringBuilder sb = new StringBuilder ();
251
+ for (String ap : annotationProcessors ) {
252
+ if (sb .length () > 0 )
253
+ sb .append (',' );
254
+ sb .append (ap );
255
+ }
256
+ args .add (sb .toString ());
257
+ }
258
+
259
+ if (processorPathEntries != null && processorPathEntries .size () > 0 ) {
260
+ args .add ("-processorpath" );
261
+ args .add (getPathString (processorPathEntries ));
262
+ }
263
+
264
+ File generatedSourcesDir = config .getGeneratedSourcesDirectory ();
265
+ if ( generatedSourcesDir != null )
266
+ {
267
+ generatedSourcesDir .mkdirs ();
268
+
269
+ //args.add( "-s" );
270
+ //args.add( generatedSourcesDir.getAbsolutePath() );
271
+ }
272
+ if ( config .getProc () != null )
273
+ {
274
+ args .add ("-proc:" + config .getProc ());
275
+ }
276
+
277
+ BatchAnnotationProcessorManager bapm = new BatchAnnotationProcessorManager ();
278
+ bapm .configure (compiler , args .toArray (new String [args .size ()]));
279
+ compiler .annotationProcessorManager = bapm ;
280
+ }
281
+ }
282
+
283
+ BatchCompiler bc = BatchCompiler .
284
+
285
+
234
286
ICompilationUnit [] units = compilationUnits .toArray ( new ICompilationUnit [compilationUnits .size ()] );
235
287
236
288
compiler .compile ( units );
@@ -249,6 +301,17 @@ public CompilerResult performCompile( CompilerConfiguration config )
249
301
return compilerResult ;
250
302
}
251
303
304
+ private boolean isPreJava16 (CompilerConfiguration config ) {
305
+ String s = config .getSourceVersion ();
306
+ if ( s == null )
307
+ {
308
+ //now return true, as the 1.6 version is not the default - 1.4 is.
309
+ return true ;
310
+ }
311
+ return s .startsWith ( "1.5" ) || s .startsWith ( "1.4" ) || s .startsWith ( "1.3" ) || s .startsWith ( "1.2" )
312
+ || s .startsWith ( "1.1" ) || s .startsWith ( "1.0" );
313
+ }
314
+
252
315
// The compiler mojo adds a dash to all keys which does not make sense for the eclipse compiler
253
316
Map <String , String > cleanKeyNames ( Map <String , String > customCompilerArgumentsAsMap )
254
317
{
0 commit comments