Search in sources :

Example 1 with ArtifactResolutionQuery

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

Aggregations

ArtifactResolutionQuery (org.gradle.api.artifacts.query.ArtifactResolutionQuery)1 ArtifactResult (org.gradle.api.artifacts.result.ArtifactResult)1 ComponentArtifactsResult (org.gradle.api.artifacts.result.ComponentArtifactsResult)1 ResolvedArtifactResult (org.gradle.api.artifacts.result.ResolvedArtifactResult)1 Artifact (org.gradle.api.component.Artifact)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