summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorWesley Wolfe <weswolf@aol.com>2014-02-15 12:05:20 -0600
committerWesley Wolfe <weswolf@aol.com>2014-02-15 12:16:07 -0600
commit3e3373e224b820fead121aa40e59ebeca8d5aff9 (patch)
treed7d2fc03669c4990f29d0786f3513d344a7a2e8b /src/main
parenta41b54d1fb3ac8fcc5adea46cf61fdeaee5befb8 (diff)
downloadbukkit-3e3373e224b820fead121aa40e59ebeca8d5aff9.tar
bukkit-3e3373e224b820fead121aa40e59ebeca8d5aff9.tar.gz
bukkit-3e3373e224b820fead121aa40e59ebeca8d5aff9.tar.lz
bukkit-3e3373e224b820fead121aa40e59ebeca8d5aff9.tar.xz
bukkit-3e3373e224b820fead121aa40e59ebeca8d5aff9.zip
Update data folder migration for spaces in plugin names. Fixes BUKKIT-5417
This change drops the previous plugin data folder migration based on the plugin's file name, and adapts the migration to now instead consider plugins that have spaces in their original name.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/bukkit/plugin/PluginDescriptionFile.java8
-rw-r--r--src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java58
2 files changed, 24 insertions, 42 deletions
diff --git a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java
index 96749147..cfd4b71b 100644
--- a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java
+++ b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java
@@ -1005,4 +1005,12 @@ public final class PluginDescriptionFile {
}
throw new InvalidDescriptionException(object + " is not properly structured.");
}
+
+ /**
+ * @deprecated Internal use
+ */
+ @Deprecated
+ public String getRawName() {
+ return rawName;
+ }
}
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
index 57681dc4..b178c0d1 100644
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
@@ -10,7 +10,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
@@ -42,8 +41,6 @@ import org.bukkit.plugin.TimedRegisteredListener;
import org.bukkit.plugin.UnknownDependencyException;
import org.yaml.snakeyaml.error.YAMLException;
-import com.google.common.collect.ImmutableList;
-
/**
* Represents a Java plugin loader, allowing plugins in the form of .jar
*/
@@ -62,41 +59,43 @@ public final class JavaPluginLoader implements PluginLoader {
server = instance;
}
- public Plugin loadPlugin(File file) throws InvalidPluginException {
+ public Plugin loadPlugin(final File file) throws InvalidPluginException {
Validate.notNull(file, "File cannot be null");
if (!file.exists()) {
throw new InvalidPluginException(new FileNotFoundException(file.getPath() + " does not exist"));
}
- PluginDescriptionFile description;
+ final PluginDescriptionFile description;
try {
description = getPluginDescription(file);
} catch (InvalidDescriptionException ex) {
throw new InvalidPluginException(ex);
}
- File dataFolder = new File(file.getParentFile(), description.getName());
- File oldDataFolder = getDataFolder(file);
+ final File parentFile = file.getParentFile();
+ final File dataFolder = new File(parentFile, description.getName());
+ @SuppressWarnings("deprecation")
+ final File oldDataFolder = new File(parentFile, description.getRawName());
// Found old data folder
if (dataFolder.equals(oldDataFolder)) {
// They are equal -- nothing needs to be done!
} else if (dataFolder.isDirectory() && oldDataFolder.isDirectory()) {
- server.getLogger().log(Level.INFO, String.format(
- "While loading %s (%s) found old-data folder: %s next to the new one: %s",
- description.getName(),
+ server.getLogger().warning(String.format(
+ "While loading %s (%s) found old-data folder: `%s' next to the new one `%s'",
+ description.getFullName(),
file,
oldDataFolder,
dataFolder
));
} else if (oldDataFolder.isDirectory() && !dataFolder.exists()) {
if (!oldDataFolder.renameTo(dataFolder)) {
- throw new InvalidPluginException("Unable to rename old data folder: '" + oldDataFolder + "' to: '" + dataFolder + "'");
+ throw new InvalidPluginException("Unable to rename old data folder: `" + oldDataFolder + "' to: `" + dataFolder + "'");
}
server.getLogger().log(Level.INFO, String.format(
- "While loading %s (%s) renamed data folder: '%s' to '%s'",
- description.getName(),
+ "While loading %s (%s) renamed data folder: `%s' to `%s'",
+ description.getFullName(),
file,
oldDataFolder,
dataFolder
@@ -105,19 +104,14 @@ public final class JavaPluginLoader implements PluginLoader {
if (dataFolder.exists() && !dataFolder.isDirectory()) {
throw new InvalidPluginException(String.format(
- "Projected datafolder: '%s' for %s (%s) exists and is not a directory",
+ "Projected datafolder: `%s' for %s (%s) exists and is not a directory",
dataFolder,
- description.getName(),
+ description.getFullName(),
file
));
}
- List<String> depend = description.getDepend();
- if (depend == null) {
- depend = ImmutableList.<String>of();
- }
-
- for (String pluginName : depend) {
+ for (final String pluginName : description.getDepend()) {
if (loaders == null) {
throw new UnknownDependencyException(pluginName);
}
@@ -128,7 +122,7 @@ public final class JavaPluginLoader implements PluginLoader {
}
}
- PluginClassLoader loader;
+ final PluginClassLoader loader;
try {
loader = new PluginClassLoader(this, getClass().getClassLoader(), description, dataFolder, file);
} catch (InvalidPluginException ex) {
@@ -142,26 +136,6 @@ public final class JavaPluginLoader implements PluginLoader {
return loader.plugin;
}
- private File getDataFolder(File file) {
- File dataFolder = null;
-
- String filename = file.getName();
- int index = file.getName().lastIndexOf(".");
-
- if (index != -1) {
- String name = filename.substring(0, index);
-
- dataFolder = new File(file.getParentFile(), name);
- } else {
- // This is if there is no extension, which should not happen
- // Using _ to prevent name collision
-
- dataFolder = new File(file.getParentFile(), filename + "_");
- }
-
- return dataFolder;
- }
-
public PluginDescriptionFile getPluginDescription(File file) throws InvalidDescriptionException {
Validate.notNull(file, "File cannot be null");