From 26bb005731b0721e4dcb53929f8ef8e33c08a85d Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 17 Aug 2012 09:10:39 -0400 Subject: [PATCH] Fix jar loader failing to inject any metadata at all if mcmod.info is not found. --- .../cpw/mods/fml/common/ModMetadata.java | 18 ++++++++---------- .../fml/common/discovery/JarDiscoverer.java | 6 +++++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/fml/common/cpw/mods/fml/common/ModMetadata.java b/fml/common/cpw/mods/fml/common/ModMetadata.java index 65257cde8..93f1478d3 100644 --- a/fml/common/cpw/mods/fml/common/ModMetadata.java +++ b/fml/common/cpw/mods/fml/common/ModMetadata.java @@ -14,33 +14,26 @@ package cpw.mods.fml.common; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; +import static argo.jdom.JsonNodeBuilders.aStringBuilder; + import java.util.List; import java.util.Map; -import java.util.StringTokenizer; -import java.util.zip.ZipInputStream; +import java.util.logging.Level; import argo.jdom.JsonNode; import argo.jdom.JsonStringNode; import com.google.common.base.Function; import com.google.common.base.Joiner; -import com.google.common.base.Objects; import com.google.common.base.Optional; import com.google.common.base.Strings; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import cpw.mods.fml.common.functions.ModNameFunction; -import cpw.mods.fml.common.modloader.ModLoaderModContainer; import cpw.mods.fml.common.versioning.ArtifactVersion; import cpw.mods.fml.common.versioning.VersionParser; -import static argo.jdom.JsonNodeBuilders.*; - /** * @author cpw * @@ -101,6 +94,11 @@ public class ModMetadata { Map processedFields = Maps.transformValues(node.getFields(), new JsonStringConverter()); modId = (String)processedFields.get(aStringBuilder("modid")); + if (Strings.isNullOrEmpty(modId)) + { + FMLLog.log(Level.SEVERE, "Found an invalid mod metadata file - missing modid"); + throw new LoaderException(); + } name = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("name"))); description = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("description"))); url = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("url"))); diff --git a/fml/common/cpw/mods/fml/common/discovery/JarDiscoverer.java b/fml/common/cpw/mods/fml/common/discovery/JarDiscoverer.java index 922ee3aa9..97c62f13f 100644 --- a/fml/common/cpw/mods/fml/common/discovery/JarDiscoverer.java +++ b/fml/common/cpw/mods/fml/common/discovery/JarDiscoverer.java @@ -2,7 +2,6 @@ package cpw.mods.fml.common.discovery; import java.util.Collections; import java.util.List; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -34,6 +33,11 @@ public class JarDiscoverer implements ITypeDiscoverer FMLLog.finer("Located mcmod.info file in file %s", candidate.getModContainer().getName()); mc = MetadataCollection.from(jar.getInputStream(modInfo)); } + else + { + FMLLog.info("The mod container %s appears to be missing an mcmod.info file", candidate.getModContainer().getName()); + mc = MetadataCollection.from(null); + } for (ZipEntry ze : Collections.list(jar.entries())) { Matcher match = classFile.matcher(ze.getName());