Search in sources :

Example 1 with GeneratedResource

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

the class IsolatingProcessingStrategy method recordGeneratedResource.

@Override
public void recordGeneratedResource(JavaFileManager.Location location, CharSequence pkg, CharSequence relativeName, Element[] originatingElements) {
    GeneratedResource.Location resourceLocation = GeneratedResource.Location.from(location);
    if (resourceLocation == null) {
        result.setFullRebuildCause(location + " is not supported for incremental annotation processing");
        return;
    }
    GeneratedResource generatedResource = new GeneratedResource(resourceLocation, pkg, relativeName);
    Set<String> originatingTypes = ElementUtils.getTopLevelTypeNames(originatingElements);
    int size = originatingTypes.size();
    if (size != 1) {
        result.setFullRebuildCause("the generated resource '" + generatedResource + "' must have exactly one originating element, but had " + size);
    }
    result.addGeneratedResource(generatedResource, originatingTypes);
}
Also used : GeneratedResource(org.gradle.api.internal.tasks.compile.incremental.compilerapi.deps.GeneratedResource)

Example 2 with GeneratedResource

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

the class ClassSetAnalysis method findDirectDependents.

/**
 * Finds all the classes and resources that are directly affected by the given one. This includes:
 *
 * - Classes that referenced this class in their bytecode
 * - Classes that use a constant declared in this class
 * - Classes and resources that were generated from this class
 */
private DependentsSet findDirectDependents(String className) {
    Set<String> generatedClasses = annotationProcessingData.getGeneratedTypesByOrigin().getOrDefault(className, Collections.emptySet());
    Set<GeneratedResource> generatedResources = annotationProcessingData.getGeneratedResourcesByOrigin().getOrDefault(className, Collections.emptySet());
    DependentsSet generatedDeps = DependentsSet.dependents(Collections.emptySet(), generatedClasses, generatedResources);
    return DependentsSet.merge(Arrays.asList(classAnalysis.getDependents(className), compilerApiData.getConstantDependentsForClass(className), generatedDeps));
}
Also used : DependentsSet(org.gradle.api.internal.tasks.compile.incremental.compilerapi.deps.DependentsSet) GeneratedResource(org.gradle.api.internal.tasks.compile.incremental.compilerapi.deps.GeneratedResource)

Example 3 with GeneratedResource

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

the class ClassSetAnalysis method findTransitiveDependents.

/**
 * Computes the transitive dependents of a set of changed classes. If the classes had any changes to inlineable constants, these need to be provided as the second parameter.
 *
 * If incremental annotation processing encountered issues in the previous compilation, a full recompilation is required.
 * If any inlineable constants have changed and the compiler does not support exact constant dependency tracking, then a full recompilation is required.
 * Otherwise follows the below rules for all of the given classes, as well as the classes that were marked as "always recompile" by annotation processing:
 *
 * Starts at this class and capture all classes that reference this class and all classes and resources that were generated from this class.
 * Then does the same analysis for all classes that expose this class on their ABI recursively until no more new classes are discovered.
 */
public DependentsSet findTransitiveDependents(Collection<String> classes, Map<String, IntSet> changedConstantsByClass) {
    if (classes.isEmpty()) {
        return DependentsSet.empty();
    }
    String fullRebuildCause = annotationProcessingData.getFullRebuildCause();
    if (fullRebuildCause != null) {
        return DependentsSet.dependencyToAll(fullRebuildCause);
    }
    if (!compilerApiData.isSupportsConstantsMapping()) {
        for (Map.Entry<String, IntSet> changedConstantsOfClass : changedConstantsByClass.entrySet()) {
            if (!changedConstantsOfClass.getValue().isEmpty()) {
                return DependentsSet.dependencyToAll("an inlineable constant in '" + changedConstantsOfClass.getKey() + "' has changed");
            }
        }
    }
    Set<String> privateDependents = new HashSet<>();
    Set<String> accessibleDependents = new HashSet<>();
    Set<GeneratedResource> dependentResources = new HashSet<>(annotationProcessingData.getGeneratedResourcesDependingOnAllOthers());
    Set<String> visited = new HashSet<>();
    Deque<String> remaining = new ArrayDeque<>(classes);
    remaining.addAll(annotationProcessingData.getGeneratedTypesDependingOnAllOthers());
    while (!remaining.isEmpty()) {
        String current = remaining.pop();
        if (!visited.add(current)) {
            continue;
        }
        accessibleDependents.add(current);
        DependentsSet dependents = findDirectDependents(current);
        if (dependents.isDependencyToAll()) {
            return dependents;
        }
        dependentResources.addAll(dependents.getDependentResources());
        privateDependents.addAll(dependents.getPrivateDependentClasses());
        remaining.addAll(dependents.getAccessibleDependentClasses());
    }
    privateDependents.removeAll(classes);
    accessibleDependents.removeAll(classes);
    return DependentsSet.dependents(privateDependents, accessibleDependents, dependentResources);
}
Also used : DependentsSet(org.gradle.api.internal.tasks.compile.incremental.compilerapi.deps.DependentsSet) IntSet(it.unimi.dsi.fastutil.ints.IntSet) GeneratedResource(org.gradle.api.internal.tasks.compile.incremental.compilerapi.deps.GeneratedResource) HashMap(java.util.HashMap) Map(java.util.Map) ArrayDeque(java.util.ArrayDeque) HashSet(java.util.HashSet) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet)

Aggregations

GeneratedResource (org.gradle.api.internal.tasks.compile.incremental.compilerapi.deps.GeneratedResource)3 DependentsSet (org.gradle.api.internal.tasks.compile.incremental.compilerapi.deps.DependentsSet)2 IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)1 IntSet (it.unimi.dsi.fastutil.ints.IntSet)1 ArrayDeque (java.util.ArrayDeque)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1