org.gradle.api.component.Artifact Java Examples

The following examples show how to use org.gradle.api.component.Artifact. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IdeDependenciesExtractor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
}
 
Example #2
Source File: IdeDependenciesExtractor.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
}
 
Example #3
Source File: DefaultArtifactResolutionQuery.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ComponentArtifactsResult buildComponentResult(ModuleComponentIdentifier moduleComponentId, RepositoryChain repositoryChain, ArtifactResolver artifactResolver) {
    BuildableComponentResolveResult moduleResolveResult = new DefaultBuildableComponentResolveResult();
    repositoryChain.getDependencyResolver().resolve(new DefaultDependencyMetaData(moduleComponentId), moduleResolveResult);
    ComponentResolveMetaData component = moduleResolveResult.getMetaData();
    DefaultComponentArtifactsResult componentResult = new DefaultComponentArtifactsResult(component.getComponentId());
    for (Class<? extends Artifact> artifactType : artifactTypes) {
        addArtifacts(componentResult, artifactType, component, artifactResolver);
    }
    return componentResult;
}
 
Example #4
Source File: DefaultComponentTypeRegistry.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ComponentTypeRegistration registerArtifactType(Class<? extends Artifact> artifact, ArtifactType artifactType) {
    if (typeRegistrations.containsKey(artifact)) {
        throw new IllegalStateException(String.format("Artifact type %s is already registered for component type %s.", artifact.getName(), componentType.getName()));
    }
    typeRegistrations.put(artifact, artifactType);
    return this;
}
 
Example #5
Source File: DefaultComponentTypeRegistry.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArtifactType getArtifactType(Class<? extends Artifact> artifact) {
    ArtifactType type = typeRegistrations.get(artifact);
    if (type == null) {
        throw new IllegalArgumentException(String.format("Artifact type %s is not registered for component type %s.", artifact.getName(), componentType.getName()));
    }
    return type;
}
 
Example #6
Source File: IdeDependenciesExtractor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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>[]) new Class<?>[artifactTypes.size()];
    query.withArtifacts(JvmLibrary.class, artifactTypes.toArray(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.setSourceFile(((ResolvedArtifactResult) sourcesResult).getFile());
                }
            }

            for (ArtifactResult javadocResult : componentResult.getArtifacts(JavadocArtifact.class)) {
                if (javadocResult instanceof ResolvedArtifactResult) {
                    dependency.setJavadocFile(((ResolvedArtifactResult) javadocResult).getFile());
                }
            }
        }
    }
}
 
Example #7
Source File: DefaultComponentArtifactsResult.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Set<ArtifactResult> getArtifacts(Class<? extends Artifact> type) {
    Set<ArtifactResult> matching = Sets.newLinkedHashSet();
    for (ArtifactResult artifactResult : artifactResults) {
        if (type.isAssignableFrom(artifactResult.getType())) {
            matching.add(artifactResult);
        }
    }
    return matching;
}
 
Example #8
Source File: DefaultArtifactResolutionQuery.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T extends Artifact> void addArtifacts(DefaultComponentArtifactsResult artifacts, Class<T> type, ComponentResolveMetaData component, ArtifactResolver artifactResolver) {
    BuildableArtifactSetResolveResult artifactSetResolveResult = new DefaultBuildableArtifactSetResolveResult();
    artifactResolver.resolveModuleArtifacts(component, convertType(type), artifactSetResolveResult);

    for (ComponentArtifactMetaData artifactMetaData : artifactSetResolveResult.getArtifacts()) {
        BuildableArtifactResolveResult resolveResult = new DefaultBuildableArtifactResolveResult();
        artifactResolver.resolveArtifact(artifactMetaData, component.getSource(), resolveResult);
        if (resolveResult.getFailure() != null) {
            artifacts.addArtifact(new DefaultUnresolvedArtifactResult(type, resolveResult.getFailure()));
        } else {
            artifacts.addArtifact(new DefaultResolvedArtifactResult(type, resolveResult.getFile()));
        }
    }
}
 
