Search in sources :

Example 1 with DependencyGraphNodeResult

use of org.gradle.api.internal.artifacts.DependencyGraphNodeResult in project gradle by gradle.

the class DefaultLenientConfiguration method getFirstLevelNodes.

private Set<DependencyGraphNodeResult> getFirstLevelNodes(Spec<? super Dependency> dependencySpec) {
    Set<DependencyGraphNodeResult> matches = new LinkedHashSet<>();
    TransientConfigurationResults graphResults = loadTransientGraphResults(getSelectedArtifacts());
    for (Map.Entry<Dependency, DependencyGraphNodeResult> entry : graphResults.getFirstLevelDependencies().entrySet()) {
        if (dependencySpec.isSatisfiedBy(entry.getKey())) {
            matches.add(entry.getValue());
        }
    }
    return matches;
}
Also used : DependencyGraphNodeResult(org.gradle.api.internal.artifacts.DependencyGraphNodeResult) LinkedHashSet(java.util.LinkedHashSet) TransientConfigurationResults(org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.TransientConfigurationResults) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) UnresolvedDependency(org.gradle.api.artifacts.UnresolvedDependency) ResolvedDependency(org.gradle.api.artifacts.ResolvedDependency) Dependency(org.gradle.api.artifacts.Dependency) Map(java.util.Map)

Example 2 with DependencyGraphNodeResult

use of org.gradle.api.internal.artifacts.DependencyGraphNodeResult in project gradle by gradle.

the class TransientConfigurationResultsBuilder method deserialize.

private TransientConfigurationResults deserialize(Decoder decoder, ResolvedGraphResults graphResults, SelectedArtifactResults artifactResults) {
    Timer clock = Timers.startTimer();
    Map<Long, DefaultResolvedDependency> allDependencies = new HashMap<Long, DefaultResolvedDependency>();
    Map<ModuleDependency, DependencyGraphNodeResult> firstLevelDependencies = new LinkedHashMap<ModuleDependency, DependencyGraphNodeResult>();
    DependencyGraphNodeResult root;
    int valuesRead = 0;
    byte type = -1;
    try {
        while (true) {
            type = decoder.readByte();
            long id;
            valuesRead++;
            switch(type) {
                case NEW_DEP:
                    id = decoder.readSmallLong();
                    ResolvedConfigurationIdentifier details = resolvedConfigurationIdentifierSerializer.read(decoder);
                    allDependencies.put(id, new DefaultResolvedDependency(id, details));
                    break;
                case ROOT:
                    id = decoder.readSmallLong();
                    root = allDependencies.get(id);
                    if (root == null) {
                        throw new IllegalStateException(String.format("Unexpected root id %s. Seen ids: %s", id, allDependencies.keySet()));
                    }
                    //root should be the last entry
                    LOG.debug("Loaded resolved configuration results ({}) from {}", clock.getElapsed(), binaryStore);
                    return new DefaultTransientConfigurationResults(root, firstLevelDependencies);
                case FIRST_LVL:
                    id = decoder.readSmallLong();
                    DefaultResolvedDependency dependency = allDependencies.get(id);
                    if (dependency == null) {
                        throw new IllegalStateException(String.format("Unexpected first level id %s. Seen ids: %s", id, allDependencies.keySet()));
                    }
                    firstLevelDependencies.put(graphResults.getModuleDependency(id), dependency);
                    break;
                case PARENT_CHILD:
                    long parentId = decoder.readSmallLong();
                    long childId = decoder.readSmallLong();
                    DefaultResolvedDependency parent = allDependencies.get(parentId);
                    DefaultResolvedDependency child = allDependencies.get(childId);
                    if (parent == null) {
                        throw new IllegalStateException(String.format("Unexpected parent dependency id %s. Seen ids: %s", parentId, allDependencies.keySet()));
                    }
                    if (child == null) {
                        throw new IllegalStateException(String.format("Unexpected child dependency id %s. Seen ids: %s", childId, allDependencies.keySet()));
                    }
                    parent.addChild(child);
                    child.addParentSpecificArtifacts(parent, artifactResults.getArtifacts(decoder.readSmallLong()));
                    break;
                default:
                    throw new IOException("Unknown value type read from stream: " + type);
            }
        }
    } catch (IOException e) {
        throw new RuntimeException("Problems loading the resolved configuration. Read " + valuesRead + " values, last was: " + type, e);
    }
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DefaultResolvedDependency(org.gradle.api.internal.artifacts.DefaultResolvedDependency) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) DependencyGraphNodeResult(org.gradle.api.internal.artifacts.DependencyGraphNodeResult) Timer(org.gradle.internal.time.Timer) ResolvedConfigurationIdentifier(org.gradle.api.internal.artifacts.ResolvedConfigurationIdentifier)

