Search in sources :

Example 11 with ModuleIdentifier

use of org.gradle.api.artifacts.ModuleIdentifier 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 12 with ModuleIdentifier

use of org.gradle.api.artifacts.ModuleIdentifier in project gradle by gradle.

the class JsonProjectDependencyRenderer method collectModules.

private Set<ModuleIdentifier> collectModules(Configuration configuration) {
    RenderableDependency root;
    if (canBeResolved(configuration)) {
        ResolutionResult result = configuration.getIncoming().getResolutionResult();
        root = new RenderableModuleResult(result.getRoot());
    } else {
        root = new UnresolvableConfigurationResult(configuration);
    }
    Set<ModuleIdentifier> modules = Sets.newHashSet();
    Set<ComponentIdentifier> visited = Sets.newHashSet();
    populateModulesWithChildDependencies(root, visited, modules);
    return modules;
}
Also used : RenderableDependency(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency) UnresolvableConfigurationResult(org.gradle.api.tasks.diagnostics.internal.graph.nodes.UnresolvableConfigurationResult) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) RenderableModuleResult(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableModuleResult)

Example 13 with ModuleIdentifier

use of org.gradle.api.artifacts.ModuleIdentifier in project gradle by gradle.

the class NodeState method getEndorsedStrictVersions.

private StrictVersionConstraints getEndorsedStrictVersions(EdgeState incomingEdge) {
    if (incomingEdge.getFrom().endorsesStrictVersionsFrom == null) {
        return StrictVersionConstraints.EMPTY;
    }
    boolean filterOwn = false;
    StrictVersionConstraints singleStrictVersionConstraints = StrictVersionConstraints.EMPTY;
    Set<ModuleIdentifier> collectedConstraints = null;
    for (EdgeState edgeState : incomingEdge.getFrom().endorsesStrictVersionsFrom) {
        if (edgeState == incomingEdge) {
            // These are my own constraints. I can not treat them as inherited,
            // because that assumes that they are defined in another node as well and might be ignored.
            filterOwn = true;
            continue;
        }
        ComponentState targetComponent = edgeState.getTargetComponent();
        if (targetComponent != null) {
            // may be null if the build is about to fail
            for (NodeState sourceNode : targetComponent.getNodes()) {
                if (sourceNode.ownStrictVersionConstraints == null) {
                    // node's dependencies were not yet visited
                    sourceNode.collectOwnStrictVersions();
                }
                if (singleStrictVersionConstraints.isEmpty()) {
                    singleStrictVersionConstraints = sourceNode.ownStrictVersionConstraints;
                } else {
                    if (collectedConstraints == null) {
                        collectedConstraints = Sets.newHashSet();
                        collectedConstraints.addAll(singleStrictVersionConstraints.getModules());
                    }
                    collectedConstraints.addAll(sourceNode.ownStrictVersionConstraints.getModules());
                }
            }
        }
    }
    if (filterOwn) {
        Set<ModuleIdentifier> resultSet;
        if (collectedConstraints != null) {
            resultSet = collectedConstraints;
        } else {
            resultSet = singleStrictVersionConstraints.getModules();
        }
        if (ownStrictVersionConstraints == null) {
            collectOwnStrictVersions();
        }
        for (ModuleIdentifier ownConstraint : ownStrictVersionConstraints.getModules()) {
            if (resultSet.contains(ownConstraint)) {
                if (collectedConstraints == null) {
                    collectedConstraints = Sets.newHashSet();
                    collectedConstraints.addAll(singleStrictVersionConstraints.getModules());
                }
                collectedConstraints.remove(ownConstraint);
            }
        }
    }
    if (collectedConstraints != null) {
        return StrictVersionConstraints.of(collectedConstraints);
    } else {
        return singleStrictVersionConstraints;
    }
}
Also used : StrictVersionConstraints(org.gradle.api.internal.artifacts.ivyservice.resolveengine.strict.StrictVersionConstraints) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 14 with ModuleIdentifier

use of org.gradle.api.artifacts.ModuleIdentifier in project gradle by gradle.

the class NodeState method cleanupConstraints.

/*
     * When a node exits the graph, its constraints need to be cleaned up.
     * This means:
     * * Rescheduling any deferred selection impacted by a constraint coming from this node
     * * Making sure we no longer are registered as pending interest on nodes pointed by constraints
     */
private void cleanupConstraints() {
    // This part covers constraint that were taken into account between a selection being deferred and this node being scheduled for traversal
    if (upcomingNoLongerPendingConstraints != null) {
        for (ModuleIdentifier identifier : upcomingNoLongerPendingConstraints) {
            ModuleResolveState module = resolveState.getModule(identifier);
            for (EdgeState unattachedDependency : module.getUnattachedDependencies()) {
                if (!unattachedDependency.getSelector().isResolved()) {
                    // Unresolved - we have a selector that was deferred but the constraint has been removed in between
                    NodeState from = unattachedDependency.getFrom();
                    from.prepareToRecomputeEdge(unattachedDependency);
                }
            }
        }
        upcomingNoLongerPendingConstraints = null;
    }
    // This part covers constraint that might be triggered in the future if the node they point gains a real edge
    if (cachedFilteredDependencyStates != null && !cachedFilteredDependencyStates.isEmpty()) {
        // Let's clear that state since it is no longer part of selection
        for (DependencyState dependencyState : cachedFilteredDependencyStates) {
            if (dependencyState.getDependency().isConstraint()) {
                ModuleResolveState targetModule = resolveState.getModule(dependencyState.getModuleIdentifier());
                if (targetModule.isPending()) {
                    targetModule.unregisterConstraintProvider(this);
                }
            }
        }
    }
}
Also used : ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 15 with ModuleIdentifier

use of org.gradle.api.artifacts.ModuleIdentifier in project gradle by gradle.

the class NodeState method isExcluded.

private boolean isExcluded(ExcludeSpec excludeSpec, DependencyState dependencyState) {
    DependencyMetadata dependency = dependencyState.getDependency();
    if (!resolveState.getEdgeFilter().isSatisfiedBy(dependency)) {
        LOGGER.debug("{} is filtered.", dependency);
        return true;
    }
    if (excludeSpec == moduleExclusions.nothing()) {
        return false;
    }
    ModuleIdentifier targetModuleId = dependencyState.getModuleIdentifier();
    if (excludeSpec.excludes(targetModuleId)) {
        LOGGER.debug("{} is excluded from {} by {}.", targetModuleId, this, excludeSpec);
        return true;
    }
    return false;
}
Also used : LocalFileDependencyMetadata(org.gradle.internal.component.local.model.LocalFileDependencyMetadata) DependencyMetadata(org.gradle.internal.component.model.DependencyMetadata) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Aggregations

ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)46 DefaultModuleIdentifier (org.gradle.api.internal.artifacts.DefaultModuleIdentifier)8 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)7 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)5 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)5 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 ExcludeSpec (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)4 GroupExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupExclude)4 GroupSetExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupSetExclude)4 ModuleExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleExclude)4 ModuleIdExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdExclude)4 ModuleIdSetExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdSetExclude)4 ModuleSetExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleSetExclude)4 LinkedHashSet (java.util.LinkedHashSet)3 Action (org.gradle.api.Action)3 InvalidUserCodeException (org.gradle.api.InvalidUserCodeException)3 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)3 DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)3 DefaultModuleComponentSelector (org.gradle.internal.component.external.model.DefaultModuleComponentSelector)3