Search in sources :

Example 1 with PreviousCompilation

use of org.gradle.api.internal.tasks.compile.incremental.recomp.PreviousCompilation 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)

Aggregations

File (java.io.File)1 CurrentCompilation (org.gradle.api.internal.tasks.compile.incremental.recomp.CurrentCompilation)1 PreviousCompilation (org.gradle.api.internal.tasks.compile.incremental.recomp.PreviousCompilation)1 PreviousCompilationData (org.gradle.api.internal.tasks.compile.incremental.recomp.PreviousCompilationData)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