Example 3 with DependencyGraphNodeResult

use of org.gradle.api.internal.artifacts.DependencyGraphNodeResult in project gradle by gradle.

the class DefaultLenientConfiguration method visitArtifacts.

/**
     * Recursive, includes unsuccessfully resolved artifacts
     *
     * @param dependencySpec dependency spec
     */
private void visitArtifacts(Spec<? super Dependency> dependencySpec, SelectedArtifactResults artifactResults, SelectedFileDependencyResults fileDependencyResults, ArtifactVisitor visitor) {
    //avoid traversing the graph causing the full ResolvedDependency graph to be loaded for the most typical scenario
    if (dependencySpec == Specs.SATISFIES_ALL) {
        if (visitor.includeFiles()) {
            fileDependencyResults.getArtifacts().visit(visitor);
        }
        artifactResults.getArtifacts().visit(visitor);
        return;
    }
    if (visitor.includeFiles()) {
        for (Map.Entry<FileCollectionDependency, ResolvedArtifactSet> entry : fileDependencyResults.getFirstLevelFiles().entrySet()) {
            if (dependencySpec.isSatisfiedBy(entry.getKey())) {
                entry.getValue().visit(visitor);
            }
        }
    }
    CachingDirectedGraphWalker<DependencyGraphNodeResult, ResolvedArtifact> walker = new CachingDirectedGraphWalker<DependencyGraphNodeResult, ResolvedArtifact>(new ResolvedDependencyArtifactsGraph(visitor, fileDependencyResults));
    DependencyGraphNodeResult rootNode = loadTransientGraphResults(artifactResults).getRootNode();
    for (DependencyGraphNodeResult node : getFirstLevelNodes(dependencySpec)) {
        node.getArtifactsForIncomingEdge(rootNode).visit(visitor);
        walker.add(node);
    }
    walker.findValues();
}
Also used : DependencyGraphNodeResult(org.gradle.api.internal.artifacts.DependencyGraphNodeResult) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ResolvedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSet) Map(java.util.Map) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) CachingDirectedGraphWalker(org.gradle.internal.graph.CachingDirectedGraphWalker)

Example 4 with DependencyGraphNodeResult

use of org.gradle.api.internal.artifacts.DependencyGraphNodeResult in project gradle by gradle.

the class DefaultLenientConfiguration method visitArtifacts.

/**
 * Recursive, includes unsuccessfully resolved artifacts
 *
 * @param dependencySpec dependency spec
 */
private void visitArtifacts(Spec<? super Dependency> dependencySpec, SelectedArtifactResults artifactResults, VisitedFileDependencyResults fileDependencyResults, ArtifactVisitor visitor) {
    // avoid traversing the graph causing the full ResolvedDependency graph to be loaded for the most typical scenario
    if (dependencySpec == Specs.SATISFIES_ALL) {
        ParallelResolveArtifactSet.wrap(artifactResults.getArtifacts(), buildOperationExecutor).visit(visitor);
        return;
    }
    List<ResolvedArtifactSet> artifactSets = new ArrayList<>();
    for (Map.Entry<FileCollectionDependency, Integer> entry : fileDependencyResults.getFirstLevelFiles().entrySet()) {
        if (dependencySpec.isSatisfiedBy(entry.getKey())) {
            artifactSets.add(artifactResults.getArtifactsWithId(entry.getValue()));
        }
    }
    CachingDirectedGraphWalker<DependencyGraphNodeResult, ResolvedArtifact> walker = new CachingDirectedGraphWalker<>(new ResolvedDependencyArtifactsGraph(artifactSets));
    for (DependencyGraphNodeResult node : getFirstLevelNodes(dependencySpec)) {
        walker.add(node);
    }
    walker.findValues();
    ParallelResolveArtifactSet.wrap(CompositeResolvedArtifactSet.of(artifactSets), buildOperationExecutor).visit(visitor);
}
Also used : DependencyGraphNodeResult(org.gradle.api.internal.artifacts.DependencyGraphNodeResult) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ResolvedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSet) CompositeResolvedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.CompositeResolvedArtifactSet) ArrayList(java.util.ArrayList) Map(java.util.Map) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) CachingDirectedGraphWalker(org.gradle.internal.graph.CachingDirectedGraphWalker)

Example 5 with DependencyGraphNodeResult

use of org.gradle.api.internal.artifacts.DependencyGraphNodeResult in project gradle by gradle.

the class TransientConfigurationResultsBuilder method deserialize.

