Search in sources :

Example 1 with DependentsSet

use of org.gradle.api.internal.tasks.compile.incremental.deps.DependentsSet in project gradle by gradle.

the class JavaChangeProcessor method processChange.

public void processChange(InputFileDetails input, RecompilationSpec spec) {
    String className = sourceToNameConverter.getClassName(input.getFile());
    spec.getClassesToCompile().add(className);
    DependentsSet actualDependents = previousCompilation.getDependents(className, IntSets.EMPTY_SET);
    if (actualDependents.isDependencyToAll()) {
        spec.setFullRebuildCause(actualDependents.getDescription(), input.getFile());
        return;
    }
    spec.getClassesToCompile().addAll(actualDependents.getDependentClasses());
}
Also used : DependentsSet(org.gradle.api.internal.tasks.compile.incremental.deps.DependentsSet)

Example 2 with DependentsSet

use of org.gradle.api.internal.tasks.compile.incremental.deps.DependentsSet in project gradle by gradle.

the class JarChangeDependentsFinder method getActualDependents.

public DependentsSet getActualDependents(InputFileDetails jarChangeDetails, JarArchive jarArchive) {
    if (jarChangeDetails.isAdded()) {
        if (jarClasspathSnapshot.isAnyClassDuplicated(jarArchive)) {
            // to avoid calculation which class gets on the classpath first, rebuild all
            return DependentsSet.dependencyToAll("at least one of the classes of '" + jarArchive.file.getName() + "' is already present in classpath");
        } else {
            // none of the new classes in the jar are duplicated on classpath, don't rebuild
            return DependentsSet.empty();
        }
    }
    final JarSnapshot previous = previousCompilation.getJarSnapshot(jarChangeDetails.getFile());
    if (previous == null) {
        // for example, a class (in jar) with a constant might have changed into a class without a constant - we need to rebuild everything
        return DependentsSet.dependencyToAll("missing jar snapshot of '" + jarArchive.file.getName() + "' from previous build");
    }
    if (jarChangeDetails.isRemoved()) {
        DependentsSet allClasses = previous.getAllClasses();
        if (allClasses.isDependencyToAll()) {
            return DependentsSet.dependencyToAll("at least one of the classes of removed jar '" + jarArchive.file.getName() + "' requires it");
        }
        // recompile all dependents of all the classes from jar
        return previousCompilation.getDependents(allClasses.getDependentClasses(), previous.getAllConstants(allClasses));
    }
    if (jarChangeDetails.isModified()) {
        final JarSnapshot currentSnapshot = jarClasspathSnapshot.getSnapshot(jarArchive);
        AffectedClasses affected = currentSnapshot.getAffectedClassesSince(previous);
        DependentsSet altered = affected.getAltered();
        if (altered.isDependencyToAll()) {
            // at least one of the classes changed in the jar is a 'dependency-to-all'
            return altered;
        }
        if (jarClasspathSnapshot.isAnyClassDuplicated(affected.getAdded())) {
            // For safe measure rebuild everything
            return DependentsSet.dependencyToAll("at least one of the classes of modified jar '" + jarArchive.file.getName() + "' is already present in the classpath");
        }
        // recompile all dependents of the classes changed in the jar
        final Set<String> dependentClasses = Sets.newHashSet(altered.getDependentClasses());
        final Deque<String> queue = Lists.newLinkedList(dependentClasses);
        while (!queue.isEmpty()) {
            final String dependentClass = queue.poll();
            jarClasspathSnapshot.forEachSnapshot(new Action<JarSnapshot>() {

                @Override
                public void execute(JarSnapshot jarSnapshot) {
                    if (jarSnapshot != previous) {
                        // we need to find in the other jars classes that would potentially extend classes changed
                        // in the current snapshot (they are intermediates)
                        ClassSetAnalysisData data = jarSnapshot.getData().data;
                        Set<String> children = data.getChildren(dependentClass);
                        for (String child : children) {
                            if (dependentClasses.add(child)) {
                                queue.add(child);
                            }
                        }
                    }
                }
            });
        }
        return previousCompilation.getDependents(dependentClasses, currentSnapshot.getRelevantConstants(previous, dependentClasses));
    }
    throw new IllegalArgumentException("Unknown input file details provided: " + jarChangeDetails);
}
Also used : Set(java.util.Set) DependentsSet(org.gradle.api.internal.tasks.compile.incremental.deps.DependentsSet) AffectedClasses(org.gradle.api.internal.tasks.compile.incremental.deps.AffectedClasses) DependentsSet(org.gradle.api.internal.tasks.compile.incremental.deps.DependentsSet) ClassSetAnalysisData(org.gradle.api.internal.tasks.compile.incremental.deps.ClassSetAnalysisData)

