org.gradle.api.artifacts.ModuleVersionSelector Java Examples

The following examples show how to use org.gradle.api.artifacts.ModuleVersionSelector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryChainDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private boolean getBestMatchingDependencyWithMetaData(DependencyMetaData dependency, ModuleAccess moduleAccess) {
    ModuleVersionSelector selector = dependency.getRequested();
    for (Versioned candidate : selectionResult.getVersions().sortLatestFirst(latestStrategy)) {
        // Resolve the metadata
        DependencyMetaData moduleVersionDependency = dependency.withRequestedVersion(candidate.getVersion());
        moduleAccess.getDependency(moduleVersionDependency, resolveResult);
        if (resolveResult.getState() != BuildableModuleVersionMetaDataResolveResult.State.Resolved) {
            // Couldn't load listed module
            LOGGER.warn("Could not load metadata for '{}' of listed module '{}' - ignoring.", candidate, selector);
            resolveResult.reset();
            return true;
        }
        if (versionMatcher.accept(selector.getVersion(), resolveResult.getMetaData())) {
            // We already resolved the correct module.
            return true;
        }
        resolveResult.reset();
    }
    return false;
}
 
Example #2
Source File: VersionForcingDependencyToModuleResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void resolve(DependencyMetaData dependency, BuildableComponentIdResolveResult result) {
    ModuleVersionSelector module = dependency.getRequested();
    DefaultDependencyResolveDetails details = new DefaultDependencyResolveDetails(module);
    try {
        rule.execute(details);
    } catch (Throwable e) {
        result.failed(new ModuleVersionResolveException(module, e));
        return;
    }
    if (details.isUpdated()) {
        DependencyMetaData substitutedDependency = dependency.withRequestedVersion(details.getTarget());
        resolver.resolve(substitutedDependency, result);
        result.setSelectionReason(details.getSelectionReason());
        return;
    }
    resolver.resolve(dependency, result);
}
 
Example #3
Source File: ModuleVersionSelectorParsers.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void convert(String notation, NotationConvertResult<? super ModuleVersionSelector> result) throws TypeConversionException {
    ParsedModuleStringNotation parsed;
    try {
        parsed = new ParsedModuleStringNotation(notation, null);
    } catch (IllegalDependencyNotation e) {
        throw new InvalidUserDataException(
                "Invalid format: '" + notation + "'. The correct notation is a 3-part group:name:version notation, "
                        + "e.g: 'org.gradle:gradle-core:1.0'");
    }

    if (parsed.getGroup() == null || parsed.getName() == null || parsed.getVersion() == null) {
        throw new InvalidUserDataException(
                "Invalid format: '" + notation + "'. Group, name and version cannot be empty. Correct example: "
                        + "'org.gradle:gradle-core:1.0'");
    }
    result.converted(newSelector(parsed.getGroup(), parsed.getName(), parsed.getVersion()));
}
 
Example #4
Source File: ExternalResourceResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected MutableModuleVersionMetaData findMetaDataArtifact(DependencyMetaData dependency, ArtifactResolver artifactResolver) {
    ModuleVersionArtifactMetaData artifact = getMetaDataArtifactFor(dependency);
    if (artifact == null) {
        return null;
    }
    ExternalResource metaDataResource = artifactResolver.resolveMetaDataArtifact(artifact);
    if (metaDataResource == null) {
        return null;
    }
    MutableModuleVersionMetaData moduleVersionMetaData = getArtifactMetadata(artifact, metaDataResource);

    if (isCheckconsistency()) {
        ModuleVersionSelector requested = dependency.getRequested();
        ModuleVersionIdentifier requestedId = DefaultModuleVersionIdentifier.newId(requested.getGroup(), requested.getName(), requested.getVersion());
        checkMetadataConsistency(requestedId, moduleVersionMetaData);
    }
    return moduleVersionMetaData;
}
 
