Search in sources :

Example 1 with PathClassLoader

use of com.google.devtools.j2objc.util.PathClassLoader in project j2objc by google.

the class AnnotationPreProcessor method hasAnnotationProcessors.

/**
   * Check whether any javax.annotation.processing.Processor services are defined on
   * the declared classpath. This is checked here to avoid batch compiling sources
   * in case any might have annotations that should be processed.
   */
private boolean hasAnnotationProcessors() {
    PathClassLoader loader = new PathClassLoader(options.fileUtil().getClassPathEntries());
    loader.addPaths(options.getProcessorPathEntries());
    ServiceLoader<Processor> serviceLoader = ServiceLoader.load(Processor.class, loader);
    Iterator<Processor> iterator = serviceLoader.iterator();
    return iterator.hasNext();
}
Also used : PathClassLoader(com.google.devtools.j2objc.util.PathClassLoader) Processor(javax.annotation.processing.Processor)

Example 2 with PathClassLoader

use of com.google.devtools.j2objc.util.PathClassLoader in project j2objc by google.

the class JavacParser method processAnnotations.

@Override
public ProcessingResult processAnnotations(Iterable<String> fileArgs, List<ProcessingContext> inputs) {
    final List<ProcessingContext> generatedInputs = Lists.newArrayList();
    PathClassLoader loader = new PathClassLoader(options.fileUtil().getClassPathEntries());
    loader.addPaths(options.getProcessorPathEntries());
    Iterator<Processor> serviceIterator = ServiceLoader.load(Processor.class, loader).iterator();
    if (serviceIterator.hasNext() || options.getProcessors() != null) {
        List<File> inputFiles = new ArrayList<>();
        for (ProcessingContext input : inputs) {
            inputFiles.add(new File(input.getFile().getAbsolutePath()));
        }
        try {
            JavacEnvironment env = createEnvironment(inputFiles, null, true);
            env.task().parse();
            env.task().analyze();
            processDiagnostics(env.diagnostics());
            // The source output directory is created and set in createEnvironment().
            File sourceOutputDirectory = env.fileManager().getLocation(StandardLocation.SOURCE_OUTPUT).iterator().next();
            collectGeneratedInputs(sourceOutputDirectory, "", generatedInputs);
            return new JavacProcessingResult(generatedInputs, sourceOutputDirectory);
        } catch (IOException e) {
            ErrorUtil.fatalError(e, "javac file manager error");
        }
    }
    // No annotation processors on classpath, or processing errors reported.
    return new JavacProcessingResult(generatedInputs, null);
}
Also used : ProcessingContext(com.google.devtools.j2objc.pipeline.ProcessingContext) PathClassLoader(com.google.devtools.j2objc.util.PathClassLoader) Processor(javax.annotation.processing.Processor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) InputFile(com.google.devtools.j2objc.file.InputFile) File(java.io.File)

Aggregations

PathClassLoader (com.google.devtools.j2objc.util.PathClassLoader)2 Processor (javax.annotation.processing.Processor)2 InputFile (com.google.devtools.j2objc.file.InputFile)1 RegularInputFile (com.google.devtools.j2objc.file.RegularInputFile)1 ProcessingContext (com.google.devtools.j2objc.pipeline.ProcessingContext)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1