Search in sources :

Example 16 with ModuleComponentSelector

use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.

the class GradlePomModuleDescriptorParser method parseImportedDependencyMgts.

/**
 * Parses imported dependency management information.
 *
 * @param parseContext Parse context
 * @param currentDependencyMgts Current dependency management information
 * @return Imported dependency management information
 */
private Map<MavenDependencyKey, PomDependencyMgt> parseImportedDependencyMgts(DescriptorParseContext parseContext, Collection<PomDependencyMgt> currentDependencyMgts) throws IOException, SAXException {
    Map<MavenDependencyKey, PomDependencyMgt> importedDependencyMgts = new LinkedHashMap<>();
    for (PomDependencyMgt currentDependencyMgt : currentDependencyMgts) {
        if (isDependencyImportScoped(currentDependencyMgt)) {
            ModuleComponentSelector importedId = DefaultModuleComponentSelector.newSelector(DefaultModuleIdentifier.newId(currentDependencyMgt.getGroupId(), currentDependencyMgt.getArtifactId()), new DefaultImmutableVersionConstraint(currentDependencyMgt.getVersion()));
            PomReader importedPom = parsePomForSelector(parseContext, importedId, Maps.newHashMap());
            for (Map.Entry<MavenDependencyKey, PomDependencyMgt> entry : importedPom.getDependencyMgt().entrySet()) {
                if (!importedDependencyMgts.containsKey(entry.getKey())) {
                    importedDependencyMgts.put(entry.getKey(), entry.getValue());
                }
            }
        }
    }
    return importedDependencyMgts;
}
Also used : DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) PomDependencyMgt(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.data.PomDependencyMgt) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MavenDependencyKey(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.data.MavenDependencyKey) LinkedHashMap(java.util.LinkedHashMap)

Example 17 with ModuleComponentSelector

use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.

the class RepositoryChainDependencyToComponentIdResolver method resolve.

@Override
public void resolve(DependencyMetadata dependency, VersionSelector acceptor, @Nullable VersionSelector rejector, BuildableComponentIdResolveResult result) {
    ComponentSelector componentSelector = dependency.getSelector();
    if (componentSelector instanceof ModuleComponentSelector) {
        ModuleComponentSelector module = (ModuleComponentSelector) componentSelector;
        if (acceptor.isDynamic()) {
            dynamicRevisionResolver.resolve(toModuleDependencyMetadata(dependency), acceptor, rejector, consumerAttributes, result);
        } else {
            String version = acceptor.getSelector();
            ModuleIdentifier moduleId = module.getModuleIdentifier();
            ModuleComponentIdentifier id = DefaultModuleComponentIdentifier.newId(moduleId, version);
            ModuleVersionIdentifier mvId = DefaultModuleVersionIdentifier.newId(moduleId, version);
            if (rejector != null && rejector.accept(version)) {
                result.rejected(id, mvId);
            } else {
                result.resolved(id, mvId);
            }
        }
    }
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 18 with ModuleComponentSelector

use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.

the class IvyModuleDescriptorConverter method addDependency.

private void addDependency(List<IvyDependencyDescriptor> result, DependencyDescriptor dependencyDescriptor) {
    ModuleRevisionId revisionId = dependencyDescriptor.getDependencyRevisionId();
    ModuleComponentSelector requested = DefaultModuleComponentSelector.newSelector(DefaultModuleIdentifier.newId(revisionId.getOrganisation(), revisionId.getName()), new DefaultImmutableVersionConstraint(revisionId.getRevision()));
    ListMultimap<String, String> configMappings = ArrayListMultimap.create();
    for (Map.Entry<String, List<String>> entry : readConfigMappings(dependencyDescriptor).entrySet()) {
        configMappings.putAll(entry.getKey(), entry.getValue());
    }
    List<Artifact> artifacts = Lists.newArrayList();
    for (DependencyArtifactDescriptor ivyArtifact : dependencyDescriptor.getAllDependencyArtifacts()) {
        IvyArtifactName ivyArtifactName = new DefaultIvyArtifactName(ivyArtifact.getName(), ivyArtifact.getType(), ivyArtifact.getExt(), (String) ivyArtifact.getExtraAttributes().get(CLASSIFIER));
        artifacts.add(new Artifact(ivyArtifactName, Sets.newHashSet(ivyArtifact.getConfigurations())));
    }
    List<Exclude> excludes = Lists.newArrayList();
    for (ExcludeRule excludeRule : dependencyDescriptor.getAllExcludeRules()) {
        excludes.add(forIvyExclude(excludeRule));
    }
    result.add(new IvyDependencyDescriptor(requested, dependencyDescriptor.getDynamicConstraintDependencyRevisionId().getRevision(), dependencyDescriptor.isChanging(), dependencyDescriptor.isTransitive(), false, configMappings, artifacts, excludes));
}
Also used : DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) Exclude(org.gradle.internal.component.model.Exclude) DefaultExclude(org.gradle.internal.component.external.descriptor.DefaultExclude) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ExcludeRule(org.apache.ivy.core.module.descriptor.ExcludeRule) Artifact(org.gradle.internal.component.external.descriptor.Artifact) DependencyArtifactDescriptor(org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor) IvyDependencyDescriptor(org.gradle.internal.component.external.model.ivy.IvyDependencyDescriptor) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) List(java.util.List) Map(java.util.Map)

Example 19 with ModuleComponentSelector