Example #5
Source File: ModuleVersionSelectorParsers.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ModuleVersionSelector parseType(CharSequence notation) {
    ParsedModuleStringNotation parsed;
    try {
        parsed = new ParsedModuleStringNotation(notation.toString(), null);
    } catch (IllegalDependencyNotation e) {
        throw new InvalidUserDataException(
                "Invalid format: '" + notation + "'. The Correct notation is a 3-part group:name:version notation, "
                        + "e.g: 'org.gradle:gradle-core:1.0'");
    }

    if (parsed.getGroup() == null || parsed.getName() == null || parsed.getVersion() == null) {
        throw new InvalidUserDataException(
                "Invalid format: '" + notation + "'. Group, name and version cannot be empty. Correct example: "
                        + "'org.gradle:gradle-core:1.0'");
    }
    return newSelector(parsed.getGroup(), parsed.getName(), parsed.getVersion());
}
 
Example #6
Source File: RepositoryChainDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private boolean getBestMatchingDependencyWithMetaData(DependencyMetaData dependency, ModuleAccess moduleAccess) {
    ModuleVersionSelector selector = dependency.getRequested();
    for (Versioned candidate : selectionResult.getVersions().sortLatestFirst(latestStrategy)) {
        // Resolve the metadata
        DependencyMetaData moduleVersionDependency = dependency.withRequestedVersion(candidate.getVersion());
        moduleAccess.getDependency(moduleVersionDependency, resolveResult);
        if (resolveResult.getState() != BuildableModuleVersionMetaDataResolveResult.State.Resolved) {
            // Couldn't load listed module
            LOGGER.warn("Could not load metadata for '{}' of listed module '{}' - ignoring.", candidate, selector);
            resolveResult.reset();
            return true;
        }
        if (versionMatcher.accept(selector.getVersion(), resolveResult.getMetaData())) {
            // We already resolved the correct module.
            return true;
        }
        resolveResult.reset();
    }
    return false;
}
 
Example #7
Source File: CachingModuleComponentRepository.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void listModuleVersionsFromCache(DependencyMetaData dependency, BuildableModuleComponentVersionSelectionResolveResult result) {
    ModuleVersionSelector requested = dependency.getRequested();
    final ModuleIdentifier moduleId = getCacheKey(requested);
    ModuleVersionsCache.CachedModuleVersionList cachedModuleVersionList = moduleVersionsCache.getCachedModuleResolution(delegate, moduleId);
    if (cachedModuleVersionList != null) {
        ModuleVersionListing versionList = cachedModuleVersionList.getModuleVersions();
        Set<ModuleVersionIdentifier> versions = CollectionUtils.collect(versionList.getVersions(), new Transformer<ModuleVersionIdentifier, Versioned>() {
            public ModuleVersionIdentifier transform(Versioned original) {
                return new DefaultModuleVersionIdentifier(moduleId, original.getVersion());
            }
        });
        if (cachePolicy.mustRefreshVersionList(moduleId, versions, cachedModuleVersionList.getAgeMillis())) {
            LOGGER.debug("Version listing in dynamic revision cache is expired: will perform fresh resolve of '{}' in '{}'", requested, delegate.getName());
        } else {
            result.listed(versionList);
            // When age == 0, verified since the start of this build, assume listing hasn't changed
            result.setAuthoritative(cachedModuleVersionList.getAgeMillis() == 0);
        }
    }
}
 
