Search in sources :

Example 16 with ModuleIdentifier

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

the class DefaultCapabilitiesConflictHandler method registerCandidate.

@Override
public PotentialConflict registerCandidate(CapabilitiesConflictHandler.Candidate candidate) {
    CapabilityInternal capability = (CapabilityInternal) candidate.getCapability();
    String group = capability.getGroup();
    String name = capability.getName();
    final Set<NodeState> nodes = findNodesFor(capability);
    Collection<NodeState> implicitCapabilityProviders = candidate.getImplicitCapabilityProviders();
    nodes.addAll(implicitCapabilityProviders);
    NodeState node = candidate.getNode();
    if (nodes.add(node) && nodes.size() > 1) {
        // The registered nodes may contain nodes which are no longer selected.
        // We don't remove them from the list in the first place because it proved to be
        // slower than filtering as needed.
        ModuleIdentifier rootId = null;
        final List<NodeState> candidatesForConflict = Lists.newArrayListWithCapacity(nodes.size());
        for (NodeState ns : nodes) {
            if (ns.isSelected()) {
                candidatesForConflict.add(ns);
                if (ns.isRoot()) {
                    rootId = ns.getComponent().getId().getModule();
                }
            }
        }
        if (rootId != null && candidatesForConflict.size() > 1) {
            // This is a special case for backwards compatibility: it is possible to have
            // a cycle where the root component depends on a library which transitively
            // depends on a different version of the root module. In this case, we effectively
            // allow 2 modules to have the same capability, so we filter the nodes coming
            // from transitive dependencies
            ModuleIdentifier rootModuleId = rootId;
            candidatesForConflict.removeIf(n -> !n.isRoot() && n.getComponent().getId().getModule().equals(rootModuleId));
        }
        if (candidatesForConflict.size() > 1) {
            PotentialConflict conflict = new PotentialConflict() {

                @Override
                public void withParticipatingModules(Action<ModuleIdentifier> action) {
                    for (NodeState node : candidatesForConflict) {
                        action.execute(node.getComponent().getId().getModule());
                    }
                }

                @Override
                public boolean conflictExists() {
                    return true;
                }
            };
            conflicts.add(new CapabilityConflict(group, name, candidatesForConflict));
            return conflict;
        }
    }
    return PotentialConflictFactory.noConflict();
}
Also used : Action(org.gradle.api.Action) NodeState(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.NodeState) CapabilityInternal(org.gradle.internal.component.external.model.CapabilityInternal) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 17 with ModuleIdentifier

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

the class ModuleComponentResolveMetadataSerializer method readModuleIdentifier.

private VirtualComponentIdentifier readModuleIdentifier(Decoder decoder) throws IOException {
    String group = decoder.readString();
    String module = decoder.readString();
    String version = decoder.readString();
    ModuleIdentifier moduleIdentifier = DefaultModuleIdentifier.newId(group, module);
    return new DefaultVirtualModuleComponentIdentifier(moduleIdentifier, version);
}
Also used : ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) DefaultModuleIdentifier(org.gradle.api.internal.artifacts.DefaultModuleIdentifier) DefaultVirtualModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultVirtualModuleComponentIdentifier)

Example 18 with ModuleIdentifier

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

the class PgpKeyGrouper method groupByModuleId.

private void groupByModuleId(Map.Entry<String, Collection<PgpEntry>> e, List<ModuleIdentifier> moduleIds) {
    ModuleIdentifier mi = moduleIds.get(0);
    verificationsBuilder.addTrustedKey(e.getKey(), mi.getGroup(), mi.getName(), null, null, false);
    markKeyDeclaredGlobally(e);
}
Also used : ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 19 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, Replacement> 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 = unwrap(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<>();
    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 = unwrap(replacements.get(m));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 20 with ModuleIdentifier

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

the class DependenciesAwareVersionCatalogBuilder method build.

@Override
public DefaultVersionCatalog build() {
    if (shouldAmendModel) {
        DependencySet allDependencies = dependenciesConfiguration.getAllDependencies();
        DependencyConstraintSet allDependencyConstraints = dependenciesConfiguration.getAllDependencyConstraints();
        Set<ModuleIdentifier> seen = Sets.newHashSet();
        collectDependencies(allDependencies, seen);
        collectConstraints(allDependencyConstraints, seen);
    }
    shouldAmendModel = false;
    return super.build();
}
Also used : DependencySet(org.gradle.api.artifacts.DependencySet) DependencyConstraintSet(org.gradle.api.artifacts.DependencyConstraintSet) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) DefaultModuleIdentifier(org.gradle.api.internal.artifacts.DefaultModuleIdentifier)

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