Search in sources :

Example 1 with ArtifactResolutionResult

use of org.gradle.api.artifacts.result.ArtifactResolutionResult 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)

Aggregations

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 ComponentResolvers (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ComponentResolvers)1 ErrorHandlingArtifactResolver (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingArtifactResolver)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 ArtifactResolver (org.gradle.internal.resolve.resolver.ArtifactResolver)1 ComponentMetaDataResolver (org.gradle.internal.resolve.resolver.ComponentMetaDataResolver)1