Search in sources :

Example 1 with ComponentResolveMetadata

use of org.gradle.internal.component.model.ComponentResolveMetadata in project gradle by gradle.

the class LatestModuleConflictResolver method select.

public <T extends ComponentResolutionState> T select(Collection<? extends T> candidates) {
    // Find the candidates with the highest base version
    Version baseVersion = null;
    Map<Version, T> matches = new LinkedHashMap<Version, T>();
    for (T candidate : candidates) {
        Version version = versionParser.transform(candidate.getVersion());
        if (baseVersion == null || versionComparator.compare(version.getBaseVersion(), baseVersion) > 0) {
            matches.clear();
            baseVersion = version.getBaseVersion();
            matches.put(version, candidate);
        } else if (version.getBaseVersion().equals(baseVersion)) {
            matches.put(version, candidate);
        }
    }
    if (matches.size() == 1) {
        return matches.values().iterator().next();
    }
    // Work backwards from highest version, return the first candidate with qualified version and release status, or candidate with unqualified version
    List<Version> sorted = new ArrayList<Version>(matches.keySet());
    Collections.sort(sorted, Collections.reverseOrder(versionComparator));
    for (Version version : sorted) {
        T component = matches.get(version);
        if (!version.isQualified()) {
            return component;
        }
        ComponentResolveMetadata metaData = component.getMetaData();
        if (metaData != null && "release".equals(metaData.getStatus())) {
            return component;
        }
    }
    // Nothing - just return the highest version
    return matches.get(sorted.get(0));
}
Also used : Version(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata)

Example 2 with ComponentResolveMetadata

use of org.gradle.internal.component.model.ComponentResolveMetadata in project gradle by gradle.

the class ProjectDependencyForcingResolver method select.

@Override
public <T extends ComponentResolutionState> T select(Collection<? extends T> candidates) {
    // the collection will only be initialized if more than one project candidate is found
    Collection<T> projectCandidates = null;
    T foundProjectCandidate = null;
    // fine one or more project dependencies among conflicting modules
    for (T candidate : candidates) {
        ComponentResolveMetadata metaData = candidate.getMetaData();
        if (metaData != null && metaData.getComponentId() instanceof ProjectComponentIdentifier) {
            if (foundProjectCandidate == null) {
                // found the first project dependency
                foundProjectCandidate = candidate;
            } else {
                // found more than one
                if (projectCandidates == null) {
                    projectCandidates = new ArrayList<T>();
                    projectCandidates.add(foundProjectCandidate);
                }
                projectCandidates.add(candidate);
            }
        }
    }
    // let the delegate resolver select among them
    if (projectCandidates != null) {
        return delegate.select(projectCandidates);
    }
    // if found only one project dependency - return it, otherwise call the next resolver
    return foundProjectCandidate != null ? foundProjectCandidate : delegate.select(candidates);
}
Also used : ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 3 with ComponentResolveMetadata

use of org.gradle.internal.component.model.ComponentResolveMetadata in project gradle by gradle.

the class RepositoryChainArtifactResolver method resolveArtifacts.

@Override
public void resolveArtifacts(ComponentResolveMetadata component, BuildableComponentArtifactsResolveResult result) {
    ModuleComponentRepository sourceRepository = findSourceRepository(component.getSource());
    ComponentResolveMetadata unpackedComponent = unpackSource(component);
    // First try to determine the artifacts locally before going remote
    sourceRepository.getLocalAccess().resolveArtifacts(unpackedComponent, result);
    if (!result.hasResult()) {
        sourceRepository.getRemoteAccess().resolveArtifacts(unpackedComponent, result);
    }
}
Also used : ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata)

Example 4 with ComponentResolveMetadata

use of org.gradle.internal.component.model.ComponentResolveMetadata in project gradle by gradle.

the class RepositoryChainArtifactResolver method resolveArtifacts.

@Nullable
@Override
public ArtifactSet resolveArtifacts(ComponentResolveMetadata component, ConfigurationMetadata configuration, ArtifactTypeRegistry artifactTypeRegistry, ModuleExclusion exclusions) {
    ModuleComponentRepository sourceRepository = findSourceRepository(component.getSource());
    ComponentResolveMetadata unpackedComponent = unpackSource(component);
    // First try to determine the artifacts locally before going remote
    DefaultBuildableComponentArtifactsResolveResult result = new DefaultBuildableComponentArtifactsResolveResult();
    sourceRepository.getLocalAccess().resolveArtifacts(unpackedComponent, result);
    if (!result.hasResult()) {
        sourceRepository.getRemoteAccess().resolveArtifacts(unpackedComponent, result);
    }
    if (result.hasResult()) {
        return result.getResult().getArtifactsFor(component, configuration, this, sourceRepository.getArtifactCache(), artifactTypeRegistry, exclusions);
    }
    return null;
}
Also used : DefaultBuildableComponentArtifactsResolveResult(org.gradle.internal.resolve.result.DefaultBuildableComponentArtifactsResolveResult) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) Nullable(javax.annotation.Nullable)

Example 5 with ComponentResolveMetadata

use of org.gradle.internal.component.model.ComponentResolveMetadata in project gradle by gradle.

the class PotentialEdge method of.

static PotentialEdge of(ResolveState resolveState, NodeState from, ModuleComponentIdentifier toComponent, ModuleComponentSelector toSelector, ComponentIdentifier owner, boolean force, boolean transitive) {
    DependencyState dependencyState = new DependencyState(new LenientPlatformDependencyMetadata(resolveState, from, toSelector, toComponent, owner, force || hasStrongOpinion(from), transitive), resolveState.getComponentSelectorConverter());
    dependencyState = NodeState.maybeSubstitute(dependencyState, resolveState.getDependencySubstitutionApplicator());
    ExcludeSpec exclusions = from.previousTraversalExclusions;
    if (exclusions == null) {
        exclusions = resolveState.getModuleExclusions().nothing();
    }
    EdgeState edge = new EdgeState(from, dependencyState, exclusions, resolveState);
    edge.computeSelector();
    ModuleVersionIdentifier toModuleVersionId = DefaultModuleVersionIdentifier.newId(toSelector.getModuleIdentifier(), toSelector.getVersion());
    ComponentState version = resolveState.getModule(toSelector.getModuleIdentifier()).getVersion(toModuleVersionId, toComponent);
    // We need to check if the target version exists. For this, we have to try to get metadata for the aligned version.
    // If it's there, it means we can align, otherwise, we must NOT add the edge, or resolution would fail
    ComponentResolveMetadata metadata = version.getMetadata();
    return new PotentialEdge(edge, toModuleVersionId, metadata, version);
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)

Aggregations

ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)16 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)3 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)3 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)3 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)2 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 Version (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version)2 ExcludeSpec (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Nullable (javax.annotation.Nullable)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)1 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)1 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)1 DefaultModuleVersionIdentifier (org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier)1 DefaultConflictResolverDetails (org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.DefaultConflictResolverDetails)1 MavenUniqueSnapshotComponentIdentifier (org.gradle.api.internal.artifacts.repositories.resolver.MavenUniqueSnapshotComponentIdentifier)1 DefaultComponentArtifactsResult (org.gradle.api.internal.artifacts.result.DefaultComponentArtifactsResult)1 AttributeMergingException (org.gradle.api.internal.attributes.AttributeMergingException)1