Skip to content

Commit

Permalink
use manifest name in file name instead of url hash (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceWalkerRS authored Sep 3, 2024
1 parent 7ab6e56 commit 039b435
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,33 +53,26 @@ public Iterator<ManifestLocation> iterator() {
}

public class ManifestLocation implements Comparable<ManifestLocation> {
private final int priority;
private final String name;
private final String url;
private final String builtInFileName;

private ManifestLocation(int priority, String url) {
this(priority, url, null);
}
private final int priority;

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() {
return url;
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,13 @@ private MinecraftVersionMeta readVersionMeta() throws IOException {
}

private String getVersionMetaFileName() {
String base = "minecraft-info";

// custom version metadata
if (versionEntry.manifest == null) {
return base + Integer.toHexString(versionEntry.entry.url.hashCode()) + ".json";
}

// custom versions manifest
if (!versionEntry.manifest.isBuiltIn()) {
return base + Integer.toHexString(versionEntry.manifest.url().hashCode()) + ".json";
return "minecraft_info_" + Integer.toHexString(versionEntry.entry.url.hashCode()) + ".json";
}

return base + ".json";
// metadata url taken from versions manifest
return versionEntry.manifest.name() + "_minecraft_info.json";
}

public record Options(String minecraftVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ protected LoomGradleExtensionApiImpl(Project project, LoomFiles directories) {
.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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 039b435

Please sign in to comment.