Fix jar loader failing to inject any metadata at all if mcmod.info is not found.

This commit is contained in:
Christian 2012-08-17 09:10:39 -04:00
parent 8444fa6d3c
commit 26bb005731
2 changed files with 13 additions and 11 deletions

View file

@ -14,33 +14,26 @@
package cpw.mods.fml.common; package cpw.mods.fml.common;
import java.io.IOException; import static argo.jdom.JsonNodeBuilders.aStringBuilder;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.StringTokenizer; import java.util.logging.Level;
import java.util.zip.ZipInputStream;
import argo.jdom.JsonNode; import argo.jdom.JsonNode;
import argo.jdom.JsonStringNode; import argo.jdom.JsonStringNode;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import cpw.mods.fml.common.functions.ModNameFunction; 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.ArtifactVersion;
import cpw.mods.fml.common.versioning.VersionParser; import cpw.mods.fml.common.versioning.VersionParser;
import static argo.jdom.JsonNodeBuilders.*;
/** /**
* @author cpw * @author cpw
* *
@ -101,6 +94,11 @@ public class ModMetadata
{ {
Map<JsonStringNode, Object> processedFields = Maps.transformValues(node.getFields(), new JsonStringConverter()); Map<JsonStringNode, Object> processedFields = Maps.transformValues(node.getFields(), new JsonStringConverter());
modId = (String)processedFields.get(aStringBuilder("modid")); 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"))); name = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("name")));
description = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("description"))); description = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("description")));
url = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("url"))); url = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("url")));

View file

@ -2,7 +2,6 @@ package cpw.mods.fml.common.discovery;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; 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()); FMLLog.finer("Located mcmod.info file in file %s", candidate.getModContainer().getName());
mc = MetadataCollection.from(jar.getInputStream(modInfo)); 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())) for (ZipEntry ze : Collections.list(jar.entries()))
{ {
Matcher match = classFile.matcher(ze.getName()); Matcher match = classFile.matcher(ze.getName());