Search in sources :

Example 1 with JarClasspathSnapshot

use of org.gradle.api.internal.tasks.compile.incremental.jar.JarClasspathSnapshot 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

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