Search in sources :

Example 1 with AnnotationProcessorDeclaration

use of org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration in project gradle by gradle.

the class JdkJavaCompiler method createCompileTask.

private JavaCompiler.CompilationTask createCompileTask(JavaCompileSpec spec, JdkJavaCompilerResult result) {
    List<String> options = new JavaCompilerArgumentsBuilder(spec).build();
    JavaCompiler compiler = javaHomeBasedJavaCompilerFactory.create();
    MinimalJavaCompileOptions compileOptions = spec.getCompileOptions();
    StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(null, null, compileOptions.getEncoding() != null ? Charset.forName(compileOptions.getEncoding()) : null);
    Iterable<? extends JavaFileObject> compilationUnits = standardFileManager.getJavaFileObjectsFromFiles(spec.getSource());
    StandardJavaFileManager fileManager = standardFileManager;
    if (JavaVersion.current().isJava9Compatible() && emptySourcepathIn(options)) {
        fileManager = (StandardJavaFileManager) SourcepathIgnoringProxy.proxy(standardFileManager, StandardJavaFileManager.class);
    }
    JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, options, spec.getClasses(), compilationUnits);
    Set<AnnotationProcessorDeclaration> annotationProcessors = spec.getEffectiveAnnotationProcessors();
    if (annotationProcessors != null) {
        task = new IncrementalAnnotationProcessingCompileTask(task, annotationProcessors, spec.getAnnotationProcessorPath(), result.getAnnotationProcessingResult());
    }
    return task;
}
Also used : JavaCompiler(javax.tools.JavaCompiler) StandardJavaFileManager(javax.tools.StandardJavaFileManager) AnnotationProcessorDeclaration(org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration)

Example 2 with AnnotationProcessorDeclaration

use of org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration in project gradle by gradle.

the class IncrementalAnnotationProcessingCompiler method getEffectiveAnnotationProcessors.

/**
 * Scans the processor path for processor declarations. Filters them if the explicit <code>-processor</code> argument is given.
 * Treats explicit processors that didn't have a matching declaration on the path as non-incremental.
 */
private Set<AnnotationProcessorDeclaration> getEffectiveAnnotationProcessors(JavaCompileSpec spec) {
    Map<String, AnnotationProcessorDeclaration> declarations = annotationProcessorDetector.detectProcessors(spec.getAnnotationProcessorPath());
    List<String> compilerArgs = spec.getCompileOptions().getCompilerArgs();
    int processorIndex = compilerArgs.lastIndexOf("-processor");
    if (processorIndex == -1) {
        return Sets.newLinkedHashSet(declarations.values());
    }
    Collection<String> explicitProcessors = Splitter.on(',').splitToList(compilerArgs.get(processorIndex + 1));
    Set<AnnotationProcessorDeclaration> effectiveProcessors = Sets.newLinkedHashSet();
    for (String explicitProcessor : explicitProcessors) {
        AnnotationProcessorDeclaration declaration = declarations.get(explicitProcessor);
        if (declaration != null) {
            effectiveProcessors.add(declaration);
        } else {
            effectiveProcessors.add(new AnnotationProcessorDeclaration(explicitProcessor, IncrementalAnnotationProcessorType.UNKNOWN));
        }
    }
    return effectiveProcessors;
}
Also used : AnnotationProcessorDeclaration(org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration)

Example 3 with AnnotationProcessorDeclaration

use of org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration in project gradle by gradle.

the class IncrementalCompilerDecorator method warnAboutNonIncrementalProcessors.

private void warnAboutNonIncrementalProcessors(List<AnnotationProcessorDeclaration> nonIncrementalProcessors) {
    if (LOG.isInfoEnabled()) {
        StringBuilder processorListing = new StringBuilder();
        for (AnnotationProcessorDeclaration processor : nonIncrementalProcessors) {
            processorListing.append(TextUtil.getPlatformLineSeparator()).append('\t').append(processor);
        }
        LOG.info("{} - is not incremental. The following annotation processors don't support incremental compilation:{}", displayName, processorListing);
    }
}
Also used : AnnotationProcessorDeclaration(org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration)

Example 4 with AnnotationProcessorDeclaration

use of org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration in project gradle by gradle.

the class IncrementalCompilerDecorator method getNonIncrementalProcessors.

