Search in sources :

Example 1 with ModuleIdentifier

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

the class ModuleExclusions method forExclude.

private static AbstractModuleExclusion forExclude(Exclude rule) {
    // For custom ivy pattern matchers, don't inspect the rule any more deeply: this prevents us from doing smart merging later
    if (!PatternMatchers.isExactMatcher(rule.getMatcher())) {
        return new IvyPatternMatcherExcludeRuleSpec(rule);
    }
    ModuleIdentifier moduleId = rule.getModuleId();
    IvyArtifactName artifact = rule.getArtifact();
    boolean anyOrganisation = isWildcard(moduleId.getGroup());
    boolean anyModule = isWildcard(moduleId.getName());
    boolean anyArtifact = isWildcard(artifact.getName()) && isWildcard(artifact.getType()) && isWildcard(artifact.getExtension());
    // Build a strongly typed (mergeable) exclude spec for each supplied rule
    if (anyArtifact) {
        if (!anyOrganisation && !anyModule) {
            return new ModuleIdExcludeSpec(moduleId);
        } else if (!anyModule) {
            return new ModuleNameExcludeSpec(moduleId.getName());
        } else if (!anyOrganisation) {
            return new GroupNameExcludeSpec(moduleId.getGroup());
        } else {
            return EXCLUDE_ALL_MODULES_SPEC;
        }
    } else {
        return new ArtifactExcludeSpec(moduleId, artifact);
    }
}
Also used : IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 2 with ModuleIdentifier

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

the class DependencyGraphBuilder method traverseGraph.

/**
     * Traverses the dependency graph, resolving conflicts and building the paths from the root configuration.
     */
private void traverseGraph(final ResolveState resolveState, final ConflictHandler conflictHandler) {
    resolveState.onMoreSelected(resolveState.root);
    List<DependencyEdge> dependencies = new ArrayList<DependencyEdge>();
    while (resolveState.peek() != null || conflictHandler.hasConflicts()) {
        if (resolveState.peek() != null) {
            ConfigurationNode node = resolveState.pop();
            LOGGER.debug("Visiting configuration {}.", node);
            // Calculate the outgoing edges of this configuration
            dependencies.clear();
            node.visitOutgoingDependencies(dependencies);
            for (DependencyEdge dependency : dependencies) {
                LOGGER.debug("Visiting dependency {}", dependency);
                // Resolve dependency to a particular revision
                ModuleVersionResolveState moduleRevision = dependency.resolveModuleRevisionId();
                if (moduleRevision == null) {
                    // Failed to resolve.
                    continue;
                }
                ModuleIdentifier moduleId = moduleRevision.id.getModule();
                // Check for a new conflict
                if (moduleRevision.state == ModuleState.New) {
                    ModuleResolveState module = resolveState.getModule(moduleId);
                    // A new module revision. Check for conflict
                    PotentialConflict c = conflictHandler.registerModule(module);
                    if (!c.conflictExists()) {
                        // No conflict. Select it for now
                        LOGGER.debug("Selecting new module version {}", moduleRevision);
                        module.select(moduleRevision);
                    } else {
                        // We have a conflict
                        LOGGER.debug("Found new conflicting module version {}", moduleRevision);
                        // Deselect the currently selected version, and remove all outgoing edges from the version
                        // This will propagate through the graph and prune configurations that are no longer required
                        // For each module participating in the conflict (many times there is only one participating module that has multiple versions)
                        c.withParticipatingModules(new Action<ModuleIdentifier>() {

                            public void execute(ModuleIdentifier module) {
                                ModuleVersionResolveState previouslySelected = resolveState.getModule(module).clearSelection();
                                if (previouslySelected != null) {
                                    for (ConfigurationNode configuration : previouslySelected.configurations) {
                                        configuration.deselect();
                                    }
                                }
                            }
                        });
                    }
                }
                dependency.attachToTargetConfigurations();
            }
        } else {
            // We have some batched up conflicts. Resolve the first, and continue traversing the graph
            conflictHandler.resolveNextConflict(new Action<ConflictResolutionResult>() {

                public void execute(final ConflictResolutionResult result) {
                    result.getConflict().withParticipatingModules(new Action<ModuleIdentifier>() {

                        public void execute(ModuleIdentifier moduleIdentifier) {
                            ModuleVersionResolveState selected = result.getSelected();
                            // Restart each configuration. For the evicted configuration, this means moving incoming dependencies across to the
                            // matching selected configuration. For the select configuration, this mean traversing its dependencies.
                            resolveState.getModule(moduleIdentifier).restart(selected);
                        }
                    });
                }
            });
        }
    }
}
Also used : ConflictResolutionResult(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.ConflictResolutionResult) Action(org.gradle.api.Action) PotentialConflict(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.PotentialConflict) ArrayList(java.util.ArrayList) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 3 with ModuleIdentifier

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

