Search in sources :

Example 1 with ArtifactResolver

use of org.gradle.internal.resolve.resolver.ArtifactResolver in project gradle by gradle.

the class DefaultArtifactResolutionQuery method execute.

public ArtifactResolutionResult execute() {
    if (componentType == null) {
        throw new IllegalStateException("Must specify component type and artifacts to query.");
    }
    List<ResolutionAwareRepository> repositories = CollectionUtils.collect(repositoryHandler, Transformers.cast(ResolutionAwareRepository.class));
    ResolutionStrategyInternal resolutionStrategy = configurationContainer.detachedConfiguration().getResolutionStrategy();
    final ComponentResolvers componentResolvers = ivyFactory.create(resolutionStrategy, repositories, metadataHandler.getComponentMetadataProcessor());
    final ComponentMetaDataResolver componentMetaDataResolver = componentResolvers.getComponentResolver();
    final ArtifactResolver artifactResolver = new ErrorHandlingArtifactResolver(componentResolvers.getArtifactResolver());
    return lockingManager.useCache(new Factory<ArtifactResolutionResult>() {

        public ArtifactResolutionResult create() {
            Set<ComponentResult> componentResults = Sets.newHashSet();
            for (ComponentIdentifier componentId : componentIds) {
                try {
                    ComponentIdentifier validId = validateComponentIdentifier(componentId);
                    componentResults.add(buildComponentResult(validId, componentMetaDataResolver, artifactResolver));
                } catch (Throwable t) {
                    componentResults.add(new DefaultUnresolvedComponentResult(componentId, t));
                }
            }
            return new DefaultArtifactResolutionResult(componentResults);
        }

        private ComponentIdentifier validateComponentIdentifier(ComponentIdentifier componentId) {
            if (componentId instanceof ModuleComponentIdentifier) {
                return componentId;
            }
            if (componentId instanceof ProjectComponentIdentifier) {
                throw new IllegalArgumentException(String.format("Cannot query artifacts for a project component (%s).", componentId.getDisplayName()));
            }
            throw new IllegalArgumentException(String.format("Cannot resolve the artifacts for component %s with unsupported type %s.", componentId.getDisplayName(), componentId.getClass().getName()));
        }
    });
}
Also used : ComponentMetaDataResolver(org.gradle.internal.resolve.resolver.ComponentMetaDataResolver) Set(java.util.Set) ResolutionAwareRepository(org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository) ErrorHandlingArtifactResolver(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingArtifactResolver) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ArtifactResolver(org.gradle.internal.resolve.resolver.ArtifactResolver) ErrorHandlingArtifactResolver(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingArtifactResolver) DefaultArtifactResolutionResult(org.gradle.api.internal.artifacts.result.DefaultArtifactResolutionResult) DefaultArtifactResolutionResult(org.gradle.api.internal.artifacts.result.DefaultArtifactResolutionResult) ArtifactResolutionResult(org.gradle.api.artifacts.result.ArtifactResolutionResult) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ComponentResolvers(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ComponentResolvers) ResolutionStrategyInternal(org.gradle.api.internal.artifacts.configurations.ResolutionStrategyInternal) DefaultUnresolvedComponentResult(org.gradle.api.internal.artifacts.result.DefaultUnresolvedComponentResult) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 2 with ArtifactResolver

use of org.gradle.internal.resolve.resolver.ArtifactResolver in project gradle by gradle.

the class DefaultArtifactDependencyResolver method resolve.

@Override
public void resolve(ResolveContext resolveContext, List<? extends ResolutionAwareRepository> repositories, GlobalDependencyResolutionRules metadataHandler, Spec<? super DependencyMetadata> edgeFilter, DependencyGraphVisitor graphVisitor, DependencyArtifactsVisitor artifactsVisitor, AttributesSchema attributesSchema, ImmutableModuleIdentifierFactory moduleIdentifierFactory, ModuleExclusions moduleExclusions) {
    LOGGER.debug("Resolving {}", resolveContext);
    ComponentResolvers resolvers = createResolvers(resolveContext, repositories, metadataHandler);
    DependencyGraphBuilder builder = createDependencyGraphBuilder(resolvers, resolveContext.getResolutionStrategy(), metadataHandler, edgeFilter, attributesSchema, moduleIdentifierFactory, moduleExclusions);
    ArtifactResolver artifactResolver = new ErrorHandlingArtifactResolver(new CacheLockingArtifactResolver(cacheLockingManager, resolvers.getArtifactResolver()));
    BuildOperationExecutor buildOperationExecutor = serviceRegistry.get(BuildOperationExecutor.class);
    DependencyGraphVisitor artifactsGraphVisitor = new ResolvedArtifactsGraphVisitor(artifactsVisitor, artifactResolver, attributesFactory, buildOperationExecutor, moduleExclusions);
    // Resolve the dependency graph
    builder.resolve(resolveContext, new CompositeDependencyGraphVisitor(graphVisitor, artifactsGraphVisitor));
}
Also used : DependencyGraphVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphVisitor) CompositeDependencyGraphVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.CompositeDependencyGraphVisitor) DependencyGraphBuilder(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder) ResolvedArtifactsGraphVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactsGraphVisitor) CacheLockingArtifactResolver(org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactResolver) CompositeDependencyGraphVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.CompositeDependencyGraphVisitor) ErrorHandlingArtifactResolver(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingArtifactResolver) ComponentResolvers(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ComponentResolvers) CacheLockingArtifactResolver(org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactResolver) ArtifactResolver(org.gradle.internal.resolve.resolver.ArtifactResolver) ErrorHandlingArtifactResolver(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingArtifactResolver) BuildOperationExecutor(org.gradle.internal.progress.BuildOperationExecutor)

Aggregations

ComponentResolvers (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ComponentResolvers)2 ErrorHandlingArtifactResolver (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingArtifactResolver)2 ArtifactResolver (org.gradle.internal.resolve.resolver.ArtifactResolver)2 Set (java.util.Set)1 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)1 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1 ArtifactResolutionResult (org.gradle.api.artifacts.result.ArtifactResolutionResult)1 ResolutionStrategyInternal (org.gradle.api.internal.artifacts.configurations.ResolutionStrategyInternal)1 CacheLockingArtifactResolver (org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactResolver)1 ResolvedArtifactsGraphVisitor (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactsGraphVisitor)1 CompositeDependencyGraphVisitor (org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.CompositeDependencyGraphVisitor)1 DependencyGraphBuilder (org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder)1 DependencyGraphVisitor (org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphVisitor)1 ResolutionAwareRepository (org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository)1 DefaultArtifactResolutionResult (org.gradle.api.internal.artifacts.result.DefaultArtifactResolutionResult)1 DefaultUnresolvedComponentResult (org.gradle.api.internal.artifacts.result.DefaultUnresolvedComponentResult)1 BuildOperationExecutor (org.gradle.internal.progress.BuildOperationExecutor)1 ComponentMetaDataResolver (org.gradle.internal.resolve.resolver.ComponentMetaDataResolver)1