Search in sources :

Example 21 with ModuleIdentifier

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

the class DependenciesAwareVersionCatalogBuilder method collectDependencies.

private void collectDependencies(DependencySet allDependencies, Set<ModuleIdentifier> seen) {
    for (Dependency dependency : allDependencies) {
        String group = dependency.getGroup();
        String name = dependency.getName();
        if (group != null) {
            ModuleIdentifier id = DefaultModuleIdentifier.newId(group, name);
            if (seen.add(id)) {
                String alias = explicitAliases.get(id);
                if (alias != null) {
                    library(alias, group, name).version(v -> copyDependencyVersion(dependency, group, name, v));
                } else {
                    tryGenericAlias(group, name, v -> copyDependencyVersion(dependency, group, name, v));
                }
            } else {
                LOGGER.warn("Duplicate entry for dependency " + group + ":" + name);
            }
        }
    }
}
Also used : ExternalModuleDependency(org.gradle.api.artifacts.ExternalModuleDependency) Dependency(org.gradle.api.artifacts.Dependency) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) DefaultModuleIdentifier(org.gradle.api.internal.artifacts.DefaultModuleIdentifier)

Example 22 with ModuleIdentifier

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

the class DefaultComponentSelectionRules method createSpecRuleActionFromId.

private SpecRuleAction<? super ComponentSelection> createSpecRuleActionFromId(Object id, RuleAction<? super ComponentSelection> ruleAction) {
    final ModuleIdentifier moduleIdentifier;
    try {
        moduleIdentifier = moduleIdentifierNotationParser.parseNotation(id);
    } catch (UnsupportedNotationException e) {
        throw new InvalidUserCodeException(String.format(INVALID_SPEC_ERROR, id == null ? "null" : id.toString()), e);
    }
    Spec<ComponentSelection> spec = new ComponentSelectionMatchingSpec(moduleIdentifier);
    return new SpecRuleAction<>(ruleAction, spec);
}
Also used : InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) SpecRuleAction(org.gradle.internal.rules.SpecRuleAction) UnsupportedNotationException(org.gradle.internal.typeconversion.UnsupportedNotationException) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) ComponentSelection(org.gradle.api.artifacts.ComponentSelection)

Example 23 with ModuleIdentifier

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

the class ModuleForcingResolveRule method execute.

@Override
public void execute(DependencySubstitutionInternal details) {
    if (forcedModules == null) {
        return;
    }
    if (details.getRequested() instanceof ModuleComponentSelector) {
        ModuleComponentSelector selector = (ModuleComponentSelector) details.getRequested();
        ModuleIdentifier key = selector.getModuleIdentifier();
        if (forcedModules.containsKey(key)) {
            DefaultImmutableVersionConstraint versionConstraint = new DefaultImmutableVersionConstraint(forcedModules.get(key));
            details.useTarget(newSelector(key, versionConstraint, selector.getAttributes(), selector.getRequestedCapabilities()), ComponentSelectionReasons.FORCED);
        }
    }
}
Also used : DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 24 with ModuleIdentifier

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

the class Unions method tryModuleUnion.

private ExcludeSpec tryModuleUnion(ModuleExclude left, ExcludeSpec right) {
    String leftModule = left.getModule();
    if (right instanceof ModuleIdExclude) {
        ModuleIdExclude mie = (ModuleIdExclude) right;
        if (mie.getModuleId().getName().equals(leftModule)) {
            return left;
        }
    }
    if (right instanceof ModuleIdSetExclude) {
        ModuleIdSetExclude ids = (ModuleIdSetExclude) right;
        Set<ModuleIdentifier> items = ids.getModuleIds().stream().filter(id -> !id.getName().equals(leftModule)).collect(Collectors.toSet());
        if (items.size() == 1) {
            return factory.anyOf(left, factory.moduleId(items.iterator().next()));
        }
        if (items.isEmpty()) {
            return left;
        }
        if (items.size() != ids.getModuleIds().size()) {
            return factory.anyOf(left, factory.moduleIdSet(items));
        }
    }
    return null;
}
Also used : GroupExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupExclude) ModuleSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleSetExclude) ModuleIdExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdExclude) GroupSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupSetExclude) ModuleExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleExclude) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) ModuleIdSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdSetExclude) Set(java.util.Set) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec) Collectors(java.util.stream.Collectors) ModuleIdExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdExclude) ModuleIdSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdSetExclude) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 25 with ModuleIdentifier

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

the class Unions method tryGroupSetUnion.

private ExcludeSpec tryGroupSetUnion(GroupSetExclude left, ExcludeSpec right) {
    Set<String> leftGroups = left.getGroups();
    if (right instanceof ModuleIdExclude) {
        ModuleIdExclude mie = (ModuleIdExclude) right;
        if (leftGroups.contains(mie.getModuleId().getGroup())) {
            return left;
        }
    }
    if (right instanceof ModuleIdSetExclude) {
        ModuleIdSetExclude ids = (ModuleIdSetExclude) right;
        Set<ModuleIdentifier> items = ids.getModuleIds().stream().filter(id -> !leftGroups.contains(id.getGroup())).collect(Collectors.toSet());
        if (items.size() == 1) {
            return factory.anyOf(left, factory.moduleId(items.iterator().next()));
        }
        if (items.isEmpty()) {
            return left;
        }
        if (items.size() != ids.getModuleIds().size()) {
            return factory.anyOf(left, factory.moduleIdSet(items));
        }
    }
    return null;
}
Also used : GroupExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupExclude) ModuleSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleSetExclude) ModuleIdExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdExclude) GroupSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupSetExclude) ModuleExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleExclude) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) ModuleIdSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdSetExclude) Set(java.util.Set) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec) Collectors(java.util.stream.Collectors) ModuleIdExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdExclude) ModuleIdSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdSetExclude) 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