Search in sources :

Example 1 with ExcludeSpec

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec in project gradle by gradle.

the class PotentialEdge method of.

static PotentialEdge of(ResolveState resolveState, NodeState from, ModuleComponentIdentifier toComponent, ModuleComponentSelector toSelector, ComponentIdentifier owner, boolean force, boolean transitive) {
    DependencyState dependencyState = new DependencyState(new LenientPlatformDependencyMetadata(resolveState, from, toSelector, toComponent, owner, force || hasStrongOpinion(from), transitive), resolveState.getComponentSelectorConverter());
    dependencyState = NodeState.maybeSubstitute(dependencyState, resolveState.getDependencySubstitutionApplicator());
    ExcludeSpec exclusions = from.previousTraversalExclusions;
    if (exclusions == null) {
        exclusions = resolveState.getModuleExclusions().nothing();
    }
    EdgeState edge = new EdgeState(from, dependencyState, exclusions, resolveState);
    edge.computeSelector();
    ModuleVersionIdentifier toModuleVersionId = DefaultModuleVersionIdentifier.newId(toSelector.getModuleIdentifier(), toSelector.getVersion());
    ComponentState version = resolveState.getModule(toSelector.getModuleIdentifier()).getVersion(toModuleVersionId, toComponent);
    // We need to check if the target version exists. For this, we have to try to get metadata for the aligned version.
    // If it's there, it means we can align, otherwise, we must NOT add the edge, or resolution would fail
    ComponentResolveMetadata metadata = version.getMetadata();
    return new PotentialEdge(edge, toModuleVersionId, metadata, version);
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)

Example 2 with ExcludeSpec

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec in project gradle by gradle.

the class EdgeState method computeExclusionsWhenExcludesPresent.

private void computeExclusionsWhenExcludesPresent(List<ExcludeMetadata> excludes) {
    ModuleExclusions moduleExclusions = resolveState.getModuleExclusions();
    ExcludeSpec edgeExclusions = moduleExclusions.excludeAny(excludes);
    cachedExclusions = moduleExclusions.excludeAny(edgeExclusions, transitiveExclusions);
}
Also used : ModuleExclusions(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.ModuleExclusions) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)

Example 3 with ExcludeSpec

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec in project gradle by gradle.

the class DefaultArtifactSet method toResolvedVariant.