Example #8
Source File: ModuleVersionResolveException.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ModuleVersionResolveException createCopy() {
    try {
        return getClass().getConstructor(ModuleVersionSelector.class, String.class).newInstance(selector, messageFormat);
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #9
Source File: DynamicVersionResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void resolve(DependencyMetaData dependency, BuildableComponentIdResolveResult result) {
    ModuleVersionSelector requested = dependency.getRequested();
    LOGGER.debug("Attempting to resolve {} using repositories {}", requested, repositoryNames);
    List<Throwable> errors = new ArrayList<Throwable>();

    List<RepositoryResolveState> resolveStates = new ArrayList<RepositoryResolveState>();
    for (ModuleComponentRepository repository : repositories) {
        resolveStates.add(new RepositoryResolveState(repository));
    }

    final RepositoryChainModuleResolution latestResolved = findLatestModule(dependency, resolveStates, errors);
    if (latestResolved != null) {
        LOGGER.debug("Using {} from {}", latestResolved.module.getId(), latestResolved.repository);
        for (Throwable error : errors) {
            LOGGER.debug("Discarding resolve failure.", error);
        }

        result.resolved(metaDataFactory.transform(latestResolved));
        return;
    }
    if (!errors.isEmpty()) {
        result.failed(new ModuleVersionResolveException(requested, errors));
    } else {
        for (RepositoryResolveState resolveState : resolveStates) {
            resolveState.applyTo(result);
        }
        result.notFound(requested);
    }
}
 
Example #10
Source File: InMemoryMetaDataCache.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean supplyModuleVersions(ModuleVersionSelector requested, BuildableModuleComponentVersionSelectionResolveResult result) {
    ModuleVersionListing moduleVersionListing1 = moduleVersionListing.get(requested);
    if (moduleVersionListing1 == null) {
        return false;
    }
    result.listed(moduleVersionListing1);
    return true;
}
 
Example #11
Source File: ResolveIvyFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Transformer<ModuleIdentifier, ModuleVersionSelector> getModuleExtractor(ConfiguredModuleVersionRepository rootRepository) {
    // If the backing repository is a custom ivy resolver, then we don't get a full listing
    if (rootRepository instanceof IvyAwareModuleVersionRepository) {
        return new LegacyIvyResolverModuleIdExtractor();
    }
    return new DefaultModuleIdExtractor();
}
 
Example #12
Source File: DependencyMetadataCache.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static boolean supply(ModuleVersionSelector requested, BuildableModuleVersionMetaDataResolveResult result, Map<ModuleVersionSelector, CachedModuleVersionResult> map, DependencyMetadataCacheStats stats) {
    CachedModuleVersionResult fromCache = map.get(requested);
    if (fromCache == null) {
        return false;
    }
    fromCache.supply(result);
    stats.metadataServed++;
    return true;
}
 
Example #13
Source File: VersionForcingDependencyToModuleResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ModuleVersionIdResolveResult resolve(DependencyMetaData dependency) {
    ModuleVersionSelector module = dependency.getRequested();
    DefaultDependencyResolveDetails details = new DefaultDependencyResolveDetails(module);
    try {
        rule.execute(details);
    } catch (Throwable e) {
        return new FailedDependencyResolveRuleResult(module, e);
    }
    if (details.isUpdated()) {
        DependencyMetaData substitutedDependency = dependency.withRequestedVersion(details.getTarget());
        ModuleVersionIdResolveResult result = resolver.resolve(substitutedDependency);
        return new SubstitutedModuleVersionIdResolveResult(result, details.getSelectionReason());
    }
    return resolver.resolve(dependency);
}
 
Example #14
Source File: DefaultDependencyMetaData.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DependencyMetaData withRequestedVersion(ModuleVersionSelector requestedVersion) {
    if (requestedVersion.equals(requested)) {
        return this;
    }

    ModuleRevisionId requestedId = IvyUtil.createModuleRevisionId(requestedVersion.getGroup(), requestedVersion.getName(), requestedVersion.getVersion());
    DependencyDescriptor substitutedDescriptor = new ReflectiveDependencyDescriptorFactory().create(dependencyDescriptor, requestedId);
    return new DefaultDependencyMetaData(substitutedDescriptor);
}
 
Example #15
Source File: ModuleVersionResolveException.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ModuleVersionResolveException createCopy() {
    try {
        return getClass().getConstructor(ModuleVersionSelector.class, String.class).newInstance(selector, messageFormat);
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #16
Source File: RepositoryChainDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void resolve(DependencyMetaData dependency, BuildableComponentResolveResult result) {
    ModuleVersionSelector requested = dependency.getRequested();
    LOGGER.debug("Attempting to resolve {} using repositories {}", requested, repositoryNames);
    ModuleComponentIdentifier moduleComponentIdentifier = new DefaultModuleComponentIdentifier(requested.getGroup(), requested.getName(), requested.getVersion());
    ModuleVersionIdentifier moduleVersionIdentifier = new DefaultModuleVersionIdentifier(requested.getGroup(), requested.getName(), requested.getVersion());

    List<Throwable> errors = new ArrayList<Throwable>();

    List<ComponentMetaDataResolveState> resolveStates = new ArrayList<ComponentMetaDataResolveState>();
    for (ModuleComponentRepository repository : repositories) {
        resolveStates.add(new ComponentMetaDataResolveState(dependency, moduleComponentIdentifier, repository, componentChooser));
    }

    final RepositoryChainModuleResolution latestResolved = findBestMatch(resolveStates, errors);
    if (latestResolved != null) {
        LOGGER.debug("Using {} from {}", latestResolved.module.getId(), latestResolved.repository);
        for (Throwable error : errors) {
            LOGGER.debug("Discarding resolve failure.", error);
        }

        result.resolved(metaDataFactory.transform(latestResolved));
        return;
    }
    if (!errors.isEmpty()) {
        result.failed(new ModuleVersionResolveException(moduleComponentIdentifier, errors));
    } else {
        for (ComponentMetaDataResolveState resolveState : resolveStates) {
            resolveState.applyTo(result);
        }
        result.notFound(moduleVersionIdentifier);
    }
}
 
Example #17
Source File: NewestVersionComponentChooser.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean versionMatches(ModuleVersionSelector requested, ModuleComponentIdentifier candidateIdentifier, MetaDataSupplier metaDataSupplier) {
    if (versionMatcher.needModuleMetadata(requested.getVersion())) {
        return versionMatcher.accept(requested.getVersion(), metaDataSupplier.create());
    } else {
        return versionMatcher.accept(requested.getVersion(), candidateIdentifier.getVersion());
    }
}
 
Example #18
Source File: ModuleForcingResolveRule.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ModuleForcingResolveRule(Collection<? extends ModuleVersionSelector> forcedModules) {
    if (!forcedModules.isEmpty()) {
        this.forcedModules = new HashMap<ModuleIdentifier, String>();
        for (ModuleVersionSelector module : forcedModules) {
            this.forcedModules.put(new DefaultModuleIdentifier(module.getGroup(), module.getName()), module.getVersion());
        }
    } else {
        this.forcedModules = null;
    }
}
 
Example #19
Source File: ModuleForcingResolveRule.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ModuleForcingResolveRule(Collection<? extends ModuleVersionSelector> forcedModules) {
    if (!forcedModules.isEmpty()) {
        this.forcedModules = new HashMap<ModuleIdentifier, String>();
        for (ModuleVersionSelector module : forcedModules) {
            this.forcedModules.put(new DefaultModuleIdentifier(module.getGroup(), module.getName()), module.getVersion());
        }
    } else {
        this.forcedModules = null;
    }
}
 
Example #20
Source File: ModuleForcingResolveRule.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ModuleForcingResolveRule(Collection<? extends ModuleVersionSelector> forcedModules) {
    if (!forcedModules.isEmpty()) {
        this.forcedModules = new HashMap<ModuleIdentifier, String>();
        for (ModuleVersionSelector module : forcedModules) {
            this.forcedModules.put(new DefaultModuleIdentifier(module.getGroup(), module.getName()), module.getVersion());
        }
    } else {
        this.forcedModules = null;
    }
}
 
Example #21
Source File: RepositoryChainDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void resolve(DependencyMetaData dependency, BuildableComponentResolveResult result) {
    ModuleVersionSelector requested = dependency.getRequested();
    LOGGER.debug("Attempting to resolve {} using repositories {}", requested, repositoryNames);
    ModuleComponentIdentifier moduleComponentIdentifier = new DefaultModuleComponentIdentifier(requested.getGroup(), requested.getName(), requested.getVersion());
    ModuleVersionIdentifier moduleVersionIdentifier = new DefaultModuleVersionIdentifier(requested.getGroup(), requested.getName(), requested.getVersion());

    List<Throwable> errors = new ArrayList<Throwable>();

    List<ComponentMetaDataResolveState> resolveStates = new ArrayList<ComponentMetaDataResolveState>();
    for (ModuleComponentRepository repository : repositories) {
        resolveStates.add(new ComponentMetaDataResolveState(dependency, moduleComponentIdentifier, repository, componentChooser));
    }

    final RepositoryChainModuleResolution latestResolved = findBestMatch(resolveStates, errors);
    if (latestResolved != null) {
        LOGGER.debug("Using {} from {}", latestResolved.module.getId(), latestResolved.repository);
        for (Throwable error : errors) {
            LOGGER.debug("Discarding resolve failure.", error);
        }

        result.resolved(metaDataFactory.transform(latestResolved));
        return;
    }
    if (!errors.isEmpty()) {
        result.failed(new ModuleVersionResolveException(moduleComponentIdentifier, errors));
    } else {
        for (ComponentMetaDataResolveState resolveState : resolveStates) {
            resolveState.applyTo(result);
        }
        result.notFound(moduleVersionIdentifier);
    }
}
 
Example #22
Source File: ModuleVersionSelectorStrictSpec.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ModuleVersionSelectorStrictSpec(ModuleVersionSelector selector) {
    assert selector != null;
    this.selector = selector;
}
 
Example #23
Source File: ModuleVersionResolveException.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ModuleVersionResolveException(ModuleVersionSelector selector, String messageFormat) {
    super(format(messageFormat, selector));
    this.selector = selector;
    this.messageFormat = messageFormat;
}
 
Example #24
Source File: DefaultUnresolvedDependencyResult.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ModuleComponentSelector getAttempted() {
    ModuleVersionSelector moduleVersionSelector = failure.getSelector();
    return DefaultModuleComponentSelector.newSelector(moduleVersionSelector.getGroup(), moduleVersionSelector.getName(), moduleVersionSelector.getVersion());
}
 
Example #25
Source File: DefaultBuildableComponentResolveResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void notFound(ModuleVersionSelector versionSelector) {
    failed(new ModuleVersionNotFoundException(versionSelector));
}
 
Example #26
Source File: DefaultUnresolvedDependencyResult.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ModuleComponentSelector getAttempted() {
    ModuleVersionSelector moduleVersionSelector = failure.getSelector();
    return DefaultModuleComponentSelector.newSelector(moduleVersionSelector.getGroup(), moduleVersionSelector.getName(), moduleVersionSelector.getVersion());
}
 
Example #27
Source File: ModuleVersionResolveException.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static String format(String messageFormat, ModuleVersionSelector id) {
    return format(messageFormat, id.getGroup(), id.getName(), id.getVersion());
}
 
Example #28
Source File: ModuleVersionSelectorStrictSpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ModuleVersionSelectorStrictSpec(ModuleVersionSelector selector) {
    assert selector != null;
    this.selector = selector;
}
 
Example #29
Source File: DefaultUnresolvedDependency.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultUnresolvedDependency(ModuleVersionSelector selector, Throwable problem) {
    this.selector = selector;
    this.problem = problem;
}
 
Example #30
Source File: DependencyMetadataCache.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void newDependencyResult(ModuleVersionSelector requested, BuildableModuleVersionMetaDataResolveResult result) {
    newResult(requested, result, metaData);
}