Search in sources :

Example 1 with ResolvedArtifactResult

use of org.gradle.api.artifacts.result.ResolvedArtifactResult in project gradle by gradle.

the class IdeDependenciesExtractor method downloadAuxiliaryArtifacts.

private static void downloadAuxiliaryArtifacts(DependencyHandler dependencyHandler, Multimap<ComponentIdentifier, IdeExtendedRepoFileDependency> dependencies, List<Class<? extends Artifact>> artifactTypes) {
    if (artifactTypes.isEmpty()) {
        return;
    }
    ArtifactResolutionQuery query = dependencyHandler.createArtifactResolutionQuery();
    query.forComponents(dependencies.keySet());
    @SuppressWarnings("unchecked") Class<? extends Artifact>[] artifactTypesArray = (Class<? extends Artifact>[]) artifactTypes.toArray(new Class<?>[0]);
    query.withArtifacts(JvmLibrary.class, artifactTypesArray);
    Set<ComponentArtifactsResult> componentResults = query.execute().getResolvedComponents();
    for (ComponentArtifactsResult componentResult : componentResults) {
        for (IdeExtendedRepoFileDependency dependency : dependencies.get(componentResult.getId())) {
            for (ArtifactResult sourcesResult : componentResult.getArtifacts(SourcesArtifact.class)) {
                if (sourcesResult instanceof ResolvedArtifactResult) {
                    dependency.addSourceFile(((ResolvedArtifactResult) sourcesResult).getFile());
                }
            }
            for (ArtifactResult javadocResult : componentResult.getArtifacts(JavadocArtifact.class)) {
                if (javadocResult instanceof ResolvedArtifactResult) {
                    dependency.addJavadocFile(((ResolvedArtifactResult) javadocResult).getFile());
                }
            }
        }
    }
}
Also used : ComponentArtifactsResult(org.gradle.api.artifacts.result.ComponentArtifactsResult) IdeExtendedRepoFileDependency(org.gradle.plugins.ide.internal.resolver.model.IdeExtendedRepoFileDependency) ArtifactResolutionQuery(org.gradle.api.artifacts.query.ArtifactResolutionQuery) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult) JavadocArtifact(org.gradle.language.java.artifact.JavadocArtifact) SourcesArtifact(org.gradle.language.base.artifact.SourcesArtifact) Artifact(org.gradle.api.component.Artifact) ArtifactResult(org.gradle.api.artifacts.result.ArtifactResult) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult)

Example 2 with ResolvedArtifactResult

use of org.gradle.api.artifacts.result.ResolvedArtifactResult in project gradle by gradle.

the class DefaultLenientConfiguration method select.

@Override
public SelectedArtifactSet select(final Spec<? super Dependency> dependencySpec, final AttributeContainerInternal requestedAttributes, final Spec<? super ComponentIdentifier> componentSpec) {
    final SelectedArtifactResults artifactResults;
    final SelectedFileDependencyResults fileDependencyResults;
    VariantSelector selector = artifactTransforms.variantSelector(requestedAttributes);
    artifactResults = this.artifactResults.select(componentSpec, selector);
    fileDependencyResults = this.fileDependencyResults.select(componentSpec, selector);
    return new SelectedArtifactSet() {

        @Override
        public <T extends Collection<Object>> T collectBuildDependencies(T dest) {
            artifactResults.getArtifacts().collectBuildDependencies(dest);
            fileDependencyResults.getArtifacts().collectBuildDependencies(dest);
            return dest;
        }

        @Override
        public void visitArtifacts(ArtifactVisitor visitor) {
            DefaultLenientConfiguration.this.visitArtifacts(dependencySpec, artifactResults, fileDependencyResults, visitor);
        }

        /**
             * Collects files reachable from first level dependencies that satisfy the given spec. Fails when any file cannot be resolved
             */
        @Override
        public <T extends Collection<? super File>> T collectFiles(T dest) throws ResolveException {
            rethrowFailure();
            ResolvedFilesCollectingVisitor visitor = new ResolvedFilesCollectingVisitor(dest);
            try {
                DefaultLenientConfiguration.this.visitArtifacts(dependencySpec, artifactResults, fileDependencyResults, visitor);
                // The visitor adds file dependencies directly to the destination collection however defers adding the artifacts.
                // This is to ensure a fixed order regardless of whether the first level dependencies are filtered or not
                // File dependencies and artifacts are currently treated separately as a migration step
                visitor.addArtifacts();
            } catch (Throwable t) {
                visitor.failures.add(t);
            }
            if (!visitor.failures.isEmpty()) {
                throw new ArtifactResolveException("files", configuration.getPath(), configuration.getDisplayName(), visitor.failures);
            }
            return dest;
        }

        /**
             * Collects all resolved artifacts. Fails when any artifact cannot be resolved.
             */
        @Override
        public <T extends Collection<? super ResolvedArtifactResult>> T collectArtifacts(T dest) throws ResolveException {
            rethrowFailure();
            ResolvedArtifactCollectingVisitor visitor = new ResolvedArtifactCollectingVisitor(dest);
            try {
                DefaultLenientConfiguration.this.visitArtifacts(dependencySpec, artifactResults, fileDependencyResults, visitor);
            } catch (Throwable t) {
                visitor.failures.add(t);
            }
            if (!visitor.failures.isEmpty()) {
                throw new ArtifactResolveException("artifacts", configuration.getPath(), configuration.getDisplayName(), visitor.failures);
            }
            return dest;
        }
    };
}
Also used : SelectedFileDependencyResults(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedFileDependencyResults) SelectedArtifactResults(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedArtifactResults) VariantSelector(org.gradle.api.internal.artifacts.transform.VariantSelector) SelectedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedArtifactSet) ArtifactVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ArtifactVisitor) Collection(java.util.Collection) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult) DefaultResolvedArtifactResult(org.gradle.api.internal.artifacts.result.DefaultResolvedArtifactResult) File(java.io.File)

Aggregations

ResolvedArtifactResult (org.gradle.api.artifacts.result.ResolvedArtifactResult)2 File (java.io.File)1 Collection (java.util.Collection)1 ArtifactResolutionQuery (org.gradle.api.artifacts.query.ArtifactResolutionQuery)1 ArtifactResult (org.gradle.api.artifacts.result.ArtifactResult)1 ComponentArtifactsResult (org.gradle.api.artifacts.result.ComponentArtifactsResult)1 Artifact (org.gradle.api.component.Artifact)1 ArtifactVisitor (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ArtifactVisitor)1 SelectedArtifactResults (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedArtifactResults)1 SelectedArtifactSet (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedArtifactSet)1 SelectedFileDependencyResults (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedFileDependencyResults)1 DefaultResolvedArtifactResult (org.gradle.api.internal.artifacts.result.DefaultResolvedArtifactResult)1 VariantSelector (org.gradle.api.internal.artifacts.transform.VariantSelector)1 SourcesArtifact (org.gradle.language.base.artifact.SourcesArtifact)1 JavadocArtifact (org.gradle.language.java.artifact.JavadocArtifact)1 IdeExtendedRepoFileDependency (org.gradle.plugins.ide.internal.resolver.model.IdeExtendedRepoFileDependency)1