10
10
import java .io .File ;
11
11
import java .io .IOException ;
12
12
import java .util .ArrayList ;
13
- import java .util .Arrays ;
14
13
import java .util .Collection ;
14
+ import java .util .Collections ;
15
15
import java .util .EnumSet ;
16
16
import java .util .HashSet ;
17
17
import java .util .List ;
@@ -57,7 +57,7 @@ public enum Library {
57
57
58
58
private final String name ;
59
59
60
- private Library (String name ) {
60
+ Library (String name ) {
61
61
this .name = name ;
62
62
}
63
63
@@ -82,7 +82,7 @@ public String getName() {
82
82
PROCESSOR_OUT_DIR = new File ( TARGET_DIR , "processor-generated-test-classes" );
83
83
if ( !PROCESSOR_OUT_DIR .exists () ) {
84
84
if ( !PROCESSOR_OUT_DIR .mkdirs () ) {
85
- fail ( "Unable to create test output directory " + PROCESSOR_OUT_DIR . toString () );
85
+ fail ( "Unable to create test output directory " + PROCESSOR_OUT_DIR );
86
86
}
87
87
}
88
88
}
@@ -163,7 +163,23 @@ public boolean compile(Processor annotationProcessor, DiagnosticCollector<JavaFi
163
163
EnumSet <Library > dependencies , File ... sourceFiles ) {
164
164
StandardJavaFileManager fileManager = compiler .getStandardFileManager ( null , null , null );
165
165
Iterable <? extends JavaFileObject > compilationUnits = fileManager .getJavaFileObjects ( sourceFiles );
166
- List <String > options = new ArrayList <String >();
166
+ try {
167
+ fileManager .setLocation ( StandardLocation .CLASS_PATH , getDependenciesAsFiles ( dependencies ) );
168
+ fileManager .setLocation ( StandardLocation .CLASS_OUTPUT , Collections .singletonList ( PROCESSOR_OUT_DIR ) );
169
+ }
170
+ catch (IOException e ) {
171
+ throw new RuntimeException ( e );
172
+ }
173
+
174
+ final List <String > options = extractOptions ( diagnosticKind , verbose , allowMethodConstraints );
175
+ CompilationTask task = compiler .getTask ( null , fileManager , diagnostics , options , null , compilationUnits );
176
+ task .setProcessors ( Collections .singletonList ( annotationProcessor ) );
177
+
178
+ return task .call ();
179
+ }
180
+
181
+ private static List <String > extractOptions (Kind diagnosticKind , Boolean verbose , Boolean allowMethodConstraints ) {
182
+ final List <String > options = new ArrayList <>();
167
183
168
184
if ( diagnosticKind != null ) {
169
185
options .add ( StringHelper .format ( "-A%s=%s" , Configuration .DIAGNOSTIC_KIND_PROCESSOR_OPTION , diagnosticKind ) );
@@ -174,27 +190,9 @@ public boolean compile(Processor annotationProcessor, DiagnosticCollector<JavaFi
174
190
}
175
191
176
192
if ( allowMethodConstraints != null ) {
177
- options .add (
178
- StringHelper .format (
179
- "-A%s=%b" ,
180
- Configuration .METHOD_CONSTRAINTS_SUPPORTED_PROCESSOR_OPTION ,
181
- allowMethodConstraints
182
- )
183
- );
193
+ options .add ( StringHelper .format ( "-A%s=%b" , Configuration .METHOD_CONSTRAINTS_SUPPORTED_PROCESSOR_OPTION , allowMethodConstraints ) );
184
194
}
185
-
186
- try {
187
- fileManager .setLocation ( StandardLocation .CLASS_PATH , getDependenciesAsFiles ( dependencies ) );
188
- fileManager .setLocation ( StandardLocation .CLASS_OUTPUT , Arrays .asList ( PROCESSOR_OUT_DIR ) );
189
- }
190
- catch (IOException e ) {
191
- throw new RuntimeException ( e );
192
- }
193
-
194
- CompilationTask task = compiler .getTask ( null , fileManager , diagnostics , options , null , compilationUnits );
195
- task .setProcessors ( Arrays .asList ( annotationProcessor ) );
196
-
197
- return task .call ();
195
+ return options ;
198
196
}
199
197
200
198
/**
@@ -226,7 +224,7 @@ private static Set<DiagnosticExpectation> asExpectations(Collection<Diagnostic<?
226
224
}
227
225
228
226
private Set <File > getDependenciesAsFiles (EnumSet <Library > dependencies ) {
229
- Set <File > files = new HashSet <File >();
227
+ Set <File > files = new HashSet <>();
230
228
231
229
for ( Library oneDependency : dependencies ) {
232
230
files .add ( new File ( testLibraryDir + File .separator + oneDependency .getName () ) );
0 commit comments