mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
Mod metadata fixes
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package dev.architectury.loom.metadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -37,15 +35,4 @@ public interface ModMetadataFile {
|
||||
* {@return a list of the mixin configs declared in this mod metadata file}.
|
||||
*/
|
||||
List<String> getMixinConfigs();
|
||||
|
||||
/**
|
||||
* Reads the mod metadata file from a jar.
|
||||
*
|
||||
* @param jar the path to the jar file
|
||||
* @return the mod metadata file, or {@code null} if not found
|
||||
*/
|
||||
@Deprecated // TODO 1.1 MERGE
|
||||
static @Nullable ModMetadataFile fromJar(Path jar) throws IOException {
|
||||
return ModMetadataFiles.fromJar(jar);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +14,21 @@ import org.jetbrains.annotations.Nullable;
|
||||
import net.fabricmc.loom.util.ZipUtils;
|
||||
import net.fabricmc.loom.util.gradle.SourceSetHelper;
|
||||
|
||||
/**
|
||||
* Utilities for reading mod metadata files.
|
||||
*/
|
||||
public final class ModMetadataFiles {
|
||||
private static final Map<String, Function<byte[], ModMetadataFile>> SINGLE_FILE_METADATA_TYPES = ImmutableMap.<String, Function<byte[], ModMetadataFile>>builder()
|
||||
.put(ArchitecturyCommonJson.FILE_NAME, ArchitecturyCommonJson::of)
|
||||
.put(QuiltModJson.FILE_NAME, QuiltModJson::of)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Reads the mod metadata file from a jar.
|
||||
*
|
||||
* @param jar the path to the jar file
|
||||
* @return the mod metadata file, or {@code null} if not found
|
||||
*/
|
||||
public static @Nullable ModMetadataFile fromJar(Path jar) throws IOException {
|
||||
for (final String filePath : SINGLE_FILE_METADATA_TYPES.keySet()) {
|
||||
final byte @Nullable [] bytes = ZipUtils.unpackNullable(jar, filePath);
|
||||
@@ -32,6 +41,12 @@ public final class ModMetadataFiles {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the mod metadata file from a directory.
|
||||
*
|
||||
* @param directory the path to the directory
|
||||
* @return the mod metadata file, or {@code null} if not found
|
||||
*/
|
||||
public static @Nullable ModMetadataFile fromDirectory(Path directory) throws IOException {
|
||||
for (final String filePath : SINGLE_FILE_METADATA_TYPES.keySet()) {
|
||||
final Path metadataPath = directory.resolve(filePath);
|
||||
@@ -44,6 +59,12 @@ public final class ModMetadataFiles {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the first mod metadata file from source sets.
|
||||
*
|
||||
* @param sourceSets the source sets to read from
|
||||
* @return the mod metadata file, or {@code null} if not found
|
||||
*/
|
||||
public static @Nullable ModMetadataFile fromSourceSets(SourceSet... sourceSets) throws IOException {
|
||||
for (final String filePath : SINGLE_FILE_METADATA_TYPES.keySet()) {
|
||||
final @Nullable File file = SourceSetHelper.findFirstFileInResource(filePath, sourceSets);
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.util.Objects;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.architectury.loom.metadata.ModMetadataFile;
|
||||
import dev.architectury.loom.metadata.ModMetadataFiles;
|
||||
|
||||
import net.fabricmc.loom.util.ZipUtils;
|
||||
|
||||
@@ -59,7 +60,7 @@ public record AccessWidenerFile(
|
||||
String awPath;
|
||||
|
||||
try {
|
||||
modMetadata = ModMetadataFile.fromJar(modJarPath);
|
||||
modMetadata = ModMetadataFiles.fromJar(modJarPath);
|
||||
|
||||
if (modMetadata != null) {
|
||||
awPath = modMetadata.getAccessWidener();
|
||||
|
||||
@@ -73,7 +73,7 @@ public final class FabricModJsonFactory {
|
||||
|
||||
public static FabricModJson createFromZip(Path zipPath) {
|
||||
try {
|
||||
@Nullable ModMetadataFile modMetadata = ModMetadataFile.fromJar(zipPath);
|
||||
@Nullable ModMetadataFile modMetadata = ModMetadataFiles.fromJar(zipPath);
|
||||
|
||||
if (modMetadata != null) {
|
||||
return new ModMetadataFabricModJson(modMetadata, new FabricModJsonSource.ZipSource(zipPath));
|
||||
@@ -92,7 +92,7 @@ public final class FabricModJsonFactory {
|
||||
@Nullable
|
||||
public static FabricModJson createFromZipNullable(Path zipPath) {
|
||||
try {
|
||||
final @Nullable ModMetadataFile modMetadata = ModMetadataFile.fromJar(zipPath);
|
||||
final @Nullable ModMetadataFile modMetadata = ModMetadataFiles.fromJar(zipPath);
|
||||
|
||||
if (modMetadata != null) {
|
||||
return new ModMetadataFabricModJson(modMetadata, new FabricModJsonSource.ZipSource(zipPath));
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
package net.fabricmc.loom.test.unit.architectury
|
||||
|
||||
import dev.architectury.loom.metadata.ArchitecturyCommonJson
|
||||
import dev.architectury.loom.metadata.ModMetadataFile
|
||||
import dev.architectury.loom.metadata.ModMetadataFiles
|
||||
import dev.architectury.loom.metadata.QuiltModJson
|
||||
import net.fabricmc.loom.util.ZipUtils
|
||||
import spock.lang.Specification
|
||||
@@ -33,42 +33,42 @@ import spock.lang.TempDir
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
class ModMetadataFileTest extends Specification {
|
||||
class ModMetadataFilesTest extends Specification {
|
||||
@TempDir
|
||||
Path zipContents
|
||||
|
||||
@TempDir
|
||||
Path workingDir
|
||||
|
||||
def "read nothing"() {
|
||||
def "read nothing from jar"() {
|
||||
given:
|
||||
def jar = workingDir.resolve("my_mod.jar")
|
||||
zipContents.resolve('foo.txt').text = 'hello'
|
||||
ZipUtils.pack(zipContents, jar)
|
||||
when:
|
||||
def modMetadata = ModMetadataFile.fromJar(jar)
|
||||
def modMetadata = ModMetadataFiles.fromJar(jar)
|
||||
then:
|
||||
modMetadata == null
|
||||
}
|
||||
|
||||
def "read quilt.mod.json"() {
|
||||
def "read quilt.mod.json from jar"() {
|
||||
given:
|
||||
def jar = workingDir.resolve("my_mod.jar")
|
||||
zipContents.resolve('quilt.mod.json').text = '{}'
|
||||
ZipUtils.pack(zipContents, jar)
|
||||
when:
|
||||
def modMetadata = ModMetadataFile.fromJar(jar)
|
||||
def modMetadata = ModMetadataFiles.fromJar(jar)
|
||||
then:
|
||||
modMetadata instanceof QuiltModJson
|
||||
}
|
||||
|
||||
def "read architectury.common.json"() {
|
||||
def "read architectury.common.json from jar"() {
|
||||
given:
|
||||
def jar = workingDir.resolve("my_mod.jar")
|
||||
zipContents.resolve('architectury.common.json').text = '{}'
|
||||
ZipUtils.pack(zipContents, jar)
|
||||
when:
|
||||
def modMetadata = ModMetadataFile.fromJar(jar)
|
||||
def modMetadata = ModMetadataFiles.fromJar(jar)
|
||||
then:
|
||||
modMetadata instanceof ArchitecturyCommonJson
|
||||
}
|
||||
Reference in New Issue
Block a user