the class ExternalResourceResolver method doListModuleVersions.

private void doListModuleVersions(DependencyMetadata dependency, BuildableModuleVersionListingResolveResult result) {
    ModuleIdentifier module = moduleIdentifierFactory.module(dependency.getRequested().getGroup(), dependency.getRequested().getName());
    Set<String> versions = new LinkedHashSet<String>();
    VersionPatternVisitor visitor = versionLister.newVisitor(module, versions, result);
    // List modules based on metadata files (artifact version is not considered in listVersionsForAllPatterns())
    IvyArtifactName metaDataArtifact = getMetaDataArtifactName(dependency.getRequested().getName());
    listVersionsForAllPatterns(ivyPatterns, metaDataArtifact, visitor);
    // List modules with missing metadata files
    for (IvyArtifactName otherArtifact : getDependencyArtifactNames(dependency.getRequested().getName(), dependency.getArtifacts())) {
        listVersionsForAllPatterns(artifactPatterns, otherArtifact, visitor);
    }
    result.listed(versions);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 4 with ModuleIdentifier

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

the class ComponentModuleMetadataContainer method detectCycles.

private static void detectCycles(Map<ModuleIdentifier, ModuleIdentifier> replacements, ModuleIdentifier source, ModuleIdentifier target) {
    if (source.equals(target)) {
        throw new InvalidUserDataException(String.format("Cannot declare module replacement that replaces self: %s->%s", source, target));
    }
    ModuleIdentifier m = replacements.get(target);
    if (m == null) {
        //target does not exist in the map, there's no cycle for sure
        return;
    }
    Set<ModuleIdentifier> visited = new LinkedHashSet<ModuleIdentifier>();
    visited.add(source);
    visited.add(target);
    while (m != null) {
        if (!visited.add(m)) {
            //module was already visited, there is a cycle
            throw new InvalidUserDataException(format("Cannot declare module replacement %s->%s because it introduces a cycle: %s", source, target, Joiner.on("->").join(visited) + "->" + source));
        }
        m = replacements.get(m);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 5 with ModuleIdentifier

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

the class NodeState method isExcluded.

private boolean isExcluded(ModuleExclusion selector, DependencyState dependencyState) {
    DependencyMetadata dependency = dependencyState.getDependency();
    if (!resolveState.getEdgeFilter().isSatisfiedBy(dependency)) {
        LOGGER.debug("{} is filtered.", dependency);
        return true;
    }
    if (selector == ModuleExclusions.excludeNone()) {
        return false;
    }
    ModuleIdentifier targetModuleId = dependencyState.getModuleIdentifier();
    if (selector.excludeModule(targetModuleId)) {
        LOGGER.debug("{} is excluded from {}.", targetModuleId, this);
        return true;
    }
    return false;
}
Also used : DependencyMetadata(org.gradle.internal.component.model.DependencyMetadata) LocalFileDependencyMetadata(org.gradle.internal.component.local.model.LocalFileDependencyMetadata) 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