2012-05-11 15:18:26 -04:00
|
|
|
/*
|
2013-03-07 19:25:48 -05:00
|
|
|
* Forge Mod Loader
|
|
|
|
|
* Copyright (c) 2012-2013 cpw.
|
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
* are made available under the terms of the GNU Lesser Public License v2.1
|
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2013-09-27 10:45:20 -04:00
|
|
|
*
|
2013-03-07 19:25:48 -05:00
|
|
|
* Contributors:
|
|
|
|
|
* cpw - implementation
|
2012-05-11 15:18:26 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package cpw.mods.fml.common;
|
|
|
|
|
|
2012-08-17 09:10:39 -04:00
|
|
|
import static argo.jdom.JsonNodeBuilders.aStringBuilder;
|
|
|
|
|
|
2012-08-23 14:05:17 -04:00
|
|
|
import java.util.ArrayList;
|
2012-08-23 13:43:25 -04:00
|
|
|
import java.util.Collection;
|
2012-08-23 14:05:17 -04:00
|
|
|
import java.util.HashSet;
|
2012-05-15 15:52:19 -04:00
|
|
|
import java.util.List;
|
2012-05-25 15:25:35 -04:00
|
|
|
import java.util.Map;
|
2012-08-23 13:43:25 -04:00
|
|
|
import java.util.Set;
|
2012-08-17 09:10:39 -04:00
|
|
|
import java.util.logging.Level;
|
2012-05-11 15:18:26 -04:00
|
|
|
|
2012-07-22 11:56:38 -02:30
|
|
|
import argo.jdom.JsonNode;
|
|
|
|
|
import argo.jdom.JsonStringNode;
|
|
|
|
|
|
|
|
|
|
import com.google.common.base.Function;
|
|
|
|
|
import com.google.common.base.Joiner;
|
2012-08-23 01:17:47 -04:00
|
|
|
import com.google.common.base.Objects;
|
2012-07-22 11:56:38 -02:30
|
|
|
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;
|
2012-07-30 17:01:27 -04:00
|
|
|
import cpw.mods.fml.common.versioning.ArtifactVersion;
|
|
|
|
|
import cpw.mods.fml.common.versioning.VersionParser;
|
2012-07-22 11:56:38 -02:30
|
|
|
|
2012-05-11 15:18:26 -04:00
|
|
|
/**
|
|
|
|
|
* @author cpw
|
2012-07-30 17:01:27 -04:00
|
|
|
*
|
2012-05-11 15:18:26 -04:00
|
|
|
*/
|
|
|
|
|
public class ModMetadata
|
|
|
|
|
{
|
2012-07-22 11:56:38 -02:30
|
|
|
private static final class JsonStringConverter implements Function<JsonNode, Object>
|
|
|
|
|
{
|
|
|
|
|
public Object apply(JsonNode arg0)
|
|
|
|
|
{
|
|
|
|
|
if (arg0.hasElements())
|
|
|
|
|
{
|
|
|
|
|
return Lists.transform(arg0.getElements(), new JsonArrayConverter());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return arg0.getText();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final class JsonArrayConverter implements Function<JsonNode, String>
|
|
|
|
|
{
|
|
|
|
|
public String apply(JsonNode arg0)
|
|
|
|
|
{
|
|
|
|
|
return arg0.getText();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String modId;
|
2012-05-11 15:18:26 -04:00
|
|
|
public String name;
|
2013-09-27 10:45:20 -04:00
|
|
|
public String description = "";
|
2012-07-22 11:56:38 -02:30
|
|
|
|
|
|
|
|
public String url = "";
|
|
|
|
|
public String updateUrl = "";
|
|
|
|
|
|
|
|
|
|
public String logoFile = "";
|
|
|
|
|
public String version = "";
|
|
|
|
|
public List<String> authorList = Lists.newArrayList();
|
|
|
|
|
public String credits = "";
|
|
|
|
|
public String parent = "";
|
2012-05-15 15:52:19 -04:00
|
|
|
public String[] screenshots;
|
2012-07-22 11:56:38 -02:30
|
|
|
|
2012-05-25 15:25:35 -04:00
|
|
|
public ModContainer parentMod;
|
2012-07-22 11:56:38 -02:30
|
|
|
public List<ModContainer> childMods = Lists.newArrayList();
|
|
|
|
|
|
|
|
|
|
public boolean useDependencyInformation;
|
2012-08-23 13:43:25 -04:00
|
|
|
public Set<ArtifactVersion> requiredMods;
|
2012-07-30 17:01:27 -04:00
|
|
|
public List<ArtifactVersion> dependencies;
|
|
|
|
|
public List<ArtifactVersion> dependants;
|
2012-07-23 16:33:17 -02:30
|
|
|
public boolean autogenerated;
|
2012-05-11 15:18:26 -04:00
|
|
|
|
2012-07-22 11:56:38 -02:30
|
|
|
public ModMetadata(JsonNode node)
|
2012-05-11 15:18:26 -04:00
|
|
|
{
|
2012-07-22 11:56:38 -02:30
|
|
|
Map<JsonStringNode, Object> processedFields = Maps.transformValues(node.getFields(), new JsonStringConverter());
|
|
|
|
|
modId = (String)processedFields.get(aStringBuilder("modid"));
|
2012-08-17 09:10:39 -04:00
|
|
|
if (Strings.isNullOrEmpty(modId))
|
|
|
|
|
{
|
|
|
|
|
FMLLog.log(Level.SEVERE, "Found an invalid mod metadata file - missing modid");
|
|
|
|
|
throw new LoaderException();
|
|
|
|
|
}
|
2012-07-22 11:56:38 -02:30
|
|
|
name = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("name")));
|
|
|
|
|
description = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("description")));
|
|
|
|
|
url = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("url")));
|
|
|
|
|
updateUrl = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("updateUrl")));
|
|
|
|
|
logoFile = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("logoFile")));
|
|
|
|
|
version = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("version")));
|
|
|
|
|
credits = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("credits")));
|
|
|
|
|
parent = Strings.nullToEmpty((String)processedFields.get(aStringBuilder("parent")));
|
2012-08-23 01:17:47 -04:00
|
|
|
authorList = Objects.firstNonNull(((List<String>)processedFields.get(aStringBuilder("authors"))),Objects.firstNonNull(((List<String>)processedFields.get(aStringBuilder("authorList"))), authorList));
|
2012-08-23 14:05:17 -04:00
|
|
|
requiredMods = processReferences(processedFields.get(aStringBuilder("requiredMods")), HashSet.class);
|
|
|
|
|
dependencies = processReferences(processedFields.get(aStringBuilder("dependencies")), ArrayList.class);
|
|
|
|
|
dependants = processReferences(processedFields.get(aStringBuilder("dependants")), ArrayList.class);
|
2012-07-22 11:56:38 -02:30
|
|
|
useDependencyInformation = Boolean.parseBoolean(Strings.nullToEmpty((String)processedFields.get(aStringBuilder("useDependencyInformation"))));
|
2012-05-11 15:18:26 -04:00
|
|
|
}
|
2012-07-22 11:56:38 -02:30
|
|
|
|
2012-08-04 22:51:57 -07:00
|
|
|
public ModMetadata()
|
2012-07-22 11:56:38 -02:30
|
|
|
{
|
2012-05-25 15:25:35 -04:00
|
|
|
}
|
|
|
|
|
|
2012-08-23 13:43:25 -04:00
|
|
|
private <T extends Collection<ArtifactVersion>> T processReferences(Object refs, Class<? extends T> retType)
|
2012-07-30 17:01:27 -04:00
|
|
|
{
|
2012-08-23 13:43:25 -04:00
|
|
|
T res = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
res = retType.newInstance();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
// unpossible
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-30 17:01:27 -04:00
|
|
|
if (refs == null)
|
|
|
|
|
{
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2012-08-23 13:43:25 -04:00
|
|
|
for (String ref : ((List<String>)refs))
|
2012-07-30 17:01:27 -04:00
|
|
|
{
|
|
|
|
|
res.add(VersionParser.parseVersionReference(ref));
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2012-09-15 18:04:56 -07:00
|
|
|
|
2012-05-25 15:25:35 -04:00
|
|
|
public String getChildModCountString()
|
|
|
|
|
{
|
2012-07-22 11:56:38 -02:30
|
|
|
return String.format("%d child mod%s", childMods.size(), childMods.size() != 1 ? "s" : "");
|
2012-05-25 15:25:35 -04:00
|
|
|
}
|
|
|
|
|
|
2012-07-22 11:56:38 -02:30
|
|
|
public String getAuthorList()
|
|
|
|
|
{
|
|
|
|
|
return Joiner.on(", ").join(authorList);
|
2012-05-25 15:25:35 -04:00
|
|
|
}
|
2012-07-22 11:56:38 -02:30
|
|
|
|
2012-05-25 15:25:35 -04:00
|
|
|
public String getChildModList()
|
|
|
|
|
{
|
2012-07-22 11:56:38 -02:30
|
|
|
return Joiner.on(", ").join(Lists.transform(childMods, new ModNameFunction()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String printableSortingRules()
|
|
|
|
|
{
|
2012-08-16 13:55:42 -04:00
|
|
|
return "";
|
2012-05-25 15:25:35 -04:00
|
|
|
}
|
2012-05-11 15:18:26 -04:00
|
|
|
}
|