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.

By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
Bukkit/Spigot 2014-02-15 12:05:20 -06:00
parent bc562b3f5b
commit 181110e567
2 changed files with 24 additions and 42 deletions

View File

@ -1005,4 +1005,12 @@ public final class PluginDescriptionFile {
} }
throw new InvalidDescriptionException(object + " is not properly structured."); throw new InvalidDescriptionException(object + " is not properly structured.");
} }
/**
* @deprecated Internal use
*/
@Deprecated
public String getRawName() {
return rawName;
}
} }

View File

@ -10,7 +10,6 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
@ -42,8 +41,6 @@ import org.bukkit.plugin.TimedRegisteredListener;
import org.bukkit.plugin.UnknownDependencyException; import org.bukkit.plugin.UnknownDependencyException;
import org.yaml.snakeyaml.error.YAMLException; import org.yaml.snakeyaml.error.YAMLException;
import com.google.common.collect.ImmutableList;
/** /**
* Represents a Java plugin loader, allowing plugins in the form of .jar * Represents a Java plugin loader, allowing plugins in the form of .jar
*/ */
@ -62,41 +59,43 @@ public final class JavaPluginLoader implements PluginLoader {
server = instance; server = instance;
} }
public Plugin loadPlugin(File file) throws InvalidPluginException { public Plugin loadPlugin(final File file) throws InvalidPluginException {
Validate.notNull(file, "File cannot be null"); Validate.notNull(file, "File cannot be null");
if (!file.exists()) { if (!file.exists()) {
throw new InvalidPluginException(new FileNotFoundException(file.getPath() + " does not exist")); throw new InvalidPluginException(new FileNotFoundException(file.getPath() + " does not exist"));
} }
PluginDescriptionFile description; final PluginDescriptionFile description;
try { try {
description = getPluginDescription(file); description = getPluginDescription(file);
} catch (InvalidDescriptionException ex) { } catch (InvalidDescriptionException ex) {
throw new InvalidPluginException(ex); throw new InvalidPluginException(ex);
} }
File dataFolder = new File(file.getParentFile(), description.getName()); final File parentFile = file.getParentFile();
File oldDataFolder = getDataFolder(file); final File dataFolder = new File(parentFile, description.getName());
@SuppressWarnings("deprecation")
final File oldDataFolder = new File(parentFile, description.getRawName());
// Found old data folder // Found old data folder
if (dataFolder.equals(oldDataFolder)) { if (dataFolder.equals(oldDataFolder)) {
// They are equal -- nothing needs to be done! // They are equal -- nothing needs to be done!
} else if (dataFolder.isDirectory() && oldDataFolder.isDirectory()) { } else if (dataFolder.isDirectory() && oldDataFolder.isDirectory()) {
server.getLogger().log(Level.INFO, String.format( server.getLogger().warning(String.format(
"While loading %s (%s) found old-data folder: %s next to the new one: %s", "While loading %s (%s) found old-data folder: `%s' next to the new one `%s'",
description.getName(), description.getFullName(),
file, file,
oldDataFolder, oldDataFolder,
dataFolder dataFolder
)); ));
} else if (oldDataFolder.isDirectory() && !dataFolder.exists()) { } else if (oldDataFolder.isDirectory() && !dataFolder.exists()) {
if (!oldDataFolder.renameTo(dataFolder)) { 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( server.getLogger().log(Level.INFO, String.format(
"While loading %s (%s) renamed data folder: '%s' to '%s'", "While loading %s (%s) renamed data folder: `%s' to `%s'",
description.getName(), description.getFullName(),
file, file,
oldDataFolder, oldDataFolder,
dataFolder dataFolder
@ -105,19 +104,14 @@ public final class JavaPluginLoader implements PluginLoader {
if (dataFolder.exists() && !dataFolder.isDirectory()) { if (dataFolder.exists() && !dataFolder.isDirectory()) {
throw new InvalidPluginException(String.format( 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, dataFolder,
description.getName(), description.getFullName(),
file file
)); ));
} }
List<String> depend = description.getDepend(); for (final String pluginName : description.getDepend()) {
if (depend == null) {
depend = ImmutableList.<String>of();
}
for (String pluginName : depend) {
if (loaders == null) { if (loaders == null) {
throw new UnknownDependencyException(pluginName); throw new UnknownDependencyException(pluginName);
} }
@ -128,7 +122,7 @@ public final class JavaPluginLoader implements PluginLoader {
} }
} }
PluginClassLoader loader; final PluginClassLoader loader;
try { try {
loader = new PluginClassLoader(this, getClass().getClassLoader(), description, dataFolder, file); loader = new PluginClassLoader(this, getClass().getClassLoader(), description, dataFolder, file);
} catch (InvalidPluginException ex) { } catch (InvalidPluginException ex) {
@ -142,26 +136,6 @@ public final class JavaPluginLoader implements PluginLoader {
return loader.plugin; 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 { public PluginDescriptionFile getPluginDescription(File file) throws InvalidDescriptionException {
Validate.notNull(file, "File cannot be null"); Validate.notNull(file, "File cannot be null");