public static ResolvedVariant toResolvedVariant(VariantResolveMetadata variant, ModuleVersionIdentifier ownerId, ModuleSources moduleSources, ExcludeSpec exclusions, ArtifactResolver artifactResolver, Map<ComponentArtifactIdentifier, ResolvableArtifact> allResolvedArtifacts, ImmutableAttributes variantAttributes, CalculatedValueContainerFactory calculatedValueContainerFactory) {
    List<? extends ComponentArtifactMetadata> artifacts = variant.getArtifacts();
    ImmutableSet.Builder<ResolvableArtifact> resolvedArtifacts = ImmutableSet.builder();
    boolean hasExcludedArtifact = false;
    for (ComponentArtifactMetadata artifact : artifacts) {
        IvyArtifactName artifactName = artifact.getName();
        if (exclusions.excludesArtifact(ownerId.getModule(), artifactName)) {
            hasExcludedArtifact = true;
            continue;
        }
        ResolvableArtifact resolvedArtifact = allResolvedArtifacts.get(artifact.getId());
        if (resolvedArtifact == null) {
            if (artifact.isOptionalArtifact()) {
                DefaultBuildableArtifactResolveResult result = new DefaultBuildableArtifactResolveResult();
                artifactResolver.resolveArtifact(artifact, moduleSources, result);
                if (!result.isSuccessful()) {
                    // Optional artifact is not available
                    continue;
                }
            }
            ValueCalculator<File> artifactCalculator;
            if (artifactResolver instanceof ProjectArtifactResolver) {
                artifactCalculator = ((ProjectArtifactResolver) artifactResolver).resolveArtifactLater(artifact);
            } else {
                // TODO - push this up to all ArtifactResolver implementations
                artifactCalculator = new LazyArtifactSupplier(artifact, moduleSources, artifactResolver);
            }
            CalculatedValue<File> artifactSource = calculatedValueContainerFactory.create(Describables.of(artifact.getId()), artifactCalculator);
            resolvedArtifact = new DefaultResolvableArtifact(ownerId, artifactName, artifact.getId(), context -> context.add(artifact.getBuildDependencies()), artifactSource, calculatedValueContainerFactory);
            allResolvedArtifacts.put(artifact.getId(), resolvedArtifact);
        }
        resolvedArtifacts.add(resolvedArtifact);
    }
    VariantResolveMetadata.Identifier identifier = variant.getIdentifier();
    if (hasExcludedArtifact) {
        // An ad hoc variant, has no identifier
        identifier = null;
    }
    return ArtifactBackedResolvedVariant.create(identifier, variant.asDescribable(), variantAttributes, withImplicitCapability(variant, ownerId), resolvedArtifacts.build());
}
Also used : ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) AttributesSchemaInternal(org.gradle.api.internal.attributes.AttributesSchemaInternal) DefaultResolvableArtifact(org.gradle.api.internal.artifacts.DefaultResolvableArtifact) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) ModuleSources(org.gradle.internal.component.model.ModuleSources) ExtraExecutionGraphDependenciesResolverFactory(org.gradle.api.internal.artifacts.transform.ExtraExecutionGraphDependenciesResolverFactory) ComponentConfigurationIdentifier(org.gradle.internal.component.model.ComponentConfigurationIdentifier) ValueCalculator(org.gradle.internal.model.ValueCalculator) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) VariantResolveMetadata(org.gradle.internal.component.model.VariantResolveMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ArtifactResolver(org.gradle.internal.resolve.resolver.ArtifactResolver) Describables(org.gradle.internal.Describables) ImmutableList(com.google.common.collect.ImmutableList) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) NodeExecutionContext(org.gradle.api.internal.tasks.NodeExecutionContext) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ImmutableCapabilities(org.gradle.internal.component.external.model.ImmutableCapabilities) Map(java.util.Map) Describable(org.gradle.api.Describable) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Nullable(javax.annotation.Nullable) CapabilitiesMetadata(org.gradle.api.capabilities.CapabilitiesMetadata) TransformedVariantFactory(org.gradle.api.internal.artifacts.transform.TransformedVariantFactory) VariantDefinition(org.gradle.api.internal.artifacts.transform.VariantDefinition) ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) CalculatedValue(org.gradle.internal.model.CalculatedValue) ImmutableSet(com.google.common.collect.ImmutableSet) TaskDependencyResolveContext(org.gradle.api.internal.tasks.TaskDependencyResolveContext) ArtifactTypeRegistry(org.gradle.api.internal.artifacts.type.ArtifactTypeRegistry) Collection(java.util.Collection) VariantSelector(org.gradle.api.internal.artifacts.transform.VariantSelector) Set(java.util.Set) ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec) File(java.io.File) DefaultBuildableArtifactResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult) List(java.util.List) CalculatedValueContainerFactory(org.gradle.internal.model.CalculatedValueContainerFactory) Spec(org.gradle.api.specs.Spec) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) ProjectArtifactResolver(org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectArtifactResolver) DefaultVariantMetadata(org.gradle.internal.component.model.DefaultVariantMetadata) ProjectArtifactResolver(org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectArtifactResolver) VariantResolveMetadata(org.gradle.internal.component.model.VariantResolveMetadata) DefaultBuildableArtifactResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult) DefaultResolvableArtifact(org.gradle.api.internal.artifacts.DefaultResolvableArtifact) ImmutableSet(com.google.common.collect.ImmutableSet) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) DefaultResolvableArtifact(org.gradle.api.internal.artifacts.DefaultResolvableArtifact) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) File(java.io.File)

