Java extractor: use ServiceLoader Processors XOR use --processors
Reviewers: shahms, #core_team, zarko
Subscribers: #core_team
@@ -703,29 +703,30 @@ public class JavaCompilationUnitExtractor {
null, fileManager, diagnosticsCollector, completeOptions, null, sourceFiles);
List<Processor> procs = Lists.<Processor>newArrayList(new ProcessAnnotation(fileManager));
- Set<Class<?>> loadedProcessors = new HashSet<>();
-
- // Add any processors registered in the META-INF/services configuration.
ClassLoader loader = processingClassloader(classpath, processorpath);
- for (Processor proc : ServiceLoader.load(Processor.class, loader)) {
- procs.add(proc);
- loadedProcessors.add(proc.getClass());
- }
// Add any processors passed as flags.
for (String processor : processors) {
try {
- Class<?> procClass = loader.loadClass(processor);
- if (!loadedProcessors.add(procClass)) {
- // Skip processors already loaded from the META-INF/services configuration.
- continue;
- }
- procs.add(procClass.asSubclass(Processor.class).getConstructor().newInstance());
+ procs.add(
+ loader
+ .loadClass(processor)
+ .asSubclass(Processor.class)
+ .getConstructor()
+ .newInstance());
} catch (ReflectiveOperationException e) {
throw new ExtractionException("Bad processor entry", e, false);
}
}
+ if (procs.isEmpty()) {
+ // If no --processors were passed, add any processors registered in the META-INF/services
+ // configuration.
+ for (Processor proc : ServiceLoader.load(Processor.class, loader)) {
+ procs.add(proc);
+ }
+ }
+
JavacTask javacTask = (JavacTask) task;
javacTask.setProcessors(procs);
syms = Symtab.instance(((JavacTaskImpl) javacTask).getContext());
