Search in sources :

Example 1 with JarChangeProcessor

use of org.gradle.api.internal.tasks.compile.incremental.jar.JarChangeProcessor in project gradle by gradle.

the class RecompilationSpecProvider method provideRecompilationSpec.

public RecompilationSpec provideRecompilationSpec(IncrementalTaskInputs inputs, PreviousCompilation previousCompilation, JarClasspathSnapshot jarClasspathSnapshot) {
    //creating an action that will be executed against all changes
    RecompilationSpec spec = new RecompilationSpec();
    JavaChangeProcessor javaChangeProcessor = new JavaChangeProcessor(previousCompilation, sourceToNameConverter);
    ClassChangeProcessor classChangeProcessor = new ClassChangeProcessor(previousCompilation);
    JarChangeProcessor jarChangeProcessor = new JarChangeProcessor(fileOperations, jarClasspathSnapshot, previousCompilation);
    InputChangeAction action = new InputChangeAction(spec, javaChangeProcessor, classChangeProcessor, jarChangeProcessor);
    //go!
    inputs.outOfDate(action);
    if (action.spec.getFullRebuildCause() != null) {
        //short circuit in case we already know that that full rebuild is needed
        return action.spec;
    }
    inputs.removed(action);
    return action.spec;
}
Also used : RecompilationSpec(org.gradle.api.internal.tasks.compile.incremental.recomp.RecompilationSpec) JarChangeProcessor(org.gradle.api.internal.tasks.compile.incremental.jar.JarChangeProcessor)

Example 2 with JarChangeProcessor

use of org.gradle.api.internal.tasks.compile.incremental.jar.JarChangeProcessor in project gradle by gradle.

the class RecompilationSpecProvider method processJarClasspathChanges.

private void processJarClasspathChanges(CurrentCompilation current, PreviousCompilation previous, RecompilationSpec spec) {
    JarChangeProcessor jarChangeProcessor = new JarChangeProcessor(fileOperations, current.getClasspathSnapshot(), previous);
    Map<File, JarSnapshot> previousCompilationJarSnapshots = previous.getJarSnapshots();
    JarClasspathSnapshot currentJarSnapshots = current.getClasspathSnapshot();
    Set<File> previousCompilationJars = previousCompilationJarSnapshots.keySet();
    Set<File> currentCompilationJars = currentJarSnapshots.getJars();
    List<Alignment<File>> alignment = Alignment.align(currentCompilationJars.toArray(new File[0]), previousCompilationJars.toArray(new File[0]));
    for (Alignment<File> fileAlignment : alignment) {
        switch(fileAlignment.getKind()) {
            case added:
                jarChangeProcessor.processChange(FileChange.added(fileAlignment.getCurrentValue().getAbsolutePath(), "jar", FileType.RegularFile), spec);
                break;
            case removed:
                jarChangeProcessor.processChange(FileChange.removed(fileAlignment.getPreviousValue().getAbsolutePath(), "jar", FileType.RegularFile), spec);
                break;
            case transformed:
                // If we detect a transformation in the classpath, we need to recompile, because we could typically be facing the case where
                // 2 jars are reversed in the order of classpath elements, and one class that was shadowing the other is now visible
                spec.setFullRebuildCause("Classpath has been changed", null);
                return;
            case identical:
                File key = fileAlignment.getPreviousValue();
                JarSnapshot previousSnapshot = previousCompilationJarSnapshots.get(key);
                JarSnapshot snapshot = currentJarSnapshots.getSnapshot(key);
                if (!snapshot.getHash().equals(previousSnapshot.getHash())) {
                    jarChangeProcessor.processChange(FileChange.modified(key.getAbsolutePath(), "jar", FileType.RegularFile, FileType.RegularFile), spec);
                }
                break;
        }
    }
}
Also used : JarClasspathSnapshot(org.gradle.api.internal.tasks.compile.incremental.jar.JarClasspathSnapshot) JarSnapshot(org.gradle.api.internal.tasks.compile.incremental.jar.JarSnapshot) Alignment(org.gradle.internal.util.Alignment) JarChangeProcessor(org.gradle.api.internal.tasks.compile.incremental.jar.JarChangeProcessor) File(java.io.File)

Aggregations

JarChangeProcessor (org.gradle.api.internal.tasks.compile.incremental.jar.JarChangeProcessor)2 File (java.io.File)1 JarClasspathSnapshot (org.gradle.api.internal.tasks.compile.incremental.jar.JarClasspathSnapshot)1 JarSnapshot (org.gradle.api.internal.tasks.compile.incremental.jar.JarSnapshot)1 RecompilationSpec (org.gradle.api.internal.tasks.compile.incremental.recomp.RecompilationSpec)1 Alignment (org.gradle.internal.util.Alignment)1