Search in sources :

Example 1 with IncrementalCompilationResult

use of org.gradle.api.internal.tasks.compile.incremental.recomp.IncrementalCompilationResult in project gradle by gradle.

the class IncrementalResultStoringCompiler method getAnnotationProcessingData.

private AnnotationProcessingData getAnnotationProcessingData(JavaCompileSpec spec, WorkResult result) {
    Set<AnnotationProcessorDeclaration> processors = spec.getEffectiveAnnotationProcessors();
    if (processors.isEmpty()) {
        return new AnnotationProcessingData();
    }
    AnnotationProcessingData previousAnnotationProcessingData = null;
    RecompilationSpec recompilationSpec = null;
    if (result instanceof IncrementalCompilationResult) {
        previousAnnotationProcessingData = ((IncrementalCompilationResult) result).getPreviousCompilationData().getAnnotationProcessingData();
        recompilationSpec = ((IncrementalCompilationResult) result).getRecompilationSpec();
        result = ((IncrementalCompilationResult) result).getCompilerResult();
    }
    Set<String> changedClasses = recompilationSpec == null ? Collections.emptySet() : recompilationSpec.getClassesToCompile();
    if (result instanceof ApiCompilerResult) {
        AnnotationProcessingResult processingResult = ((ApiCompilerResult) result).getAnnotationProcessingResult();
        AnnotationProcessingData newAnnotationProcessingData = new AnnotationProcessingData(processingResult.getGeneratedTypesWithIsolatedOrigin(), processingResult.getAggregatedTypes(), processingResult.getGeneratedAggregatingTypes(), processingResult.getGeneratedResourcesWithIsolatedOrigin(), processingResult.getGeneratedAggregatingResources(), processingResult.getFullRebuildCause());
        if (previousAnnotationProcessingData == null) {
            return newAnnotationProcessingData;
        }
        return mergeAnnotationProcessingData(previousAnnotationProcessingData, newAnnotationProcessingData, changedClasses);
    }
    return new AnnotationProcessingData(ImmutableMap.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableMap.of(), ImmutableSet.of(), "the chosen compiler did not support incremental annotation processing");
}
Also used : AnnotationProcessingData(org.gradle.api.internal.tasks.compile.incremental.processing.AnnotationProcessingData) RecompilationSpec(org.gradle.api.internal.tasks.compile.incremental.recomp.RecompilationSpec) IncrementalCompilationResult(org.gradle.api.internal.tasks.compile.incremental.recomp.IncrementalCompilationResult) AnnotationProcessingResult(org.gradle.api.internal.tasks.compile.incremental.processing.AnnotationProcessingResult) ApiCompilerResult(org.gradle.api.internal.tasks.compile.ApiCompilerResult) AnnotationProcessorDeclaration(org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration)

Example 2 with IncrementalCompilationResult

use of org.gradle.api.internal.tasks.compile.incremental.recomp.IncrementalCompilationResult in project gradle by gradle.

the class IncrementalResultStoringCompiler method getCompilerApiData.

private CompilerApiData getCompilerApiData(JavaCompileSpec spec, WorkResult result) {
    if (spec.getCompileOptions().supportsCompilerApi()) {
        CompilerApiData previousCompilerApiData = null;
        RecompilationSpec recompilationSpec = null;
        if (result instanceof IncrementalCompilationResult) {
            previousCompilerApiData = ((IncrementalCompilationResult) result).getPreviousCompilationData().getCompilerApiData();
            recompilationSpec = ((IncrementalCompilationResult) result).getRecompilationSpec();
            result = ((IncrementalCompilationResult) result).getCompilerResult();
        }
        Set<String> changedClasses = recompilationSpec == null ? Collections.emptySet() : recompilationSpec.getClassesToCompile();
        ConstantToDependentsMapping previousConstantToDependentsMapping = previousCompilerApiData == null ? null : previousCompilerApiData.getConstantToClassMapping();
        Map<String, Set<String>> previousSourceClassesMapping = previousCompilerApiData == null ? null : previousCompilerApiData.getSourceToClassMapping();
        if (result instanceof ApiCompilerResult) {
            ApiCompilerResult jdkJavaResult = (ApiCompilerResult) result;
            ConstantToDependentsMapping newConstantsToDependentsMapping = jdkJavaResult.getConstantsAnalysisResult().getConstantToDependentsMapping().orElseThrow(() -> new GradleException("Constants to dependents mapping not present, but it should be"));
            Map<String, Set<String>> newSourceClassesMapping = jdkJavaResult.getSourceClassesMapping();
            Map<String, Set<String>> mergedSourceClassesMapping;
            if (previousSourceClassesMapping == null) {
                mergedSourceClassesMapping = newSourceClassesMapping;
            } else {
                mergedSourceClassesMapping = mergeSourceClassesMappings(previousSourceClassesMapping, newSourceClassesMapping, changedClasses);
            }
            ConstantToDependentsMapping mergedConstants = new ConstantToDependentsMappingMerger().merge(newConstantsToDependentsMapping, previousConstantToDependentsMapping, changedClasses);
            if (spec.getCompileOptions().supportsConstantAnalysis()) {
                return CompilerApiData.withConstantsMapping(mergedSourceClassesMapping, mergedConstants);
            } else {
                return CompilerApiData.withoutConstantsMapping(mergedSourceClassesMapping);
            }
        }
    }
    return CompilerApiData.unavailable();
}
Also used : CompilerApiData(org.gradle.api.internal.tasks.compile.incremental.compilerapi.CompilerApiData) RecompilationSpec(org.gradle.api.internal.tasks.compile.incremental.recomp.RecompilationSpec) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) IncrementalCompilationResult(org.gradle.api.internal.tasks.compile.incremental.recomp.IncrementalCompilationResult) GradleException(org.gradle.api.GradleException) ConstantToDependentsMappingMerger(org.gradle.api.internal.tasks.compile.incremental.compilerapi.constants.ConstantToDependentsMappingMerger) ApiCompilerResult(org.gradle.api.internal.tasks.compile.ApiCompilerResult) ConstantToDependentsMapping(org.gradle.api.internal.tasks.compile.incremental.compilerapi.constants.ConstantToDependentsMapping)

Aggregations

ApiCompilerResult (org.gradle.api.internal.tasks.compile.ApiCompilerResult)2 IncrementalCompilationResult (org.gradle.api.internal.tasks.compile.incremental.recomp.IncrementalCompilationResult)2 RecompilationSpec (org.gradle.api.internal.tasks.compile.incremental.recomp.RecompilationSpec)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 GradleException (org.gradle.api.GradleException)1 CompilerApiData (org.gradle.api.internal.tasks.compile.incremental.compilerapi.CompilerApiData)1 ConstantToDependentsMapping (org.gradle.api.internal.tasks.compile.incremental.compilerapi.constants.ConstantToDependentsMapping)1 ConstantToDependentsMappingMerger (org.gradle.api.internal.tasks.compile.incremental.compilerapi.constants.ConstantToDependentsMappingMerger)1 AnnotationProcessingData (org.gradle.api.internal.tasks.compile.incremental.processing.AnnotationProcessingData)1 AnnotationProcessingResult (org.gradle.api.internal.tasks.compile.incremental.processing.AnnotationProcessingResult)1 AnnotationProcessorDeclaration (org.gradle.api.internal.tasks.compile.processing.AnnotationProcessorDeclaration)1