Example 4 with ExcludeSpec

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec in project gradle by gradle.

the class ResolvedArtifactsGraphVisitor method getArtifacts.

private ArtifactsForNode getArtifacts(DependencyGraphEdge dependency, DependencyGraphNode toConfiguration) {
    ConfigurationMetadata targetConfiguration = toConfiguration.getMetadata();
    ComponentResolveMetadata component = toConfiguration.getOwner().getMetadata();
    ImmutableAttributes overriddenAttributes = dependency.getAttributes();
    List<? extends ComponentArtifactMetadata> artifacts = dependency.getArtifacts(targetConfiguration);
    if (!artifacts.isEmpty()) {
        int id = nextId++;
        ArtifactSet artifactSet = artifactSelector.resolveArtifacts(component, artifacts, overriddenAttributes);
        return new ArtifactsForNode(id, artifactSet);
    }
    ArtifactsForNode configurationArtifactSet = artifactsByNodeId.get(toConfiguration.getNodeId());
    if (configurationArtifactSet == null) {
        ExcludeSpec exclusions = dependency.getExclusions();
        ArtifactSet nodeArtifacts = artifactSelector.resolveArtifacts(component, targetConfiguration, exclusions, overriddenAttributes);
        int id = nextId++;
        configurationArtifactSet = new ArtifactsForNode(id, nodeArtifacts);
        // Only share an ArtifactSet if the artifacts are not filtered by the dependency
        if (!exclusions.mayExcludeArtifacts()) {
            artifactsByNodeId.put(toConfiguration.getNodeId(), configurationArtifactSet);
        }
    }
    return configurationArtifactSet;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)

Example 5 with ExcludeSpec

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec in project gradle by gradle.

the class NormalizingExcludeFactory method doIntersect.

private ExcludeSpec doIntersect(Set<ExcludeSpec> specs) {
    specs = simplifySet(ExcludeAnyOf.class, specs);
    FlattenOperationResult flattened = flatten(ExcludeAllOf.class, specs, ExcludeNothing.class::isInstance, ExcludeEverything.class::isInstance);
    if (flattened.fastExit) {
        return nothing();
    }
    Set<ExcludeSpec> result = flattened.result;
    if (result.isEmpty()) {
        return everything();
    }
    if (result.size() > 1) {
        // try simplify
        ExcludeSpec[] asArray = result.toArray(new ExcludeSpec[0]);
        boolean simplified = false;
        for (int i = 0; i < asArray.length; i++) {
            ExcludeSpec left = asArray[i];
            if (left != null) {
                for (int j = 0; j < asArray.length; j++) {
                    ExcludeSpec right = asArray[j];
                    if (right != null && i != j) {
                        ExcludeSpec merged = intersections.tryIntersect(left, right);
                        if (merged != null) {
                            if (merged instanceof ExcludeNothing) {
                                return merged;
                            }
                            left = merged;
                            asArray[i] = merged;
                            asArray[j] = null;
                            simplified = true;
                        }
                    }
                }
            }
        }
        if (simplified) {
            result = Arrays.stream(asArray).filter(Objects::nonNull).collect(toSet());
        }
    }
    return Optimizations.optimizeCollection(this, result, delegate::allOf);
}
Also used : ExcludeNothing(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeNothing) Objects(java.util.Objects) ExcludeEverything(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeEverything) ExcludeAnyOf(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeAnyOf) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)

Aggregations

ExcludeSpec (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)16 Set (java.util.Set)5 GroupExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupExclude)5 GroupSetExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupSetExclude)5 ModuleExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleExclude)5 ModuleIdExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdExclude)5 ModuleIdSetExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdSetExclude)5 ModuleSetExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleSetExclude)5 Collectors (java.util.stream.Collectors)4 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)4 Objects (java.util.Objects)3 ExcludeAnyOf (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeAnyOf)3 ExcludeNothing (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeNothing)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 List (java.util.List)2 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)2 ExcludeEverything (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeEverything)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)2