Search in sources :

Example 1 with Artifact

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

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);
    }
}
Also used : File(java.io.File) Artifact(org.gradle.api.component.Artifact) ResolvableArtifact(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvableArtifact) DefaultResolvedArtifactResult(org.gradle.api.internal.artifacts.result.DefaultResolvedArtifactResult)

Example 3 with Artifact

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;
}
Also used : IdeExtendedRepoFileDependency(org.gradle.plugins.ide.internal.resolver.model.IdeExtendedRepoFileDependency) UnresolvedIdeRepoFileDependency(org.gradle.plugins.ide.internal.resolver.model.UnresolvedIdeRepoFileDependency) ArrayList(java.util.ArrayList) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) JavadocArtifact(org.gradle.language.java.artifact.JavadocArtifact) SourcesArtifact(org.gradle.language.base.artifact.SourcesArtifact) Artifact(org.gradle.api.component.Artifact)

Example 4 with Artifact

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)));
    }
}
Also used : ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) AtlasPlugin(com.taobao.android.builder.AtlasPlugin) AtlasAndroidArtifacts(com.android.build.gradle.internal.publishing.AtlasAndroidArtifacts) CreatingCache(com.android.ide.common.caching.CreatingCache) Matcher(java.util.regex.Matcher) FileUtils(com.android.utils.FileUtils) ResolvedVariantResult(org.gradle.api.artifacts.result.ResolvedVariantResult) com.google.common.collect(com.google.common.collect) MavenCoordinatesImpl(com.android.builder.dependency.MavenCoordinatesImpl) Artifact(org.gradle.api.component.Artifact) GraphItem(com.android.builder.model.level2.GraphItem) Project(org.gradle.api.Project) Nullable(com.android.annotations.Nullable) AndroidArtifacts(com.android.build.gradle.internal.publishing.AndroidArtifacts) BooleanOption(com.android.build.gradle.options.BooleanOption) ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) ArtifactCollection(org.gradle.api.artifacts.ArtifactCollection) FilteredArtifactCollection(com.android.build.gradle.internal.dependency.FilteredArtifactCollection) Spec(org.gradle.api.specs.Spec) NonNull(com.android.annotations.NonNull) VariantType(com.android.builder.core.VariantType) ARTIFACT_TYPE(com.android.build.gradle.internal.publishing.AndroidArtifacts.ARTIFACT_TYPE) com.android.build.gradle.internal.ide.level2(com.android.build.gradle.internal.ide.level2) Pattern(java.util.regex.Pattern) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult) EMPTY_DEPENDENCY_GRAPH(com.android.build.gradle.internal.ide.ModelBuilder.EMPTY_DEPENDENCY_GRAPH) JvmLibrary(org.gradle.jvm.JvmLibrary) java.util(java.util) SdkConstants(com.android.SdkConstants) OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) VariantAttr(com.android.build.gradle.internal.dependency.VariantAttr) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ConfigurationDependencyGraphs(com.android.build.gradle.internal.dependency.ConfigurationDependencyGraphs) VariantScope(com.android.build.gradle.internal.scope.VariantScope) EMPTY_DEPENDENCIES_IMPL(com.android.build.gradle.internal.ide.ModelBuilder.EMPTY_DEPENDENCIES_IMPL) Configuration(org.gradle.api.artifacts.Configuration) ImmutableCollectors(com.android.utils.ImmutableCollectors) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) AttributeContainer(org.gradle.api.attributes.AttributeContainer) com.android.builder.model(com.android.builder.model) ArtifactResolutionQuery(org.gradle.api.artifacts.query.ArtifactResolutionQuery) SourcesArtifact(org.gradle.language.base.artifact.SourcesArtifact) Action(org.gradle.api.Action) Library(com.android.builder.model.level2.Library) File(java.io.File) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) Consumer(java.util.function.Consumer) ArtifactCollectionWithExtraArtifact(com.android.build.gradle.internal.dependency.ArtifactCollectionWithExtraArtifact) JavaLibraryImpl(com.android.build.gradle.internal.ide.level2.JavaLibraryImpl) Preconditions(com.google.common.base.Preconditions) DependencyGraphs(com.android.builder.model.level2.DependencyGraphs) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) ArtifactResolutionQuery(org.gradle.api.artifacts.query.ArtifactResolutionQuery) Artifact(org.gradle.api.component.Artifact) SourcesArtifact(org.gradle.language.base.artifact.SourcesArtifact) ArtifactCollectionWithExtraArtifact(com.android.build.gradle.internal.dependency.ArtifactCollectionWithExtraArtifact)

Aggregations

Artifact (org.gradle.api.component.Artifact)4 SourcesArtifact (org.gradle.language.base.artifact.SourcesArtifact)3 File (java.io.File)2 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)2 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)2 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 SdkConstants (com.android.SdkConstants)1 NonNull (com.android.annotations.NonNull)1 Nullable (com.android.annotations.Nullable)1 ArtifactCollectionWithExtraArtifact (com.android.build.gradle.internal.dependency.ArtifactCollectionWithExtraArtifact)1 ConfigurationDependencyGraphs (com.android.build.gradle.internal.dependency.ConfigurationDependencyGraphs)1 FilteredArtifactCollection (com.android.build.gradle.internal.dependency.FilteredArtifactCollection)1 VariantAttr (com.android.build.gradle.internal.dependency.VariantAttr)1 EMPTY_DEPENDENCIES_IMPL (com.android.build.gradle.internal.ide.ModelBuilder.EMPTY_DEPENDENCIES_IMPL)1 EMPTY_DEPENDENCY_GRAPH (com.android.build.gradle.internal.ide.ModelBuilder.EMPTY_DEPENDENCY_GRAPH)1 com.android.build.gradle.internal.ide.level2 (com.android.build.gradle.internal.ide.level2)1 JavaLibraryImpl (com.android.build.gradle.internal.ide.level2.JavaLibraryImpl)1 AndroidArtifacts (com.android.build.gradle.internal.publishing.AndroidArtifacts)1 ARTIFACT_TYPE (com.android.build.gradle.internal.publishing.AndroidArtifacts.ARTIFACT_TYPE)1 AtlasAndroidArtifacts (com.android.build.gradle.internal.publishing.AtlasAndroidArtifacts)1