Example 3 with DependentsSet

use of org.gradle.api.internal.tasks.compile.incremental.deps.DependentsSet in project gradle by gradle.

the class JarChangeProcessor method processChange.

public void processChange(InputFileDetails input, RecompilationSpec spec) {
    JarArchive jarArchive = new JarArchive(input.getFile(), fileOperations.zipTree(input.getFile()));
    DependentsSet actualDependents = dependentsFinder.getActualDependents(input, jarArchive);
    if (actualDependents.isDependencyToAll()) {
        spec.setFullRebuildCause(actualDependents.getDescription(), input.getFile());
        return;
    }
    spec.getClassesToCompile().addAll(actualDependents.getDependentClasses());
}
Also used : DependentsSet(org.gradle.api.internal.tasks.compile.incremental.deps.DependentsSet)

Example 4 with DependentsSet

use of org.gradle.api.internal.tasks.compile.incremental.deps.DependentsSet in project gradle by gradle.

the class JarSnapshot method getAffectedClassesSince.

public AffectedClasses getAffectedClassesSince(JarSnapshot other) {
    DependentsSet affectedClasses = affectedSince(other);
    Set<String> addedClasses = addedSince(other);
    return new AffectedClasses(affectedClasses, addedClasses);
}
Also used : AffectedClasses(org.gradle.api.internal.tasks.compile.incremental.deps.AffectedClasses) DependentsSet(org.gradle.api.internal.tasks.compile.incremental.deps.DependentsSet)

Example 5 with DependentsSet

use of org.gradle.api.internal.tasks.compile.incremental.deps.DependentsSet in project gradle by gradle.

the class JarSnapshot method affectedSince.

private DependentsSet affectedSince(JarSnapshot other) {
    final Set<String> affected = new HashSet<String>();
    for (Map.Entry<String, HashCode> otherClass : other.getHashes().entrySet()) {
        String otherClassName = otherClass.getKey();
        HashCode otherClassBytes = otherClass.getValue();
        HashCode thisClsBytes = getHashes().get(otherClassName);
        if (thisClsBytes == null || !thisClsBytes.equals(otherClassBytes)) {
            // removed since or changed since
            affected.add(otherClassName);
            DependentsSet dependents = other.getAnalysis().getRelevantDependents(otherClassName, IntSets.EMPTY_SET);
            if (dependents.isDependencyToAll()) {
                return dependents;
            }
            affected.addAll(dependents.getDependentClasses());
        }
    }
    return DependentsSet.dependents(affected);
}
Also used : HashCode(org.gradle.internal.hash.HashCode) DependentsSet(org.gradle.api.internal.tasks.compile.incremental.deps.DependentsSet) Map(java.util.Map) HashSet(java.util.HashSet) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet)

Aggregations

DependentsSet (org.gradle.api.internal.tasks.compile.incremental.deps.DependentsSet)5 AffectedClasses (org.gradle.api.internal.tasks.compile.incremental.deps.AffectedClasses)2 IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ClassSetAnalysisData (org.gradle.api.internal.tasks.compile.incremental.deps.ClassSetAnalysisData)1 HashCode (org.gradle.internal.hash.HashCode)1