Download source artifacts in parallel (#1232)

This commit is contained in:
modmuss
2024-12-23 14:24:39 +00:00
committed by GitHub
parent 40d17bacee
commit 2ba633badf

View File

@@ -35,6 +35,7 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
import com.google.common.collect.ImmutableMap;
@@ -43,6 +44,8 @@ import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.FileCollectionDependency;
import org.gradle.api.artifacts.MutableVersionConstraint;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.component.ComponentArtifactIdentifier;
import org.gradle.api.artifacts.component.ComponentIdentifier;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.artifacts.query.ArtifactResolutionQuery;
import org.gradle.api.artifacts.result.ArtifactResult;
@@ -243,7 +246,10 @@ public class ModConfigurationRemapper {
private static List<ArtifactRef> resolveArtifacts(Project project, Configuration configuration) {
final List<ArtifactRef> artifacts = new ArrayList<>();
for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) {
final Set<ResolvedArtifact> resolvedArtifacts = configuration.getResolvedConfiguration().getResolvedArtifacts();
downloadAllSources(project, resolvedArtifacts);
for (ResolvedArtifact artifact : resolvedArtifacts) {
final Path sources = findSources(project, artifact);
artifacts.add(new ArtifactRef.ResolvedArtifactRef(artifact, sources));
}
@@ -270,6 +276,27 @@ public class ModConfigurationRemapper {
return (dotIndex == -1) ? fileName : fileName.substring(0, dotIndex);
}
private static void downloadAllSources(Project project, Set<ResolvedArtifact> resolvedArtifacts) {
if (isCIBuild()) {
return;
}
final DependencyHandler dependencies = project.getDependencies();
List<ComponentIdentifier> componentIdentifiers = resolvedArtifacts.stream()
.map(ResolvedArtifact::getId)
.map(ComponentArtifactIdentifier::getComponentIdentifier)
.toList();
//noinspection unchecked
ArtifactResolutionQuery query = dependencies.createArtifactResolutionQuery()
.forComponents(componentIdentifiers)
.withArtifacts(JvmLibrary.class, SourcesArtifact.class);
// Run a single query for all of the artifacts, this will allow them to be resolved in parallel before they are queried individually
query.execute();
}
@Nullable
public static Path findSources(Project project, ResolvedArtifact artifact) {
if (isCIBuild()) {