Example #9
Source File: DefaultArtifactResolutionQuery.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ComponentArtifactsResult buildComponentResult(ModuleComponentIdentifier moduleComponentId, RepositoryChain repositoryChain, ArtifactResolver artifactResolver) {
    BuildableComponentResolveResult moduleResolveResult = new DefaultBuildableComponentResolveResult();
    repositoryChain.getDependencyResolver().resolve(new DefaultDependencyMetaData(moduleComponentId), moduleResolveResult);
    ComponentResolveMetaData component = moduleResolveResult.getMetaData();
    DefaultComponentArtifactsResult componentResult = new DefaultComponentArtifactsResult(component.getComponentId());
    for (Class<? extends Artifact> artifactType : artifactTypes) {
        addArtifacts(componentResult, artifactType, component, artifactResolver);
    }
    return componentResult;
}
 
Example #10
Source File: DefaultArtifactResolutionQuery.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArtifactResolutionQuery withArtifacts(Class<? extends Component> componentType, Class<? extends Artifact>... artifactTypes) {
    if (this.componentType != null) {
        throw new IllegalStateException("Cannot specify component type multiple times.");
    }
    this.componentType = componentType;
    this.artifactTypes.addAll(Arrays.asList(artifactTypes));
    return this;
}
 
Example #11
Source File: AtlasDependencyGraph.java    From atlas with Apache License 2.0 5 votes vote down vote up
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)));
    }
}
 
Example #12
Source File: DefaultComponentTypeRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ComponentTypeRegistration registerArtifactType(Class<? extends Artifact> artifact, ArtifactType artifactType) {
    if (typeRegistrations.containsKey(artifact)) {
        throw new IllegalStateException(String.format("Artifact type %s is already registered for component type %s.", artifact.getName(), componentType.getName()));
    }
    typeRegistrations.put(artifact, artifactType);
    return this;
}
 
Example #13
Source File: DefaultComponentTypeRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArtifactType getArtifactType(Class<? extends Artifact> artifact) {
    ArtifactType type = typeRegistrations.get(artifact);
    if (type == null) {
        throw new IllegalArgumentException(String.format("Artifact type %s is not registered for component type %s.", artifact.getName(), componentType.getName()));
    }
    return type;
}
 
Example #14
Source File: DefaultArtifactResolutionQuery.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArtifactResolutionQuery withArtifacts(Class<? extends Component> componentType, Class<? extends Artifact>... artifactTypes) {
    if (this.componentType != null) {
        throw new IllegalStateException("Cannot specify component type multiple times.");
    }
    this.componentType = componentType;
    this.artifactTypes.addAll(Arrays.asList(artifactTypes));
    return this;
}
 
Example #15
Source File: DefaultArtifactResolutionQuery.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T extends Artifact> void addArtifacts(DefaultComponentArtifactsResult artifacts, Class<T> type, ComponentResolveMetaData component, ArtifactResolver artifactResolver) {
    BuildableArtifactSetResolveResult artifactSetResolveResult = new DefaultBuildableArtifactSetResolveResult();
    artifactResolver.resolveModuleArtifacts(component, convertType(type), artifactSetResolveResult);

    for (ComponentArtifactMetaData artifactMetaData : artifactSetResolveResult.getArtifacts()) {
        BuildableArtifactResolveResult resolveResult = new DefaultBuildableArtifactResolveResult();
        artifactResolver.resolveArtifact(artifactMetaData, component.getSource(), resolveResult);
        if (resolveResult.getFailure() != null) {
            artifacts.addArtifact(new DefaultUnresolvedArtifactResult(type, resolveResult.getFailure()));
        } else {
            artifacts.addArtifact(new DefaultResolvedArtifactResult(type, resolveResult.getFile()));
        }
    }
}
 