use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.

the class GradlePomModuleDescriptorBuilder method doAddDependency.

private void doAddDependency(PomDependencyMgt dep, MavenDependencyType dependencyType) {
    MavenScope scope;
    if (dependencyType == MavenDependencyType.DEPENDENCY_MANAGEMENT) {
        scope = MavenScope.Compile;
    } else {
        String scopeString = dep.getScope();
        if (scopeString == null || scopeString.length() == 0) {
            scopeString = getDefaultScope(dep);
        }
        // unknown scope, defaulting to 'compile'
        scope = SCOPES.getOrDefault(scopeString, MavenScope.Compile);
    }
    String version = determineVersion(dep);
    String mappedVersion = convertVersionFromMavenSyntax(version);
    ModuleComponentSelector selector = DefaultModuleComponentSelector.newSelector(DefaultModuleIdentifier.newId(dep.getGroupId(), dep.getArtifactId()), new DefaultImmutableVersionConstraint(mappedVersion));
    // Example: http://repo2.maven.org/maven2/net/jini/jsk-platform/2.1/jsk-platform-2.1.pom
    if (selector.getModuleIdentifier().equals(componentIdentifier.getModuleIdentifier())) {
        return;
    }
    IvyArtifactName dependencyArtifact = null;
    boolean hasClassifier = dep.getClassifier() != null && dep.getClassifier().length() > 0;
    boolean hasNonJarType = dep.getType() != null && !"jar".equals(dep.getType());
    if (hasClassifier || hasNonJarType) {
        String type = "jar";
        if (dep.getType() != null) {
            type = dep.getType();
        }
        String ext = determineExtension(type);
        String classifier = hasClassifier ? dep.getClassifier() : getClassifierForType(type);
        dependencyArtifact = new DefaultIvyArtifactName(selector.getModule(), type, ext, classifier);
    }
    // experimentation shows the following, excluded modules are
    // inherited from parent POMs if either of the following is true:
    // the <exclusions> element is missing or the <exclusions> element
    // is present, but empty.
    List<ExcludeMetadata> excludes = Lists.newArrayList();
    List<ModuleIdentifier> excluded = dep.getExcludedModules();
    if (excluded.isEmpty()) {
        excluded = getDependencyMgtExclusions(dep);
    }
    for (ModuleIdentifier excludedModule : excluded) {
        DefaultExclude rule = new DefaultExclude(excludedModule);
        excludes.add(rule);
    }
    dependencies.add(new MavenDependencyDescriptor(scope, dependencyType, selector, dependencyArtifact, excludes));
}
Also used : DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) DefaultExclude(org.gradle.internal.component.external.descriptor.DefaultExclude) MavenScope(org.gradle.internal.component.external.descriptor.MavenScope) MavenDependencyDescriptor(org.gradle.internal.component.external.model.maven.MavenDependencyDescriptor) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) DefaultModuleIdentifier(org.gradle.api.internal.artifacts.DefaultModuleIdentifier) ExcludeMetadata(org.gradle.internal.component.model.ExcludeMetadata)

Example 20 with ModuleComponentSelector

use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.

the class DefaultDependencyResolveDetails method complete.

public void complete() {
    if (!dirty) {
        return;
    }
    ComponentSelectionDescriptorInternal selectionReason = selectionReason();
    if (useSelector != null) {
        delegate.useTarget(useSelector, selectionReason);
    } else if (useVersion != null) {
        if (delegate.getTarget() instanceof ModuleComponentSelector) {
            ModuleComponentSelector target = (ModuleComponentSelector) delegate.getTarget();
            if (!useVersion.equals(target.getVersionConstraint())) {
                delegate.useTarget(DefaultModuleComponentSelector.newSelector(target.getModuleIdentifier(), useVersion, target.getAttributes(), target.getRequestedCapabilities()), selectionReason);
            } else {
                // Still 'updated' with reason when version remains the same.
                delegate.useTarget(delegate.getTarget(), selectionReason);
            }
        } else {
            // If the current target is a project component, it must be unmodified from the requested
            ModuleComponentSelector newTarget = DefaultModuleComponentSelector.newSelector(DefaultModuleIdentifier.newId(requested.getGroup(), requested.getName()), useVersion);
            delegate.useTarget(newTarget, selectionReason);
        }
    }
    delegate.artifactSelection(artifactSelectionAction);
    dirty = false;
}
Also used : DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ComponentSelectionDescriptorInternal(org.gradle.api.internal.artifacts.ivyservice.resolveengine.result.ComponentSelectionDescriptorInternal)

Aggregations

ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)46 DefaultModuleComponentSelector (org.gradle.internal.component.external.model.DefaultModuleComponentSelector)21 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)10 ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)9 DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)8 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)7 ExcludeMetadata (org.gradle.internal.component.model.ExcludeMetadata)6 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)5 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)5 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)5 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)5 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)5 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)4 DefaultModuleVersionSelector (org.gradle.api.internal.artifacts.DefaultModuleVersionSelector)4 DefaultExclude (org.gradle.internal.component.external.descriptor.DefaultExclude)4 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)4 ArrayList (java.util.ArrayList)3 ExternalModuleDependency (org.gradle.api.artifacts.ExternalModuleDependency)3 VersionConstraint (org.gradle.api.artifacts.VersionConstraint)3 MavenScope (org.gradle.internal.component.external.descriptor.MavenScope)3