Search in sources :

Example 1 with ComponentArtifactMetadata

use of org.gradle.internal.component.model.ComponentArtifactMetadata in project gradle by gradle.

the class ProjectDependencyBuilder method determineTargetProjectPath.

private String determineTargetProjectPath(IdeProjectDependency dependency) {
    ComponentArtifactMetadata eclipseProjectArtifact = ideProjectResolver.findArtifact(dependency.getProjectId(), "eclipse.project");
    String targetProjectName = eclipseProjectArtifact == null ? dependency.getProjectName() : eclipseProjectArtifact.getName().getName();
    return "/" + targetProjectName;
}
Also used : ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata)

Example 2 with ComponentArtifactMetadata

use of org.gradle.internal.component.model.ComponentArtifactMetadata in project gradle by gradle.

the class DefaultArtifactSet method snapshot.

@Override
public ArtifactSet snapshot() {
    ImmutableSet.Builder<ResolvedVariant> result = ImmutableSet.builder();
    for (VariantMetadata variant : variants) {
        Set<? extends ComponentArtifactMetadata> artifacts = variant.getArtifacts();
        Set<ResolvedArtifact> resolvedArtifacts = new LinkedHashSet<ResolvedArtifact>(artifacts.size());
        // Add artifact format as an implicit attribute when all artifacts have the same format
        AttributeContainerInternal attributes = variant.getAttributes();
        if (!attributes.contains(ArtifactAttributes.ARTIFACT_FORMAT)) {
            String format = null;
            for (ComponentArtifactMetadata artifact : artifacts) {
                String candidateFormat = artifact.getName().getType();
                if (format == null) {
                    format = candidateFormat;
                } else if (!format.equals(candidateFormat)) {
                    format = null;
                    break;
                }
            }
            if (format != null) {
                attributes = attributesFactory.concat(attributes.asImmutable(), ArtifactAttributes.ARTIFACT_FORMAT, format);
            }
        }
        for (ComponentArtifactMetadata artifact : artifacts) {
            IvyArtifactName artifactName = artifact.getName();
            if (exclusions.excludeArtifact(moduleVersionIdentifier.getModule(), artifactName)) {
                continue;
            }
            ResolvedArtifact resolvedArtifact = allResolvedArtifacts.get(artifact.getId());
            if (resolvedArtifact == null) {
                Factory<File> artifactSource = new BuildOperationArtifactSource(buildOperationExecutor, artifact.getId(), new LazyArtifactSource(artifact, moduleSource, artifactResolver));
                resolvedArtifact = new DefaultResolvedArtifact(moduleVersionIdentifier, artifactName, artifact.getId(), artifact.getBuildDependencies(), artifactSource);
                allResolvedArtifacts.put(artifact.getId(), resolvedArtifact);
            }
            resolvedArtifacts.add(resolvedArtifact);
        }
        result.add(ArtifactBackedResolvedVariant.create(attributes, resolvedArtifacts));
    }
    return new ArtifactSetSnapshot(id, componentIdentifier, result.build());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VariantMetadata(org.gradle.internal.component.model.VariantMetadata) DefaultResolvedArtifact(org.gradle.api.internal.artifacts.DefaultResolvedArtifact) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) ImmutableSet(com.google.common.collect.ImmutableSet) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) DefaultResolvedArtifact(org.gradle.api.internal.artifacts.DefaultResolvedArtifact) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) File(java.io.File)

Example 3 with ComponentArtifactMetadata

use of org.gradle.internal.component.model.ComponentArtifactMetadata in project gradle by gradle.

the class DefaultArtifactSet method toResolvedVariant.

