mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 21:05:58 -05:00
use manifest name in file name instead of url hash (#1127)
This commit is contained in:
@@ -30,17 +30,21 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
public interface VersionsManifestsAPI {
|
||||
/**
|
||||
* Adds a URL to a versions manifest json with the default priority of {@code 0}.
|
||||
* @param name a string that uniquely identifies this versions manifest,
|
||||
* to be used in cache file paths
|
||||
* @param url the String-representation of the URL to the manifest json
|
||||
*/
|
||||
default void add(String url) {
|
||||
add(url, 0);
|
||||
default void add(String name, String url) {
|
||||
add(name, url, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a URL to a versions manifest json with the given priority.
|
||||
* @param name a string that uniquely identifies this versions manifest,
|
||||
* to be used in cache file paths
|
||||
* @param url the String-representation of the URL to the manifest json
|
||||
* @param priority the priority with which this URL gets sorted against other entries
|
||||
* entries are sorted by priority, from lowest to highest
|
||||
*/
|
||||
void add(String url, int priority);
|
||||
void add(String name, String url, int priority);
|
||||
}
|
||||
|
||||
@@ -25,29 +25,26 @@
|
||||
package net.fabricmc.loom.configuration.providers.minecraft;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
import net.fabricmc.loom.api.manifest.VersionsManifestsAPI;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.ManifestLocations.ManifestLocation;
|
||||
|
||||
public class ManifestLocations implements VersionsManifestsAPI, Iterable<ManifestLocation> {
|
||||
private static final String FILE_EXTENSION = ".json";
|
||||
private final Queue<ManifestLocation> locations = new PriorityQueue<>();
|
||||
private final String baseFileName;
|
||||
|
||||
public ManifestLocations(String baseFileName) {
|
||||
this.baseFileName = baseFileName;
|
||||
}
|
||||
|
||||
public void addBuiltIn(int priority, String url, String fileName) {
|
||||
locations.add(new ManifestLocation(priority, url, fileName));
|
||||
}
|
||||
private final Set<String> manifestNames = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public void add(String url, int priority) {
|
||||
locations.add(new ManifestLocation(priority, url));
|
||||
public void add(String name, String url, int priority) {
|
||||
if (manifestNames.add(name)) {
|
||||
locations.add(new ManifestLocation(name, url, priority));
|
||||
} else {
|
||||
throw new IllegalStateException("cannot add multiple versions manifests with the same name!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,22 +53,18 @@ public class ManifestLocations implements VersionsManifestsAPI, Iterable<Manifes
|
||||
}
|
||||
|
||||
public class ManifestLocation implements Comparable<ManifestLocation> {
|
||||
private final int priority;
|
||||
private final String name;
|
||||
private final String url;
|
||||
private final String builtInFileName;
|
||||
private final int priority;
|
||||
|
||||
private ManifestLocation(int priority, String url) {
|
||||
this(priority, url, null);
|
||||
}
|
||||
|
||||
private ManifestLocation(int priority, String url, String builtInFileName) {
|
||||
this.priority = priority;
|
||||
private ManifestLocation(String name, String url, int priority) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.builtInFileName = builtInFileName;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public boolean isBuiltIn() {
|
||||
return builtInFileName != null;
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String url() {
|
||||
@@ -79,10 +72,7 @@ public class ManifestLocations implements VersionsManifestsAPI, Iterable<Manifes
|
||||
}
|
||||
|
||||
public Path cacheFile(Path dir) {
|
||||
String fileName = (builtInFileName != null)
|
||||
? builtInFileName + FILE_EXTENSION
|
||||
: baseFileName + "-" + Integer.toHexString(url.hashCode()) + FILE_EXTENSION;
|
||||
return dir.resolve(fileName);
|
||||
return dir.resolve(name + "_versions_manifest.json");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -161,19 +161,13 @@ public final class MinecraftMetadataProvider {
|
||||
}
|
||||
|
||||
private String getVersionMetaFileName() {
|
||||
String base = "minecraft-info";
|
||||
|
||||
// custom version metadata
|
||||
if (versionEntry.manifest == null) {
|
||||
return base + Integer.toHexString(versionEntry.entry.url.hashCode()) + ".json";
|
||||
return "minecraft_info_" + Integer.toHexString(versionEntry.entry.url.hashCode()) + ".json";
|
||||
}
|
||||
|
||||
// custom versions manifest
|
||||
if (!versionEntry.manifest.isBuiltIn()) {
|
||||
return base + Integer.toHexString(versionEntry.manifest.url().hashCode()) + ".json";
|
||||
}
|
||||
|
||||
return base + ".json";
|
||||
// metadata url taken from versions manifest
|
||||
return versionEntry.manifest.name() + "_minecraft_info.json";
|
||||
}
|
||||
|
||||
public record Options(String minecraftVersion,
|
||||
|
||||
@@ -117,9 +117,9 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
.empty();
|
||||
this.log4jConfigs = project.files(directories.getDefaultLog4jConfigFile());
|
||||
this.accessWidener = project.getObjects().fileProperty();
|
||||
this.versionsManifests = new ManifestLocations("versions_manifest");
|
||||
this.versionsManifests.addBuiltIn(-2, MirrorUtil.getVersionManifests(project), "versions_manifest");
|
||||
this.versionsManifests.addBuiltIn(-1, MirrorUtil.getExperimentalVersions(project), "experimental_versions_manifest");
|
||||
this.versionsManifests = new ManifestLocations();
|
||||
this.versionsManifests.add("mojang", MirrorUtil.getVersionManifests(project), -2);
|
||||
this.versionsManifests.add("fabric_experimental", MirrorUtil.getExperimentalVersions(project), -1);
|
||||
this.customMetadata = project.getObjects().property(String.class);
|
||||
this.knownIndyBsms = project.getObjects().setProperty(String.class).convention(Set.of(
|
||||
"java/lang/invoke/StringConcatFactory",
|
||||
|
||||
@@ -153,9 +153,9 @@ class MinecraftMetadataProviderTest extends DownloadTest {
|
||||
}
|
||||
|
||||
private MinecraftMetadataProvider.Options options(String version, String customUrl) {
|
||||
ManifestLocations manifests = new ManifestLocations("versions_manifest")
|
||||
manifests.addBuiltIn(0, "$PATH/versionManifest", "versions_manifest")
|
||||
manifests.addBuiltIn(1, "$PATH/experimentalVersionManifest", "experimental_versions_manifest")
|
||||
ManifestLocations manifests = new ManifestLocations()
|
||||
manifests.add("test", "$PATH/versionManifest", 0)
|
||||
manifests.add("test_experimental", "$PATH/experimentalVersionManifest", 1)
|
||||
|
||||
return new MinecraftMetadataProvider.Options(
|
||||
version,
|
||||
|
||||
Reference in New Issue
Block a user