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()); } } } } }
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()); } } } } }
@Nullable public static String getProguardJarPath(Project project) { String proguardVersion = ProjectUtil.findVersionInClasspath(project, PROGUARD_GROUP, PROGUARD_MODULE); Configuration proguardConfiguration = project.getConfigurations().detachedConfiguration( new DefaultExternalModuleDependency(PROGUARD_GROUP, PROGUARD_MODULE, proguardVersion)); DependencyCache proguardCache = new DependencyCache(project, DependencyUtils.createCacheDir(project, PROGUARD_DEPS_CACHE)); proguardCache.build(proguardConfiguration); String proguardJarPath = null; try { Optional<ResolvedArtifactResult> artifactResult = proguardConfiguration.getIncoming().getArtifacts() .getArtifacts() .stream() .filter(artifact -> { ComponentIdentifier identifier = artifact.getId().getComponentIdentifier(); return identifier instanceof ModuleComponentIdentifier && ((ModuleComponentIdentifier) identifier).getGroup().equals(PROGUARD_GROUP) && ((ModuleComponentIdentifier) identifier).getModule().equals(PROGUARD_MODULE); }).findFirst(); if (artifactResult.isPresent()) { proguardJarPath = proguardCache.get( new ExternalDependency( PROGUARD_GROUP, PROGUARD_MODULE, proguardVersion, artifactResult.get().getFile()), true, false); } } catch (IllegalStateException ignored) {} return proguardJarPath; }
ResolvedArtifactCollectingVisitor(Collection<? super ResolvedArtifactResult> artifacts) { this.artifacts = artifacts; }
@Override public <T extends Collection<? super ResolvedArtifactResult>> T collectArtifacts(T dest) throws ResolveException { return dest; }
@Override public <T extends Collection<? super ResolvedArtifactResult>> T collectArtifacts(T dest) throws ResolveException { throw wrapException(e, configuration); }
@Override public <T extends Collection<? super ResolvedArtifactResult>> T collectArtifacts(T dest) throws ResolveException { throw new UnsupportedOperationException("Artifacts have not been resolved."); }
public Set<ResolvedArtifactResult> getArtifacts() { resolveToStateOrLater(ARTIFACTS_RESOLVED); return cachedResolverResults.getVisitedArtifacts().select(Specs.<Dependency>satisfyAll(), configurationAttributes).collectArtifacts(new LinkedHashSet<ResolvedArtifactResult>()); }
/** * Collects all artifacts into the given collection. Fails when any artifact cannot be resolved. * * @return the collection * @throws ResolveException On any failure. */ <T extends Collection<? super ResolvedArtifactResult>> T collectArtifacts(T dest) throws ResolveException;