Search in sources :

Example 1 with Version

use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version 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)

Aggregations

Version (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version)1 ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)1