From 7b04f0a6cd217e638f2dfaf676b7e7cf4712181e Mon Sep 17 00:00:00 2001 From: Wesley Wolfe Date: Sat, 15 Feb 2014 11:17:14 -0600 Subject: Fix loadbefore, soft, and normal dependencies with spaces. Fixes BUKKIT-5418 This change makes the lists of loadbefore, softdependency, and dependency replace the spaces in the names with underscored to reflect the behavior used with names. --- .../org/bukkit/plugin/PluginDescriptionFile.java | 69 ++++++++-------------- .../org/bukkit/plugin/SimplePluginManager.java | 6 +- 2 files changed, 28 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java index 0d1e3a04..18f31bff 100644 --- a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java +++ b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java @@ -169,9 +169,9 @@ public final class PluginDescriptionFile { private String name = null; private String main = null; private String classLoaderOf = null; - private List depend = null; - private List softDepend = null; - private List loadBefore = null; + private List depend = ImmutableList.of(); + private List softDepend = ImmutableList.of(); + private List loadBefore = ImmutableList.of(); private String version = null; private Map> commands = null; private String description = null; @@ -863,47 +863,9 @@ public final class PluginDescriptionFile { classLoaderOf = map.get("class-loader-of").toString(); } - if (map.get("depend") != null) { - ImmutableList.Builder dependBuilder = ImmutableList.builder(); - try { - for (Object dependency : (Iterable) map.get("depend")) { - dependBuilder.add(dependency.toString()); - } - } catch (ClassCastException ex) { - throw new InvalidDescriptionException(ex, "depend is of wrong type"); - } catch (NullPointerException e) { - throw new InvalidDescriptionException(e, "invalid dependency format"); - } - depend = dependBuilder.build(); - } - - if (map.get("softdepend") != null) { - ImmutableList.Builder softDependBuilder = ImmutableList.builder(); - try { - for (Object dependency : (Iterable) map.get("softdepend")) { - softDependBuilder.add(dependency.toString()); - } - } catch (ClassCastException ex) { - throw new InvalidDescriptionException(ex, "softdepend is of wrong type"); - } catch (NullPointerException ex) { - throw new InvalidDescriptionException(ex, "invalid soft-dependency format"); - } - softDepend = softDependBuilder.build(); - } - - if (map.get("loadbefore") != null) { - ImmutableList.Builder loadBeforeBuilder = ImmutableList.builder(); - try { - for (Object predependency : (Iterable) map.get("loadbefore")) { - loadBeforeBuilder.add(predependency.toString()); - } - } catch (ClassCastException ex) { - throw new InvalidDescriptionException(ex, "loadbefore is of wrong type"); - } catch (NullPointerException ex) { - throw new InvalidDescriptionException(ex, "invalid load-before format"); - } - loadBefore = loadBeforeBuilder.build(); - } + depend = makePluginNameList(map, "depend"); + softDepend = makePluginNameList(map, "softdepend"); + loadBefore = makePluginNameList(map, "loadbefore"); if (map.get("database") != null) { try { @@ -973,6 +935,25 @@ public final class PluginDescriptionFile { } } + private static List makePluginNameList(final Map map, final String key) throws InvalidDescriptionException { + final Object value = map.get(key); + if (value == null) { + return ImmutableList.of(); + } + + final ImmutableList.Builder builder = ImmutableList.builder(); + try { + for (final Object entry : (Iterable) value) { + builder.add(entry.toString().replace(' ', '_')); + } + } catch (ClassCastException ex) { + throw new InvalidDescriptionException(ex, key + " is of wrong type"); + } catch (NullPointerException ex) { + throw new InvalidDescriptionException(ex, "invalid " + key + " format"); + } + return builder.build(); + } + private Map saveMap() { Map map = new HashMap(); diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java index 787dcfe5..7d8a281e 100644 --- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -144,7 +144,7 @@ public final class SimplePluginManager implements PluginManager { plugins.put(description.getName(), file); Collection softDependencySet = description.getSoftDepend(); - if (softDependencySet != null) { + if (softDependencySet != null && !softDependencySet.isEmpty()) { if (softDependencies.containsKey(description.getName())) { // Duplicates do not matter, they will be removed together if applicable softDependencies.get(description.getName()).addAll(softDependencySet); @@ -154,12 +154,12 @@ public final class SimplePluginManager implements PluginManager { } Collection dependencySet = description.getDepend(); - if (dependencySet != null) { + if (dependencySet != null && !dependencySet.isEmpty()) { dependencies.put(description.getName(), new LinkedList(dependencySet)); } Collection loadBeforeSet = description.getLoadBefore(); - if (loadBeforeSet != null) { + if (loadBeforeSet != null && !loadBeforeSet.isEmpty()) { for (String loadBeforeTarget : loadBeforeSet) { if (softDependencies.containsKey(loadBeforeTarget)) { softDependencies.get(loadBeforeTarget).add(description.getName()); -- cgit v1.2.3