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));
}
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);
}
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);
}
}
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;
}
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);
}
Aggregations