Search in sources :

Example 1 with ModuleComponentSelector

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

the class DefaultDependencyMetadata method withTarget.

@Override
public DependencyMetadata withTarget(ComponentSelector target) {
    if (target instanceof ModuleComponentSelector) {
        ModuleComponentSelector moduleTarget = (ModuleComponentSelector) target;
        ModuleVersionSelector requestedVersion = DefaultModuleVersionSelector.newSelector(moduleTarget.getGroup(), moduleTarget.getModule(), moduleTarget.getVersion());
        if (requestedVersion.equals(requested)) {
            return this;
        }
        return withRequested(requestedVersion);
    } else if (target instanceof ProjectComponentSelector) {
        ProjectComponentSelector projectTarget = (ProjectComponentSelector) target;
        return new DefaultProjectDependencyMetadata(projectTarget, this);
    } else {
        throw new IllegalArgumentException("Unexpected selector provided: " + target);
    }
}
Also used : DefaultProjectDependencyMetadata(org.gradle.internal.component.local.model.DefaultProjectDependencyMetadata) DefaultModuleVersionSelector(org.gradle.api.internal.artifacts.DefaultModuleVersionSelector) ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector)

Example 2 with ModuleComponentSelector

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

the class LocalComponentDependencyMetadata method withTarget.

@Override
public LocalOriginDependencyMetadata withTarget(ComponentSelector target) {
    if (target instanceof ModuleComponentSelector) {
        ModuleComponentSelector moduleTarget = (ModuleComponentSelector) target;
        ModuleVersionSelector requestedVersion = DefaultModuleVersionSelector.newSelector(moduleTarget.getGroup(), moduleTarget.getModule(), moduleTarget.getVersion());
        if (selector.equals(target) && requested.equals(requestedVersion)) {
            return this;
        }
        return copyWithTarget(moduleTarget, requestedVersion);
    } else if (target instanceof ProjectComponentSelector) {
        if (target.equals(selector)) {
            return this;
        }
        return copyWithTarget(target, requested);
    } else {
        throw new AssertionError("Invalid component selector type for substitution: " + target);
    }
}
Also used : DefaultModuleVersionSelector(org.gradle.api.internal.artifacts.DefaultModuleVersionSelector) ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector)

Example 3 with ModuleComponentSelector

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

the class ExternalModuleIvyDependencyDescriptorFactory method createDependencyDescriptor.

public DslOriginDependencyMetadata createDependencyDescriptor(String clientConfiguration, AttributeContainer clientAttributes, ModuleDependency dependency) {
    ExternalModuleDependency externalModuleDependency = (ExternalModuleDependency) dependency;
    boolean force = externalModuleDependency.isForce();
    boolean changing = externalModuleDependency.isChanging();
    boolean transitive = externalModuleDependency.isTransitive();
    ModuleVersionSelector requested = new DefaultModuleVersionSelector(nullToEmpty(dependency.getGroup()), nullToEmpty(dependency.getName()), nullToEmpty(dependency.getVersion()));
    ModuleComponentSelector selector = DefaultModuleComponentSelector.newSelector(requested);
    List<Exclude> excludes = convertExcludeRules(clientConfiguration, dependency.getExcludeRules());
    LocalComponentDependencyMetadata dependencyMetaData = new LocalComponentDependencyMetadata(selector, requested, clientConfiguration, clientAttributes, dependency.getTargetConfiguration(), convertArtifacts(dependency.getArtifacts()), excludes, force, changing, transitive);
    return new DslOriginDependencyMetadataWrapper(dependencyMetaData, dependency);
}
Also used : DefaultModuleVersionSelector(org.gradle.api.internal.artifacts.DefaultModuleVersionSelector) ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) DefaultModuleVersionSelector(org.gradle.api.internal.artifacts.DefaultModuleVersionSelector) Exclude(org.gradle.internal.component.model.Exclude) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DslOriginDependencyMetadataWrapper(org.gradle.internal.component.local.model.DslOriginDependencyMetadataWrapper) ExternalModuleDependency(org.gradle.api.artifacts.ExternalModuleDependency) LocalComponentDependencyMetadata(org.gradle.internal.component.model.LocalComponentDependencyMetadata)

Example 4 with ModuleComponentSelector

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

the class DynamicVersionResolver method resolve.

public void resolve(ModuleDependencyMetadata dependency, VersionSelector versionSelector, VersionSelector rejectedVersionSelector, BuildableComponentIdResolveResult result) {
    ModuleComponentSelector requested = dependency.getSelector();
    LOGGER.debug("Attempting to resolve version for {} using repositories {}", requested, repositoryNames);
    List<Throwable> errors = new ArrayList<Throwable>();
    List<RepositoryResolveState> resolveStates = Lists.newArrayListWithCapacity(repositories.size());
    for (ModuleComponentRepository repository : repositories) {
        resolveStates.add(new RepositoryResolveState(versionedComponentChooser, dependency, repository, versionSelector, rejectedVersionSelector));
    }
    final RepositoryChainModuleResolution latestResolved = findLatestModule(resolveStates, errors);
    if (latestResolved != null) {
        LOGGER.debug("Using {} from {}", latestResolved.module.getModuleVersionId(), 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 {
        notFound(result, requested, resolveStates);
    }
}
Also used : ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ArrayList(java.util.ArrayList) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException)

Example 5 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, boolean optional, boolean useCompileScope) {
    MavenScope scope;
    if (useCompileScope) {
        scope = MavenScope.Compile;
    } else {
        String scopeString = dep.getScope();
        if (scopeString == null || scopeString.length() == 0) {
            scopeString = getDefaultScope(dep);
        }
        if (SCOPES.containsKey(scopeString)) {
            scope = SCOPES.get(scopeString);
        } else {
            // unknown scope, defaulting to 'compile'
            scope = MavenScope.Compile;
        }
    }
    String version = determineVersion(dep);
    String mappedVersion = convertVersionFromMavenSyntax(version);
    ModuleComponentSelector selector = DefaultModuleComponentSelector.newSelector(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.getGroup().equals(componentIdentifier.getGroup()) && selector.getModule().equals(componentIdentifier.getModule())) {
        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, optional, 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.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) ExcludeMetadata(org.gradle.internal.component.model.ExcludeMetadata)

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