Search in sources :

Example 1 with DefaultImmutableVersionConstraint

use of org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint 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)

Example 2 with DefaultImmutableVersionConstraint

use of org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint in project gradle by gradle.

the class ComponentSelectorSerializer method readVersionConstraint.

ImmutableVersionConstraint readVersionConstraint(Decoder decoder) throws IOException {
    String requires = decoder.readString();
    String prefers = decoder.readString();
    String strictly = decoder.readString();
    int rejectCount = decoder.readSmallInt();
    List<String> rejects = Lists.newArrayListWithCapacity(rejectCount);
    for (int i = 0; i < rejectCount; i++) {
        rejects.add(decoder.readString());
    }
    String branch = decoder.readNullableString();
    return new DefaultImmutableVersionConstraint(prefers, requires, strictly, rejects, branch);
}
Also used : DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ImmutableVersionConstraint(org.gradle.api.internal.artifacts.ImmutableVersionConstraint) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)

Example 3 with DefaultImmutableVersionConstraint

use of org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint in project gradle by gradle.

the class DefaultIvyModulePublishMetadata method normalizeVersionForIvy.

/**
 * [1.0] is a valid version in maven, but not in Ivy: strip the surrounding '[' and ']' characters for ivy publish.
 */
private static LocalOriginDependencyMetadata normalizeVersionForIvy(LocalOriginDependencyMetadata dependency) {
    if (dependency.getSelector() instanceof ModuleComponentSelector) {
        ModuleComponentSelector selector = (ModuleComponentSelector) dependency.getSelector();
        VersionConstraint versionConstraint = selector.getVersionConstraint();
        DefaultImmutableVersionConstraint transformedConstraint = new DefaultImmutableVersionConstraint(VERSION_TRANSFORMER.transform(versionConstraint.getPreferredVersion()), VERSION_TRANSFORMER.transform(versionConstraint.getRequiredVersion()), VERSION_TRANSFORMER.transform(versionConstraint.getStrictVersion()), CollectionUtils.collect(versionConstraint.getRejectedVersions(), VERSION_TRANSFORMER), versionConstraint.getBranch());
        ModuleComponentSelector newSelector = DefaultModuleComponentSelector.newSelector(selector.getModuleIdentifier(), transformedConstraint, selector.getAttributes(), selector.getRequestedCapabilities());
        return dependency.withTarget(newSelector);
    }
    return dependency;
}
Also used : VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector)

Example 4 with DefaultImmutableVersionConstraint

use of org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint 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 5 with DefaultImmutableVersionConstraint

use of org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint 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)

Aggregations

DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)9 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)7 DefaultModuleComponentSelector (org.gradle.internal.component.external.model.DefaultModuleComponentSelector)6 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)3 VersionConstraint (org.gradle.api.artifacts.VersionConstraint)3 DefaultExclude (org.gradle.internal.component.external.descriptor.DefaultExclude)3 DefaultIvyArtifactName (org.gradle.internal.component.model.DefaultIvyArtifactName)3 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)3 Map (java.util.Map)2 MavenScope (org.gradle.internal.component.external.descriptor.MavenScope)2 ExcludeMetadata (org.gradle.internal.component.model.ExcludeMetadata)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 DependencyArtifactDescriptor (org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor)1 ExcludeRule (org.apache.ivy.core.module.descriptor.ExcludeRule)1 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 DefaultModuleIdentifier (org.gradle.api.internal.artifacts.DefaultModuleIdentifier)1 ImmutableVersionConstraint (org.gradle.api.internal.artifacts.ImmutableVersionConstraint)1 DefaultMutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultMutableVersionConstraint)1