private static ResolvedVariant toResolvedVariant(VariantResolveMetadata variant, ModuleVersionIdentifier ownerId, ModuleSource moduleSource, ModuleExclusion exclusions, ArtifactResolver artifactResolver, Map<ComponentArtifactIdentifier, ResolvableArtifact> allResolvedArtifacts, ArtifactTypeRegistry artifactTypeRegistry) {
    List<? extends ComponentArtifactMetadata> artifacts = variant.getArtifacts();
    ImmutableSet.Builder<ResolvableArtifact> resolvedArtifacts = ImmutableSet.builder();
    // Apply any artifact type mappings to the attributes of the variant
    ImmutableAttributes attributes = artifactTypeRegistry.mapAttributesFor(variant);
    for (ComponentArtifactMetadata artifact : artifacts) {
        IvyArtifactName artifactName = artifact.getName();
        if (exclusions.excludeArtifact(ownerId.getModule(), artifactName)) {
            continue;
        }
        ResolvableArtifact resolvedArtifact = allResolvedArtifacts.get(artifact.getId());
        if (resolvedArtifact == null) {
            Factory<File> artifactSource = new LazyArtifactSource(artifact, moduleSource, artifactResolver);
            resolvedArtifact = new DefaultResolvedArtifact(ownerId, artifactName, artifact.getId(), artifact.getBuildDependencies(), artifactSource);
            allResolvedArtifacts.put(artifact.getId(), resolvedArtifact);
        }
        resolvedArtifacts.add(resolvedArtifact);
    }
    return ArtifactBackedResolvedVariant.create(variant.asDescribable(), attributes, resolvedArtifacts.build());
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ImmutableSet(com.google.common.collect.ImmutableSet) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) DefaultResolvedArtifact(org.gradle.api.internal.artifacts.DefaultResolvedArtifact) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) File(java.io.File)

Example 4 with ComponentArtifactMetadata

use of org.gradle.internal.component.model.ComponentArtifactMetadata in project gradle by gradle.

the class DefaultArtifactResolutionQuery method addArtifacts.

private <T extends Artifact> void addArtifacts(DefaultComponentArtifactsResult artifacts, Class<T> type, ComponentResolveMetadata component, ArtifactResolver artifactResolver) {
    BuildableArtifactSetResolveResult artifactSetResolveResult = new DefaultBuildableArtifactSetResolveResult();
    artifactResolver.resolveArtifactsWithType(component, convertType(type), artifactSetResolveResult);
    for (ComponentArtifactMetadata artifactMetaData : artifactSetResolveResult.getResult()) {
        BuildableArtifactResolveResult resolveResult = new DefaultBuildableArtifactResolveResult();
        artifactResolver.resolveArtifact(artifactMetaData, component.getSources(), resolveResult);
        if (resolveResult.getFailure() != null) {
            artifacts.addArtifact(new DefaultUnresolvedArtifactResult(artifactMetaData.getId(), type, resolveResult.getFailure()));
        } else {
            artifacts.addArtifact(ivyFactory.verifiedArtifact(new DefaultResolvedArtifactResult(artifactMetaData.getId(), ImmutableAttributes.EMPTY, Collections.emptyList(), Describables.of(component.getId().getDisplayName()), type, resolveResult.getResult())));
        }
    }
}
Also used : ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) DefaultUnresolvedArtifactResult(org.gradle.api.internal.artifacts.result.DefaultUnresolvedArtifactResult) BuildableArtifactSetResolveResult(org.gradle.internal.resolve.result.BuildableArtifactSetResolveResult) DefaultBuildableArtifactSetResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactSetResolveResult) DefaultBuildableArtifactSetResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactSetResolveResult) BuildableArtifactResolveResult(org.gradle.internal.resolve.result.BuildableArtifactResolveResult) DefaultBuildableArtifactResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult) DefaultBuildableArtifactResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult) DefaultResolvedArtifactResult(org.gradle.api.internal.artifacts.result.DefaultResolvedArtifactResult)

Example 5 with ComponentArtifactMetadata

use of org.gradle.internal.component.model.ComponentArtifactMetadata 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)

Aggregations

ComponentArtifactMetadata (org.gradle.internal.component.model.ComponentArtifactMetadata)9 File (java.io.File)4 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Map (java.util.Map)3 DefaultBuildableArtifactResolveResult (org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult)3 ImmutableList (com.google.common.collect.ImmutableList)2 HashMap (java.util.HashMap)2 ComponentArtifactIdentifier (org.gradle.api.artifacts.component.ComponentArtifactIdentifier)2 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)2 DefaultResolvedArtifact (org.gradle.api.internal.artifacts.DefaultResolvedArtifact)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 DefaultVariantMetadata (org.gradle.internal.component.model.DefaultVariantMetadata)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1