mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 05:27:43 -05:00
Download source artifacts in parallel (#1232)
This commit is contained in:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user