Example #16
Source File: IdeDependenciesExtractor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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>[]) new Class<?>[artifactTypes.size()];
    query.withArtifacts(JvmLibrary.class, artifactTypes.toArray(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.setSourceFile(((ResolvedArtifactResult) sourcesResult).getFile());
                }
            }

            for (ArtifactResult javadocResult : componentResult.getArtifacts(JavadocArtifact.class)) {
                if (javadocResult instanceof ResolvedArtifactResult) {
                    dependency.setJavadocFile(((ResolvedArtifactResult) javadocResult).getFile());
                }
            }
        }
    }
}
 
Example #17
Source File: DefaultComponentArtifactsResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Set<ArtifactResult> getArtifacts(Class<? extends Artifact> type) {
    Set<ArtifactResult> matching = Sets.newLinkedHashSet();
    for (ArtifactResult artifactResult : artifactResults) {
        if (type.isAssignableFrom(artifactResult.getType())) {
            matching.add(artifactResult);
        }
    }
    return matching;
}
 
Example #18
Source File: DefaultUnresolvedArtifactResult.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Class<? extends Artifact> getType() {
    return type;
}
 
Example #19
Source File: DefaultArtifactResolutionQuery.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private <T extends Artifact> ArtifactType convertType(Class<T> requestedType) {
    return componentTypeRegistry.getComponentRegistration(componentType).getArtifactType(requestedType);
}
 
Example #20
Source File: DefaultUnresolvedArtifactResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultUnresolvedArtifactResult(Class<? extends Artifact> type, Throwable failure) {
    this.type = type;
    this.failure = failure;
}
 
Example #21
Source File: DefaultResolvedArtifactResult.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Class<? extends Artifact> getType() {
    return type;
}
 
Example #22
Source File: DefaultResolvedArtifactResult.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultResolvedArtifactResult(Class<? extends Artifact> type, File file) {
    this.type = type;
    this.file = file;
}
 
Example #23
Source File: DefaultUnresolvedArtifactResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Class<? extends Artifact> getType() {
    return type;
}
 
Example #24
Source File: DefaultUnresolvedArtifactResult.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultUnresolvedArtifactResult(Class<? extends Artifact> type, Throwable failure) {
    this.type = type;
    this.failure = failure;
}
 
Example #25
Source File: DefaultArtifactResolutionQuery.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private <T extends Artifact> ArtifactType convertType(Class<T> requestedType) {
    return componentTypeRegistry.getComponentRegistration(componentType).getArtifactType(requestedType);
}
 
Example #26
Source File: DefaultResolvedArtifactResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultResolvedArtifactResult(Class<? extends Artifact> type, File file) {
    this.type = type;
    this.file = file;
}
 
Example #27
Source File: DefaultResolvedArtifactResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Class<? extends Artifact> getType() {
    return type;
}
 
Example #28
Source File: AtlasDependencyGraph.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends Artifact> getType() {
    return delegate.getType();
}
 
Example #29
Source File: ComponentArtifactsResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * <p>Returns the component artifacts of the specified type. Includes resolved and unresolved artifacts (if any).
 *
 * <p>The elements of the returned collection are declared as {@link ArtifactResult}, however the artifact instances will also implement one of the
 * following instances:</p>
 *
 * <ul>
 *     <li>{@link ResolvedArtifactResult} for artifacts which were successfully resolved.</li>
 *     <li>{@link UnresolvedArtifactResult} for artifacts which could not be resolved for some reason.</li>
 * </ul>
 *
 * @return the artifacts of this component with the specified type, or an empty set if no artifacts of the type exist.
 */
Set<ArtifactResult> getArtifacts(Class<? extends Artifact> type);
 
Example #30
Source File: ArtifactResolutionQuery.java    From pushfish-android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Defines the type of component that is expected in the result, and the artifacts to retrieve for components of this type.
 *
 * Presently, only a single component type and set of artifacts is permitted.
 *
 * @param componentType The expected type of the component.
 * @param artifactTypes The artifacts to retrieve for the queried components.
 */
ArtifactResolutionQuery withArtifacts(Class<? extends Component> componentType, Class<? extends Artifact>... artifactTypes);