mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 21:05:58 -05:00
ModMetadataFiles: Only log a warning with broken mods.toml
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package dev.architectury.loom.metadata;
|
||||
|
||||
import net.fabricmc.loom.configuration.ifaceinject.InterfaceInjectionProcessor;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A fallback mod metadata file that represents a non-fatal format error
|
||||
* in another file type. An example of such file type is mods.toml,
|
||||
* which doesn't necessarily need to be parsed – it primarily needs to just exist.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public final class ErroringModMetadataFile implements ModMetadataFile {
|
||||
private final String fileName;
|
||||
|
||||
ErroringModMetadataFile(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getIds() {
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAccessWideners() {
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InterfaceInjectionProcessor.InjectedInterface> getInjectedInterfaces(@Nullable String modId) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return fileName + " [erroring]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMixinConfigs() {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,11 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.gradle.api.logging.Logger;
|
||||
import org.gradle.api.logging.Logging;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -18,12 +21,24 @@ import net.fabricmc.loom.util.gradle.SourceSetHelper;
|
||||
* Utilities for reading mod metadata files.
|
||||
*/
|
||||
public final class ModMetadataFiles {
|
||||
private static final Logger LOGGER = Logging.getLogger(ModMetadataFiles.class);
|
||||
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)
|
||||
.put(ModsToml.FILE_PATH, ModsToml::of)
|
||||
.put(ModsToml.FILE_PATH, onError(ModsToml::of, "Could not load mods.toml", () -> new ErroringModMetadataFile("mods.toml")))
|
||||
.build();
|
||||
|
||||
private static <A, B> Function<A, B> onError(Function<A, B> fn, String message, Supplier<B> onError) {
|
||||
return a -> {
|
||||
try {
|
||||
return fn.apply(a);
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn(message, e);
|
||||
return onError.get();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the mod metadata file from a jar.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user