private TransientConfigurationResults deserialize(Decoder decoder, ResolvedGraphResults graphResults, SelectedArtifactResults artifactResults, BuildOperationExecutor buildOperationProcessor) {
    Timer clock = Time.startTimer();
    Map<Long, DefaultResolvedDependency> allDependencies = new HashMap<>();
    Map<Dependency, DependencyGraphNodeResult> firstLevelDependencies = new LinkedHashMap<>();
    DependencyGraphNodeResult root;
    int valuesRead = 0;
    byte type = -1;
    long id;
    ResolvedArtifactSet artifacts;
    try {
        while (true) {
            type = decoder.readByte();
            valuesRead++;
            switch(type) {
                case NODE:
                    id = decoder.readSmallLong();
                    ResolvedConfigurationIdentifier details = resolvedConfigurationIdentifierSerializer.read(decoder);
                    allDependencies.put(id, new DefaultResolvedDependency(details, buildOperationProcessor));
                    break;
                case ROOT:
                    id = decoder.readSmallLong();
                    root = allDependencies.get(id);
                    if (root == null) {
                        throw new IllegalStateException(String.format("Unexpected root id %s. Seen ids: %s", id, allDependencies.keySet()));
                    }
                    // root should be the last entry
                    LOG.debug("Loaded resolved configuration results ({}) from {}", clock.getElapsed(), binaryStore);
                    return new DefaultTransientConfigurationResults(root, firstLevelDependencies);
                case FIRST_LEVEL:
                    id = decoder.readSmallLong();
                    DefaultResolvedDependency dependency = allDependencies.get(id);
                    if (dependency == null) {
                        throw new IllegalStateException(String.format("Unexpected first level id %s. Seen ids: %s", id, allDependencies.keySet()));
                    }
                    firstLevelDependencies.put(graphResults.getModuleDependency(id), dependency);
                    break;
                case EDGE:
                    long parentId = decoder.readSmallLong();
                    long childId = decoder.readSmallLong();
                    DefaultResolvedDependency parent = allDependencies.get(parentId);
                    DefaultResolvedDependency child = allDependencies.get(childId);
                    if (parent == null) {
                        throw new IllegalStateException(String.format("Unexpected parent dependency id %s. Seen ids: %s", parentId, allDependencies.keySet()));
                    }
                    if (child == null) {
                        throw new IllegalStateException(String.format("Unexpected child dependency id %s. Seen ids: %s", childId, allDependencies.keySet()));
                    }
                    parent.addChild(child);
                    artifacts = artifactResults.getArtifactsWithId(decoder.readSmallInt());
                    child.addParentSpecificArtifacts(parent, artifacts);
                    break;
                case NODE_ARTIFACTS:
                    id = decoder.readSmallLong();
                    DefaultResolvedDependency node = allDependencies.get(id);
                    if (node == null) {
                        throw new IllegalStateException(String.format("Unexpected node id %s. Seen ids: %s", node, allDependencies.keySet()));
                    }
                    artifacts = artifactResults.getArtifactsWithId(decoder.readSmallInt());
                    node.addModuleArtifacts(artifacts);
                    break;
                default:
                    throw new IOException("Unknown value type read from stream: " + type);
            }
        }
    } catch (IOException e) {
        throw new RuntimeException("Problems loading the resolved configuration. Read " + valuesRead + " values, last was: " + type, e);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ResolvedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSet) DefaultResolvedDependency(org.gradle.api.internal.artifacts.DefaultResolvedDependency) DefaultResolvedDependency(org.gradle.api.internal.artifacts.DefaultResolvedDependency) Dependency(org.gradle.api.artifacts.Dependency) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) DependencyGraphNodeResult(org.gradle.api.internal.artifacts.DependencyGraphNodeResult) Timer(org.gradle.internal.time.Timer) ResolvedConfigurationIdentifier(org.gradle.api.internal.artifacts.ResolvedConfigurationIdentifier)

Aggregations

DependencyGraphNodeResult (org.gradle.api.internal.artifacts.DependencyGraphNodeResult)5 Map (java.util.Map)3 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)3 ResolvedArtifactSet (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSet)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Dependency (org.gradle.api.artifacts.Dependency)2 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)2 DefaultResolvedDependency (org.gradle.api.internal.artifacts.DefaultResolvedDependency)2 ResolvedConfigurationIdentifier (org.gradle.api.internal.artifacts.ResolvedConfigurationIdentifier)2 CachingDirectedGraphWalker (org.gradle.internal.graph.CachingDirectedGraphWalker)2 Timer (org.gradle.internal.time.Timer)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)1 ResolvedDependency (org.gradle.api.artifacts.ResolvedDependency)1 UnresolvedDependency (org.gradle.api.artifacts.UnresolvedDependency)1 CompositeResolvedArtifactSet (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.CompositeResolvedArtifactSet)1 TransientConfigurationResults (org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.TransientConfigurationResults)1