|
38 | 38 | import java.nio.file.Files;
|
39 | 39 | import java.nio.file.Path;
|
40 | 40 | import java.util.Collections;
|
| 41 | +import java.util.Comparator; |
41 | 42 | import java.util.HashMap;
|
42 | 43 | import java.util.LinkedHashMap;
|
43 | 44 | import java.util.LinkedHashSet;
|
|
53 | 54 | import java.util.concurrent.TimeUnit;
|
54 | 55 |
|
55 | 56 | public final class LibraryManager {
|
56 |
| - public static final String SPONGE_NEXUS_DOWNLOAD_URL = "https://repo.spongepowered.org/service/rest/v1/search/assets?sha512=%s" |
57 |
| - + "&maven.groupId=%s&maven.artifactId=%s&maven.baseVersion=%s&maven.extension=jar"; |
| 57 | + public static final String SPONGE_NEXUS_DOWNLOAD_URL = "https://repo.spongepowered.org/service/rest/v1/search/assets?sha512=%s&maven.groupId=%s&maven.artifactId=%s&maven.baseVersion=%s&maven.extension=jar"; |
| 58 | + |
| 59 | + // This is the list of repositories we sort artifacts by when retrieving them via the library manager. |
| 60 | + // The order of which is semi-important as we want to prefer the most authoritative repository for a given |
| 61 | + // artifact. |
| 62 | + private static final List<String> PREFERRED_REPOSITORY_ORDER = List.of( |
| 63 | + "maven-central", "minecraft-proxy", "maven-releases", "maven-snapshots", "google-proxy", |
| 64 | + "forge-proxy", "neoforge-releases", "neoforge-snapshots", "fabric-proxy"); |
58 | 65 |
|
59 | 66 | private final Logger logger;
|
60 | 67 | private final boolean checkLibraryHashes;
|
@@ -166,8 +173,16 @@ private Set<Library> scheduleDownloads(
|
166 | 173 | failures.add("No data received from '" + requestUrl + "'!");
|
167 | 174 | return null;
|
168 | 175 | }
|
169 |
| - |
170 |
| - final SonatypeResponse.Item item = response.items().get(0); |
| 176 | + // Sort the items based on the preferred repository order |
| 177 | + final var item = response.items() |
| 178 | + .stream() |
| 179 | + .min(Comparator.comparingInt(i -> { |
| 180 | + if (!PREFERRED_REPOSITORY_ORDER.contains(i.repository())) { |
| 181 | + return Integer.MAX_VALUE; |
| 182 | + } |
| 183 | + return PREFERRED_REPOSITORY_ORDER.indexOf(i.repository()); |
| 184 | + })) |
| 185 | + .get(); |
171 | 186 |
|
172 | 187 | if (checkHashes) {
|
173 | 188 | LibraryUtils.downloadAndVerifyDigest(this.logger, item.downloadUrl(), depFile, "SHA-512", item.checksum().sha512());
|
|
0 commit comments