Search in sources :

Example 6 with ComponentResolveMetadata

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

the class LatestModuleConflictResolver method select.

@Override
public <T extends ComponentResolutionState> void select(ConflictResolverDetails<T> details) {
    // Find the candidates with the highest base version
    Version baseVersion = null;
    Map<Version, T> matches = new LinkedHashMap<Version, T>();
    for (T candidate : details.getCandidates()) {
        Version version = VersionParser.INSTANCE.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) {
        details.select(matches.values().iterator().next());
        return;
    }
    // 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()) {
            details.select(component);
            return;
        }
        ComponentResolveMetadata metaData = component.getMetadata();
        if (metaData != null && "release".equals(metaData.getStatus())) {
            details.select(component);
            return;
        }
    }
    // Nothing - just return the highest version
    details.select(matches.get(sorted.get(0)));
}
Also used : Version(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version) ArrayList(java.util.ArrayList) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with ComponentResolveMetadata

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

the class RepositoryChainArtifactResolver method resolveArtifactsWithType.

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

Example 8 with ComponentResolveMetadata

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

the class EdgeState method calculateTargetConfigurations.

private void calculateTargetConfigurations() {
    targetNodes.clear();
    targetNodeSelectionFailure = null;
    ComponentResolveMetadata targetModuleVersion = targetModuleRevision.getMetadata();
    if (targetModuleVersion == null) {
        // Broken version
        return;
    }
    ImmutableAttributes attributes = resolveState.getRoot().getMetadata().getAttributes();
    List<ConfigurationMetadata> targetConfigurations;
    try {
        targetConfigurations = dependencyMetadata.selectConfigurations(attributes, targetModuleVersion, resolveState.getAttributesSchema());
    } catch (Throwable t) {
        // Failure to select the target variant/configurations from this component, given the dependency attributes/metadata.
        targetNodeSelectionFailure = new ModuleVersionResolveException(dependencyState.getRequested(), t);
        return;
    }
    for (ConfigurationMetadata targetConfiguration : targetConfigurations) {
        NodeState targetNodeState = resolveState.getNode(targetModuleRevision, targetConfiguration);
        this.targetNodes.add(targetNodeState);
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 9 with ComponentResolveMetadata

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

the class DefaultArtifactResolutionQuery method buildComponentResult.

private ComponentArtifactsResult buildComponentResult(ComponentIdentifier componentId, ComponentMetaDataResolver componentMetaDataResolver, ArtifactResolver artifactResolver) {
    BuildableComponentResolveResult moduleResolveResult = new DefaultBuildableComponentResolveResult();
    componentMetaDataResolver.resolve(componentId, new DefaultComponentOverrideMetadata(), moduleResolveResult);
    ComponentResolveMetadata component = moduleResolveResult.getMetadata();
    DefaultComponentArtifactsResult componentResult = new DefaultComponentArtifactsResult(component.getId());
    for (Class<? extends Artifact> artifactType : artifactTypes) {
        addArtifacts(componentResult, artifactType, component, artifactResolver);
    }
    return componentResult;
}
Also used : DefaultBuildableComponentResolveResult(org.gradle.internal.resolve.result.DefaultBuildableComponentResolveResult) BuildableComponentResolveResult(org.gradle.internal.resolve.result.BuildableComponentResolveResult) DefaultBuildableComponentResolveResult(org.gradle.internal.resolve.result.DefaultBuildableComponentResolveResult) DefaultComponentOverrideMetadata(org.gradle.internal.component.model.DefaultComponentOverrideMetadata) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) DefaultComponentArtifactsResult(org.gradle.api.internal.artifacts.result.DefaultComponentArtifactsResult)

Example 10 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> void select(ConflictResolverDetails<T> details) {
    // 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 : details.getCandidates()) {
        ComponentResolveMetadata metaData = candidate.getMetadata();
        if (metaData != null && metaData.getId() 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) {
        ConflictResolverDetails<T> projectDetails = new DefaultConflictResolverDetails<T>(Cast.<List<T>>uncheckedCast(projectCandidates));
        delegate.select(projectDetails);
        details.select(projectDetails.getSelected());
        return;
    }
    // if found only one project dependency - return it, otherwise call the next resolver
    if (foundProjectCandidate != null) {
        details.select(foundProjectCandidate);
    } else {
        delegate.select(details);
    }
}
Also used : DefaultConflictResolverDetails(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.DefaultConflictResolverDetails) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Aggregations

ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)10 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 Version (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version)2 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Nullable (javax.annotation.Nullable)1 ModuleExclusion (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.ModuleExclusion)1 DefaultConflictResolverDetails (org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.DefaultConflictResolverDetails)1 DefaultComponentArtifactsResult (org.gradle.api.internal.artifacts.result.DefaultComponentArtifactsResult)1 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)1 DefaultComponentOverrideMetadata (org.gradle.internal.component.model.DefaultComponentOverrideMetadata)1 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)1 BuildableComponentResolveResult (org.gradle.internal.resolve.result.BuildableComponentResolveResult)1 DefaultBuildableComponentArtifactsResolveResult (org.gradle.internal.resolve.result.DefaultBuildableComponentArtifactsResolveResult)1 DefaultBuildableComponentResolveResult (org.gradle.internal.resolve.result.DefaultBuildableComponentResolveResult)1