private List<AnnotationProcessorDeclaration> getNonIncrementalProcessors() {
    Map<String, AnnotationProcessorDeclaration> allProcessors = annotationProcessorDetector.detectProcessors(annotationProcessorPath);
    List<AnnotationProcessorDeclaration> nonIncrementalProcessors = Lists.newArrayListWithCapacity(allProcessors.size());
    for (AnnotationProcessorDeclaration processor : allProcessors.values()) {
        if (!processor.getType().isIncremental()) {
            nonIncrementalProcessors.add(processor);
        }
    }
    return nonIncrementalProcessors;
}
Also used : AnnotationProcessorDeclaration(org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration)

Example 5 with AnnotationProcessorDeclaration

use of org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration in project gradle by gradle.

the class IncrementalCompilerDecorator method getCompiler.

private Compiler<JavaCompileSpec> getCompiler(IncrementalTaskInputs inputs, CompilationSourceDirs sourceDirs) {
    if (!inputs.isIncremental()) {
        LOG.info("{} - is not incremental (e.g. outputs have changed, no previous execution, etc.).", displayName);
        return cleaningCompiler;
    }
    if (!sourceDirs.canInferSourceRoots()) {
        LOG.info("{} - is not incremental. Unable to infer the source directories.", displayName);
        return cleaningCompiler;
    }
    List<AnnotationProcessorDeclaration> nonIncrementalProcessors = getNonIncrementalProcessors();
    if (!nonIncrementalProcessors.isEmpty()) {
        warnAboutNonIncrementalProcessors(nonIncrementalProcessors);
        return cleaningCompiler;
    }
    ClassSetAnalysisData data = compileCaches.getLocalClassSetAnalysisStore().get();
    if (data == null) {
        LOG.info("{} - is not incremental. No class analysis data available from the previous build.", displayName);
        return cleaningCompiler;
    }
    PreviousCompilation previousCompilation = new PreviousCompilation(new ClassSetAnalysis(data), compileCaches.getLocalJarClasspathSnapshotStore(), compileCaches.getJarSnapshotCache(), compileCaches.getAnnotationProcessorPathStore());
    return new SelectiveCompiler(inputs, previousCompilation, cleaningCompiler, staleClassDetecter, compilationInitializer, jarClasspathSnapshotMaker);
}
Also used : PreviousCompilation(org.gradle.api.internal.tasks.compile.incremental.jar.PreviousCompilation) ClassSetAnalysisData(org.gradle.api.internal.tasks.compile.incremental.deps.ClassSetAnalysisData) ClassSetAnalysis(org.gradle.api.internal.tasks.compile.incremental.deps.ClassSetAnalysis) AnnotationProcessorDeclaration(org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration)

Aggregations

AnnotationProcessorDeclaration (org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration)10 ArrayList (java.util.ArrayList)2 Processor (javax.annotation.processing.Processor)2 JavaCompiler (javax.tools.JavaCompiler)2 StandardJavaFileManager (javax.tools.StandardJavaFileManager)2 AggregatingProcessor (org.gradle.api.internal.tasks.compile.processing.AggregatingProcessor)2 IsolatingProcessor (org.gradle.api.internal.tasks.compile.processing.IsolatingProcessor)2 URLClassLoader (java.net.URLClassLoader)1 Charset (java.nio.charset.Charset)1 JavaFileManager (javax.tools.JavaFileManager)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 ApiCompilerResult (org.gradle.api.internal.tasks.compile.ApiCompilerResult)1 ClassSetAnalysis (org.gradle.api.internal.tasks.compile.incremental.deps.ClassSetAnalysis)1 ClassSetAnalysisData (org.gradle.api.internal.tasks.compile.incremental.deps.ClassSetAnalysisData)1 PreviousCompilation (org.gradle.api.internal.tasks.compile.incremental.jar.PreviousCompilation)1 AnnotationProcessingData (org.gradle.api.internal.tasks.compile.incremental.processing.AnnotationProcessingData)1 AnnotationProcessingResult (org.gradle.api.internal.tasks.compile.incremental.processing.AnnotationProcessingResult)1 AnnotationProcessorResult (org.gradle.api.internal.tasks.compile.incremental.processing.AnnotationProcessorResult)1 IncrementalCompilationResult (org.gradle.api.internal.tasks.compile.incremental.recomp.IncrementalCompilationResult)1 RecompilationSpec (org.gradle.api.internal.tasks.compile.incremental.recomp.RecompilationSpec)1