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());
}
}
}
}
}
Aggregations