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
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 #2
Source Project: pushfish-android   Author: PushFish   File: ExternalResourceResolver.java    License: 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 #3
Source Project: pushfish-android   Author: PushFish   File: ModuleVersionSelectorParsers.java    License: 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 #4
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 #5
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 #6
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 Project: Pushjet-Android   Author: Pushjet   File: ModuleVersionSelectorParsers.java    License: 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 #8
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 #9
Source Project: Pushjet-Android   Author: Pushjet   File: ModuleForcingResolveRule.java    License: 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 #10
Source Project: pushfish-android   Author: PushFish   File: ModuleForcingResolveRule.java    License: 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 #11
Source Project: Pushjet-Android   Author: Pushjet   File: ModuleForcingResolveRule.java    License: 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 #12
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 #13
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 Project: Pushjet-Android   Author: Pushjet   File: InMemoryMetaDataCache.java    License: 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 #15
Source Project: Pushjet-Android   Author: Pushjet   File: NewestVersionComponentChooser.java    License: 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 #16
Source Project: pushfish-android   Author: PushFish   File: DefaultDependencyMetaData.java    License: 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 #17
Source Project: pushfish-android   Author: PushFish   File: DependencyMetadataCache.java    License: 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 #18
Source Project: Pushjet-Android   Author: Pushjet   File: DynamicVersionResolver.java    License: 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 #19
Source Project: pushfish-android   Author: PushFish   File: ModuleVersionResolveException.java    License: 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 #20
Source Project: pushfish-android   Author: PushFish   File: ResolveIvyFactory.java    License: 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 #21
Source Project: Pushjet-Android   Author: Pushjet   File: ModuleVersionResolveException.java    License: 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 #22
Source Project: pushfish-android   Author: PushFish   File: DefaultUnresolvedDependency.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultUnresolvedDependency(ModuleVersionSelector selector, Throwable problem) {
    this.selector = selector;
    this.problem = problem;
}
 
Example #23
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultUnresolvedDependency.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ModuleVersionSelector getSelector() {
    return selector;
}
 
Example #24
public ModuleVersionSelector getTarget() {
    return target;
}
 
Example #25
Source Project: Pushjet-Android   Author: Pushjet   File: ModuleVersionSelectorParsers.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static NotationParser<Object, ModuleVersionSelector> parser() {
    return builder().toComposite();
}
 
Example #26
Source Project: Pushjet-Android   Author: Pushjet   File: DependencyMetadataCache.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static void newResult(ModuleVersionSelector requested, BuildableModuleVersionMetaDataResolveResult result, Map<ModuleVersionSelector, CachedModuleVersionResult> map) {
    CachedModuleVersionResult cachedResult = new CachedModuleVersionResult(result);
    if (cachedResult.isCacheable()) {
        map.put(requested, cachedResult);
    }
}
 
Example #27
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultResolutionStrategy.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultResolutionStrategy setForcedModules(Object ... moduleVersionSelectorNotations) {
    Set<ModuleVersionSelector> forcedModules = ModuleVersionSelectorParsers.multiParser().parseNotation(moduleVersionSelectorNotations);
    this.forcedModules = forcedModules;
    return this;
}
 
Example #28
Source Project: pushfish-android   Author: PushFish   File: DependencyMetadataCache.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
void newLocalDependencyResult(ModuleVersionSelector requested, BuildableModuleVersionMetaDataResolveResult result) {
    newResult(requested, result, localMetaData);
}
 
Example #29
Source Project: pushfish-android   Author: PushFish   File: InMemoryMetaDataCache.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void newModuleVersions(ModuleVersionSelector requested, BuildableModuleComponentVersionSelectionResolveResult result) {
    if (result.getState() == Listed) {
        moduleVersionListing.put(requested, result.getVersions());
    }
}
 
Example #30
private DefaultModuleIdentifier getCacheKey(ModuleVersionSelector requested) {
    return new DefaultModuleIdentifier(requested.getGroup(), requested.getName());
}