use of org.gradle.api.component.Artifact 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());
}
}
}
}
}
use of org.gradle.api.component.Artifact in project gradle by gradle.
the class ResolvedArtifactCollectingVisitor method visitArtifact.
@Override
public void visitArtifact(String variantName, AttributeContainer variantAttributes, ResolvableArtifact artifact) {
try {
if (seenArtifacts.add(artifact.getId())) {
// Trigger download of file, if required
File file = artifact.getFile();
this.artifacts.add(new DefaultResolvedArtifactResult(artifact.getId(), variantAttributes, variantName, Artifact.class, file));
}
} catch (Throwable t) {
failures.add(t);
}
}
use of org.gradle.api.component.Artifact in project gradle by gradle.
the class IdeDependenciesExtractor method extractRepoFileDependencies.
public Collection<IdeExtendedRepoFileDependency> extractRepoFileDependencies(DependencyHandler dependencyHandler, Collection<Configuration> plusConfigurations, Collection<Configuration> minusConfigurations, boolean downloadSources, boolean downloadJavadoc) {
// can have multiple IDE dependencies with same component identifier (see GRADLE-1622)
Multimap<ComponentIdentifier, IdeExtendedRepoFileDependency> resolvedDependenciesComponentMap = LinkedHashMultimap.create();
for (IdeExtendedRepoFileDependency dep : resolvedExternalDependencies(plusConfigurations, minusConfigurations)) {
resolvedDependenciesComponentMap.put(toComponentIdentifier(dep.getId()), dep);
}
List<Class<? extends Artifact>> artifactTypes = new ArrayList<Class<? extends Artifact>>(2);
if (downloadSources) {
artifactTypes.add(SourcesArtifact.class);
}
if (downloadJavadoc) {
artifactTypes.add(JavadocArtifact.class);
}
downloadAuxiliaryArtifacts(dependencyHandler, resolvedDependenciesComponentMap, artifactTypes);
Collection<UnresolvedIdeRepoFileDependency> unresolvedDependencies = unresolvedExternalDependencies(plusConfigurations, minusConfigurations);
Collection<IdeExtendedRepoFileDependency> resolvedDependencies = resolvedDependenciesComponentMap.values();
Collection<IdeExtendedRepoFileDependency> resolvedAndUnresolved = new ArrayList<IdeExtendedRepoFileDependency>(unresolvedDependencies.size() + resolvedDependencies.size());
resolvedAndUnresolved.addAll(resolvedDependencies);
resolvedAndUnresolved.addAll(unresolvedDependencies);
return resolvedAndUnresolved;
}
use of org.gradle.api.component.Artifact in project atlas by alibaba.
the class AtlasDependencyGraph method handleSources.
private static void handleSources(@NonNull Project project, @NonNull Set<ComponentIdentifier> artifacts, @NonNull Consumer<SyncIssue> failureConsumer) {
final DependencyHandler dependencies = project.getDependencies();
try {
ArtifactResolutionQuery query = dependencies.createArtifactResolutionQuery();
query.forComponents(artifacts);
@SuppressWarnings("unchecked") Class<? extends Artifact>[] artifactTypesArray = (Class<? extends Artifact>[]) new Class<?>[] { SourcesArtifact.class };
query.withArtifacts(JvmLibrary.class, artifactTypesArray);
query.execute().getResolvedComponents();
} catch (Throwable t) {
DependencyFailureHandlerKt.processDependencyThrowable(t, s -> null, (data, messages) -> failureConsumer.accept(new SyncIssueImpl(SyncIssue.TYPE_GENERIC, SyncIssue.SEVERITY_WARNING, null, String.format("Unable to download sources: %s", messages.get(0)), messages)));
}
}
Aggregations