Search in sources :

Example 1 with PreviousCompilationData

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

the class SelectiveCompiler method execute.

@Override
public WorkResult execute(T spec) {
    if (!recompilationSpecProvider.isIncremental()) {
        LOG.info("Full recompilation is required because no incremental change information is available. This is usually caused by clean builds or changing compiler arguments.");
        return rebuildAllCompiler.execute(spec);
    }
    File previousCompilationDataFile = Objects.requireNonNull(spec.getCompileOptions().getPreviousCompilationDataFile());
    if (!previousCompilationDataFile.exists()) {
        LOG.info("Full recompilation is required because no previous compilation result is available.");
        return rebuildAllCompiler.execute(spec);
    }
    if (spec.getSourceRoots().isEmpty()) {
        LOG.info("Full recompilation is required because the source roots could not be inferred.");
        return rebuildAllCompiler.execute(spec);
    }
    Timer clock = Time.startTimer();
    CurrentCompilation currentCompilation = new CurrentCompilation(spec, classpathSnapshotter);
    PreviousCompilationData previousCompilationData = previousCompilationAccess.readPreviousCompilationData(previousCompilationDataFile);
    PreviousCompilation previousCompilation = new PreviousCompilation(previousCompilationData);
    RecompilationSpec recompilationSpec = recompilationSpecProvider.provideRecompilationSpec(currentCompilation, previousCompilation);
    if (recompilationSpec.isFullRebuildNeeded()) {
        LOG.info("Full recompilation is required because {}. Analysis took {}.", recompilationSpec.getFullRebuildCause(), clock.getElapsed());
        return rebuildAllCompiler.execute(spec);
    }
    boolean cleanedOutput = recompilationSpecProvider.initializeCompilation(spec, recompilationSpec);
    if (Iterables.isEmpty(spec.getSourceFiles()) && spec.getClasses().isEmpty()) {
        LOG.info("None of the classes needs to be compiled! Analysis took {}. ", clock.getElapsed());
        return new RecompilationNotNecessary(previousCompilationData, recompilationSpec);
    }
    try {
        WorkResult result = recompilationSpecProvider.decorateResult(recompilationSpec, previousCompilationData, cleaningCompiler.getCompiler().execute(spec));
        return result.or(WorkResults.didWork(cleanedOutput));
    } finally {
        Collection<String> classesToCompile = recompilationSpec.getClassesToCompile();
        LOG.info("Incremental compilation of {} classes completed in {}.", classesToCompile.size(), clock.getElapsed());
        LOG.debug("Recompiled classes {}", classesToCompile);
    }
}
Also used : RecompilationSpec(org.gradle.api.internal.tasks.compile.incremental.recomp.RecompilationSpec) PreviousCompilation(org.gradle.api.internal.tasks.compile.incremental.recomp.PreviousCompilation) Timer(org.gradle.internal.time.Timer) WorkResult(org.gradle.api.tasks.WorkResult) PreviousCompilationData(org.gradle.api.internal.tasks.compile.incremental.recomp.PreviousCompilationData) File(java.io.File) CurrentCompilation(org.gradle.api.internal.tasks.compile.incremental.recomp.CurrentCompilation)

Example 2 with PreviousCompilationData

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

the class IncrementalResultStoringCompiler method storeResult.

private void storeResult(JavaCompileSpec spec, WorkResult result) {
    ClassSetAnalysisData outputSnapshot = classpathSnapshotter.analyzeOutputFolder(spec.getDestinationDir());
    ClassSetAnalysisData classpathSnapshot = classpathSnapshotter.getClasspathSnapshot(Iterables.concat(spec.getCompileClasspath(), spec.getModulePath()));
    AnnotationProcessingData annotationProcessingData = getAnnotationProcessingData(spec, result);
    CompilerApiData compilerApiData = getCompilerApiData(spec, result);
    ClassSetAnalysisData minimizedClasspathSnapshot = classpathSnapshot.reduceToTypesAffecting(outputSnapshot, compilerApiData);
    PreviousCompilationData data = new PreviousCompilationData(outputSnapshot, annotationProcessingData, minimizedClasspathSnapshot, compilerApiData);
    File previousCompilationDataFile = Objects.requireNonNull(spec.getCompileOptions().getPreviousCompilationDataFile());
    previousCompilationAccess.writePreviousCompilationData(data, previousCompilationDataFile);
}
Also used : AnnotationProcessingData(org.gradle.api.internal.tasks.compile.incremental.processing.AnnotationProcessingData) CompilerApiData(org.gradle.api.internal.tasks.compile.incremental.compilerapi.CompilerApiData) ClassSetAnalysisData(org.gradle.api.internal.tasks.compile.incremental.deps.ClassSetAnalysisData) PreviousCompilationData(org.gradle.api.internal.tasks.compile.incremental.recomp.PreviousCompilationData) File(java.io.File)

Aggregations

File (java.io.File)2 PreviousCompilationData (org.gradle.api.internal.tasks.compile.incremental.recomp.PreviousCompilationData)2 CompilerApiData (org.gradle.api.internal.tasks.compile.incremental.compilerapi.CompilerApiData)1 ClassSetAnalysisData (org.gradle.api.internal.tasks.compile.incremental.deps.ClassSetAnalysisData)1 AnnotationProcessingData (org.gradle.api.internal.tasks.compile.incremental.processing.AnnotationProcessingData)1 CurrentCompilation (org.gradle.api.internal.tasks.compile.incremental.recomp.CurrentCompilation)1 PreviousCompilation (org.gradle.api.internal.tasks.compile.incremental.recomp.PreviousCompilation)1 RecompilationSpec (org.gradle.api.internal.tasks.compile.incremental.recomp.RecompilationSpec)1 WorkResult (org.gradle.api.tasks.WorkResult)1 Timer (org.gradle.internal.time.Timer)1