if (!file.exists()) {
throw new InvalidPluginException(new FileNotFoundException(file.getPath() + " does not exist"));
}
final PluginDescriptionFile description;
try {
description = getPluginDescription(file);
} catch (InvalidDescriptionException ex) {
throw new InvalidPluginException(ex);
}
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().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 + "'");
}
server.getLogger().log(Level.INFO, String.format(
"While loading %s (%s) renamed data folder: `%s' to `%s'",
description.getFullName(),
file,
oldDataFolder,
dataFolder
));
}
if (dataFolder.exists() && !dataFolder.isDirectory()) {
throw new InvalidPluginException(String.format(
"Projected datafolder: `%s' for %s (%s) exists and is not a directory",
dataFolder,
description.getFullName(),
file
));
}
for (final String pluginName : description.getDepend()) {
if (loaders == null) {
throw new UnknownDependencyException(pluginName);
}
PluginClassLoader current = loaders.get(pluginName);
if (current == null) {
throw new UnknownDependencyException(pluginName);
}
}
final PluginClassLoader loader;
try {
loader = new PluginClassLoader(this, getClass().getClassLoader(), description, dataFolder, file);
} catch (InvalidPluginException ex) {
throw ex;
} catch (Throwable ex) {
throw new InvalidPluginException(ex);
}
loaders.put(description.getName(), loader);
return loader.plugin;
}