[Bleeding] Exception cleanup. Addresses BUKKIT-774
This commit is contained in:
parent
db57cff67c
commit
332e8cad5d
@ -181,13 +181,7 @@ public class YamlConfiguration extends FileConfiguration {
|
|||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
|
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
|
||||||
} catch (InvalidConfigurationException ex) {
|
} catch (InvalidConfigurationException ex) {
|
||||||
if (ex.getCause() instanceof YAMLException) {
|
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file , ex);
|
||||||
Bukkit.getLogger().severe("Config file " + file + " isn't valid! " + ex.getCause());
|
|
||||||
} else if ((ex.getCause() == null) || (ex.getCause() instanceof ClassCastException)) {
|
|
||||||
Bukkit.getLogger().severe("Config file " + file + " isn't valid!");
|
|
||||||
} else {
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file + ": " + ex.getCause().getClass(), ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
@ -213,15 +207,9 @@ public class YamlConfiguration extends FileConfiguration {
|
|||||||
try {
|
try {
|
||||||
config.load(stream);
|
config.load(stream);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration", ex);
|
Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration from stream", ex);
|
||||||
} catch (InvalidConfigurationException ex) {
|
} catch (InvalidConfigurationException ex) {
|
||||||
if (ex.getCause() instanceof YAMLException) {
|
Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration from stream", ex);
|
||||||
Bukkit.getLogger().severe("Config file isn't valid! " + ex.getCause());
|
|
||||||
} else if ((ex.getCause() == null) || (ex.getCause() instanceof ClassCastException)) {
|
|
||||||
Bukkit.getLogger().severe("Config file isn't valid!");
|
|
||||||
} else {
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration: " + ex.getCause().getClass(), ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
@ -4,7 +4,7 @@ package org.bukkit.plugin;
|
|||||||
* Thrown when attempting to load an invalid PluginDescriptionFile
|
* Thrown when attempting to load an invalid PluginDescriptionFile
|
||||||
*/
|
*/
|
||||||
public class InvalidDescriptionException extends Exception {
|
public class InvalidDescriptionException extends Exception {
|
||||||
private static final long serialVersionUID = 5721389122281775895L;
|
private static final long serialVersionUID = 5721389122281775896L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new InvalidDescriptionException based on the given Exception
|
* Constructs a new InvalidDescriptionException based on the given Exception
|
||||||
@ -13,16 +13,16 @@ public class InvalidDescriptionException extends Exception {
|
|||||||
* @param cause Exception that triggered this Exception
|
* @param cause Exception that triggered this Exception
|
||||||
*/
|
*/
|
||||||
public InvalidDescriptionException(final Throwable cause, final String message) {
|
public InvalidDescriptionException(final Throwable cause, final String message) {
|
||||||
super(message + (cause != null ? ": " + cause.getMessage() : ""), cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new InvalidDescriptionException based on the given Exception
|
* Constructs a new InvalidDescriptionException based on the given Exception
|
||||||
*
|
*
|
||||||
* @param throwable Exception that triggered this Exception
|
* @param cause Exception that triggered this Exception
|
||||||
*/
|
*/
|
||||||
public InvalidDescriptionException(final Throwable cause) {
|
public InvalidDescriptionException(final Throwable cause) {
|
||||||
this(cause, "Invalid plugin.yml");
|
super("Invalid plugin.yml", cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,13 +31,13 @@ public class InvalidDescriptionException extends Exception {
|
|||||||
* @param message Brief message explaining the cause of the exception
|
* @param message Brief message explaining the cause of the exception
|
||||||
*/
|
*/
|
||||||
public InvalidDescriptionException(final String message) {
|
public InvalidDescriptionException(final String message) {
|
||||||
this(null, message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new InvalidDescriptionException
|
* Constructs a new InvalidDescriptionException
|
||||||
*/
|
*/
|
||||||
public InvalidDescriptionException() {
|
public InvalidDescriptionException() {
|
||||||
this(null, "Invalid plugin.yml");
|
super("Invalid plugin.yml");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ package org.bukkit.plugin;
|
|||||||
* Thrown when attempting to load an invalid Plugin file
|
* Thrown when attempting to load an invalid Plugin file
|
||||||
*/
|
*/
|
||||||
public class InvalidPluginException extends Exception {
|
public class InvalidPluginException extends Exception {
|
||||||
private static final long serialVersionUID = -8242141640709409543L;
|
private static final long serialVersionUID = -8242141640709409544L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new InvalidPluginException based on the given Exception
|
* Constructs a new InvalidPluginException based on the given Exception
|
||||||
@ -12,13 +12,32 @@ public class InvalidPluginException extends Exception {
|
|||||||
* @param cause Exception that triggered this Exception
|
* @param cause Exception that triggered this Exception
|
||||||
*/
|
*/
|
||||||
public InvalidPluginException(final Throwable cause) {
|
public InvalidPluginException(final Throwable cause) {
|
||||||
super("Invalid plugin" + (cause != null ? ": " + cause.getMessage() : ""), cause);
|
super(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new InvalidPluginException
|
* Constructs a new InvalidPluginException
|
||||||
*/
|
*/
|
||||||
public InvalidPluginException() {
|
public InvalidPluginException() {
|
||||||
this(null);
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new InvalidPluginException with the specified detail message and cause.
|
||||||
|
*
|
||||||
|
* @param message the detail message (which is saved for later retrieval by the getMessage() method).
|
||||||
|
* @param cause the cause (which is saved for later retrieval by the getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
|
||||||
|
*/
|
||||||
|
public InvalidPluginException(final String message, final Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new InvalidPluginException with the specified detail message
|
||||||
|
*
|
||||||
|
* @param the detail message. The detail message is saved for later retrieval by the getMessage() method.
|
||||||
|
*/
|
||||||
|
public InvalidPluginException(final String message) {
|
||||||
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,20 +21,18 @@ public interface PluginLoader {
|
|||||||
* @return Plugin that was contained in the specified file, or null if
|
* @return Plugin that was contained in the specified file, or null if
|
||||||
* unsuccessful
|
* unsuccessful
|
||||||
* @throws InvalidPluginException Thrown when the specified file is not a plugin
|
* @throws InvalidPluginException Thrown when the specified file is not a plugin
|
||||||
* @throws InvalidDescriptionException If the plugin description file was invalid
|
|
||||||
* @throws UnknownDependencyException If a required dependency could not be found
|
* @throws UnknownDependencyException If a required dependency could not be found
|
||||||
*/
|
*/
|
||||||
public Plugin loadPlugin(File file) throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException;
|
public Plugin loadPlugin(File file) throws InvalidPluginException, UnknownDependencyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a PluginDescriptionFile from the specified file
|
* Loads a PluginDescriptionFile from the specified file
|
||||||
*
|
*
|
||||||
* @param file File to attempt to load from
|
* @param file File to attempt to load from
|
||||||
* @return A new PluginDescriptionFile loaded from the plugin.yml in the specified file
|
* @return A new PluginDescriptionFile loaded from the plugin.yml in the specified file
|
||||||
* @throws InvalidPluginException If when the specified file does not contain a plugin description file
|
|
||||||
* @throws InvalidDescriptionException If the plugin description file could not be created
|
* @throws InvalidDescriptionException If the plugin description file could not be created
|
||||||
*/
|
*/
|
||||||
public PluginDescriptionFile getPluginDescription(File file) throws InvalidPluginException, InvalidDescriptionException;
|
public PluginDescriptionFile getPluginDescription(File file) throws InvalidDescriptionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all filename filters expected by this PluginLoader
|
* Returns a list of all filename filters expected by this PluginLoader
|
||||||
|
@ -131,11 +131,8 @@ public final class SimplePluginManager implements PluginManager {
|
|||||||
PluginDescriptionFile description = null;
|
PluginDescriptionFile description = null;
|
||||||
try {
|
try {
|
||||||
description = loader.getPluginDescription(file);
|
description = loader.getPluginDescription(file);
|
||||||
} catch (InvalidPluginException ex) {
|
|
||||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': " + ex.getMessage(), ex);
|
|
||||||
continue;
|
|
||||||
} catch (InvalidDescriptionException ex) {
|
} catch (InvalidDescriptionException ex) {
|
||||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': " + ex.getMessage(), ex);
|
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'", ex);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +176,7 @@ public final class SimplePluginManager implements PluginManager {
|
|||||||
|
|
||||||
server.getLogger().log(
|
server.getLogger().log(
|
||||||
Level.SEVERE,
|
Level.SEVERE,
|
||||||
"Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': ",
|
"Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'",
|
||||||
new UnknownDependencyException(dependency));
|
new UnknownDependencyException(dependency));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -216,11 +213,7 @@ public final class SimplePluginManager implements PluginManager {
|
|||||||
loadedPlugins.add(plugin);
|
loadedPlugins.add(plugin);
|
||||||
continue;
|
continue;
|
||||||
} catch (InvalidPluginException ex) {
|
} catch (InvalidPluginException ex) {
|
||||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': ", ex.getCause());
|
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'", ex);
|
||||||
} catch (InvalidDescriptionException ex) {
|
|
||||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': " + ex.getMessage(), ex);
|
|
||||||
} catch (UnknownDependencyException ex) {
|
|
||||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': " + ex.getMessage(), ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,11 +238,7 @@ public final class SimplePluginManager implements PluginManager {
|
|||||||
loadedPlugins.add(plugin);
|
loadedPlugins.add(plugin);
|
||||||
break;
|
break;
|
||||||
} catch (InvalidPluginException ex) {
|
} catch (InvalidPluginException ex) {
|
||||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': ", ex.getCause());
|
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'", ex);
|
||||||
} catch (InvalidDescriptionException ex) {
|
|
||||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': " + ex.getMessage(), ex);
|
|
||||||
} catch (UnknownDependencyException ex) {
|
|
||||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': " + ex.getMessage(), ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -279,10 +268,9 @@ public final class SimplePluginManager implements PluginManager {
|
|||||||
* @param file File containing the plugin to load
|
* @param file File containing the plugin to load
|
||||||
* @return The Plugin loaded, or null if it was invalid
|
* @return The Plugin loaded, or null if it was invalid
|
||||||
* @throws InvalidPluginException Thrown when the specified file is not a valid plugin
|
* @throws InvalidPluginException Thrown when the specified file is not a valid plugin
|
||||||
* @throws InvalidDescriptionException Thrown when the specified file contains an invalid description
|
|
||||||
* @throws UnknownDependencyException If a required dependency could not be found
|
* @throws UnknownDependencyException If a required dependency could not be found
|
||||||
*/
|
*/
|
||||||
public synchronized Plugin loadPlugin(File file) throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException {
|
public synchronized Plugin loadPlugin(File file) throws InvalidPluginException, UnknownDependencyException {
|
||||||
Validate.notNull(file, "File cannot be null");
|
Validate.notNull(file, "File cannot be null");
|
||||||
|
|
||||||
checkUpdate(file);
|
checkUpdate(file);
|
||||||
@ -375,7 +363,7 @@ public final class SimplePluginManager implements PluginManager {
|
|||||||
try {
|
try {
|
||||||
plugin.getPluginLoader().enablePlugin(plugin);
|
plugin.getPluginLoader().enablePlugin(plugin);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?): " + ex.getMessage(), ex);
|
server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
HandlerList.bakeAll();
|
HandlerList.bakeAll();
|
||||||
@ -393,32 +381,32 @@ public final class SimplePluginManager implements PluginManager {
|
|||||||
try {
|
try {
|
||||||
plugin.getPluginLoader().disablePlugin(plugin);
|
plugin.getPluginLoader().disablePlugin(plugin);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while disabling " + plugin.getDescription().getFullName() + " (Is it up to date?): " + ex.getMessage(), ex);
|
server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while disabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
server.getScheduler().cancelTasks(plugin);
|
server.getScheduler().cancelTasks(plugin);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while cancelling tasks for " + plugin.getDescription().getFullName() + " (Is it up to date?): " + ex.getMessage(), ex);
|
server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while cancelling tasks for " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
server.getServicesManager().unregisterAll(plugin);
|
server.getServicesManager().unregisterAll(plugin);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while unregistering services for " + plugin.getDescription().getFullName() + " (Is it up to date?): " + ex.getMessage(), ex);
|
server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while unregistering services for " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HandlerList.unregisterAll(plugin);
|
HandlerList.unregisterAll(plugin);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while unregistering events for " + plugin.getDescription().getFullName() + " (Is it up to date?): " + ex.getMessage(), ex);
|
server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while unregistering events for " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
server.getMessenger().unregisterIncomingPluginChannel(plugin);
|
server.getMessenger().unregisterIncomingPluginChannel(plugin);
|
||||||
server.getMessenger().unregisterOutgoingPluginChannel(plugin);
|
server.getMessenger().unregisterOutgoingPluginChannel(plugin);
|
||||||
} catch(Throwable ex) {
|
} catch(Throwable ex) {
|
||||||
server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while unregistering plugin channels for " + plugin.getDescription().getFullName() + " (Is it up to date?): " + ex.getMessage(), ex);
|
server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while unregistering plugin channels for " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,17 @@ package org.bukkit.plugin;
|
|||||||
/**
|
/**
|
||||||
* Thrown when attempting to load an invalid Plugin file
|
* Thrown when attempting to load an invalid Plugin file
|
||||||
*/
|
*/
|
||||||
public class UnknownDependencyException extends Exception {
|
public class UnknownDependencyException extends RuntimeException {
|
||||||
|
|
||||||
private static final long serialVersionUID = 5721389371901775894L;
|
private static final long serialVersionUID = 5721389371901775895L;
|
||||||
private final Throwable cause;
|
|
||||||
private final String message;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new UnknownDependencyException based on the given Exception
|
* Constructs a new UnknownDependencyException based on the given Exception
|
||||||
*
|
*
|
||||||
* @param throwable Exception that triggered this Exception
|
* @param throwable Exception that triggered this Exception
|
||||||
*/
|
*/
|
||||||
public UnknownDependencyException(Throwable throwable) {
|
public UnknownDependencyException(final Throwable throwable) {
|
||||||
this(throwable, "Unknown dependency");
|
super(throwable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,7 +22,7 @@ public class UnknownDependencyException extends Exception {
|
|||||||
* @param message Brief message explaining the cause of the exception
|
* @param message Brief message explaining the cause of the exception
|
||||||
*/
|
*/
|
||||||
public UnknownDependencyException(final String message) {
|
public UnknownDependencyException(final String message) {
|
||||||
this(null, message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,29 +32,13 @@ public class UnknownDependencyException extends Exception {
|
|||||||
* @param throwable Exception that triggered this Exception
|
* @param throwable Exception that triggered this Exception
|
||||||
*/
|
*/
|
||||||
public UnknownDependencyException(final Throwable throwable, final String message) {
|
public UnknownDependencyException(final Throwable throwable, final String message) {
|
||||||
this.cause = null;
|
super(message, throwable);
|
||||||
this.message = message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new UnknownDependencyException
|
* Constructs a new UnknownDependencyException
|
||||||
*/
|
*/
|
||||||
public UnknownDependencyException() {
|
public UnknownDependencyException() {
|
||||||
this(null, "Unknown dependency");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If applicable, returns the Exception that triggered this Exception
|
|
||||||
*
|
|
||||||
* @return Inner exception, or null if one does not exist
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Throwable getCause() {
|
|
||||||
return cause;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
package org.bukkit.plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when attempting to load an invalid Plugin file
|
|
||||||
*/
|
|
||||||
public class UnknownSoftDependencyException extends UnknownDependencyException {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 5721389371901775899L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new UnknownSoftDependencyException based on the given Exception
|
|
||||||
*
|
|
||||||
* @param throwable Exception that triggered this Exception
|
|
||||||
*/
|
|
||||||
public UnknownSoftDependencyException(Throwable throwable) {
|
|
||||||
this(throwable, "Unknown soft dependency");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new UnknownSoftDependencyException with the given message
|
|
||||||
*
|
|
||||||
* @param message Brief message explaining the cause of the exception
|
|
||||||
*/
|
|
||||||
public UnknownSoftDependencyException(final String message) {
|
|
||||||
this(null, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new UnknownSoftDependencyException based on the given Exception
|
|
||||||
*
|
|
||||||
* @param message Brief message explaining the cause of the exception
|
|
||||||
* @param throwable Exception that triggered this Exception
|
|
||||||
*/
|
|
||||||
public UnknownSoftDependencyException(final Throwable throwable, final String message) {
|
|
||||||
super(throwable, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new UnknownSoftDependencyException
|
|
||||||
*/
|
|
||||||
public UnknownSoftDependencyException() {
|
|
||||||
this(null, "Unknown dependency");
|
|
||||||
}
|
|
||||||
}
|
|
@ -54,14 +54,19 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Plugin loadPlugin(File file) throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException {
|
public Plugin loadPlugin(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(String.format("%s does not exist", file.getPath())));
|
throw new InvalidPluginException(new FileNotFoundException(file.getPath() + " does not exist"));
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginDescriptionFile description = getPluginDescription(file);
|
PluginDescriptionFile description;
|
||||||
|
try {
|
||||||
|
description = getPluginDescription(file);
|
||||||
|
} catch (InvalidDescriptionException ex) {
|
||||||
|
throw new InvalidPluginException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
File dataFolder = new File(file.getParentFile(), description.getName());
|
File dataFolder = new File(file.getParentFile(), description.getName());
|
||||||
File oldDataFolder = getDataFolder(file);
|
File oldDataFolder = getDataFolder(file);
|
||||||
@ -79,7 +84,7 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
));
|
));
|
||||||
} else if (oldDataFolder.isDirectory() && !dataFolder.exists()) {
|
} else if (oldDataFolder.isDirectory() && !dataFolder.exists()) {
|
||||||
if (!oldDataFolder.renameTo(dataFolder)) {
|
if (!oldDataFolder.renameTo(dataFolder)) {
|
||||||
throw new InvalidPluginException(new Exception("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'",
|
||||||
@ -91,12 +96,12 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dataFolder.exists() && !dataFolder.isDirectory()) {
|
if (dataFolder.exists() && !dataFolder.isDirectory()) {
|
||||||
throw new InvalidPluginException(new Exception(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.getName(),
|
||||||
file
|
file
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<String> depend;
|
ArrayList<String> depend;
|
||||||
@ -155,7 +160,7 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin loadPlugin(File file, boolean ignoreSoftDependencies) throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException {
|
public Plugin loadPlugin(File file, boolean ignoreSoftDependencies) throws InvalidPluginException {
|
||||||
return loadPlugin(file);
|
return loadPlugin(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +184,7 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
return dataFolder;
|
return dataFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginDescriptionFile getPluginDescription(File file) throws InvalidDescriptionException, InvalidPluginException {
|
public PluginDescriptionFile getPluginDescription(File file) throws InvalidDescriptionException {
|
||||||
Validate.notNull(file, "File cannot be null");
|
Validate.notNull(file, "File cannot be null");
|
||||||
|
|
||||||
JarFile jar = null;
|
JarFile jar = null;
|
||||||
@ -190,7 +195,7 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
JarEntry entry = jar.getJarEntry("plugin.yml");
|
JarEntry entry = jar.getJarEntry("plugin.yml");
|
||||||
|
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
throw new InvalidPluginException(new FileNotFoundException("Jar does not contain plugin.yml"));
|
throw new InvalidDescriptionException(new FileNotFoundException("Jar does not contain plugin.yml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
stream = jar.getInputStream(entry);
|
stream = jar.getInputStream(entry);
|
||||||
@ -198,7 +203,7 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
return new PluginDescriptionFile(stream);
|
return new PluginDescriptionFile(stream);
|
||||||
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new InvalidPluginException(ex);
|
throw new InvalidDescriptionException(ex);
|
||||||
} catch (YAMLException ex) {
|
} catch (YAMLException ex) {
|
||||||
throw new InvalidDescriptionException(ex);
|
throw new InvalidDescriptionException(ex);
|
||||||
} finally {
|
} finally {
|
||||||
@ -337,7 +342,7 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
try {
|
try {
|
||||||
jPlugin.setEnabled(true);
|
jPlugin.setEnabled(true);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
server.getLogger().log(Level.SEVERE, "Error occurred while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?): " + ex.getMessage(), ex);
|
server.getLogger().log(Level.SEVERE, "Error occurred while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perhaps abort here, rather than continue going, but as it stands,
|
// Perhaps abort here, rather than continue going, but as it stands,
|
||||||
@ -363,7 +368,7 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
try {
|
try {
|
||||||
jPlugin.setEnabled(false);
|
jPlugin.setEnabled(false);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
server.getLogger().log(Level.SEVERE, "Error occurred while disabling " + plugin.getDescription().getFullName() + " (Is it up to date?): " + ex.getMessage(), ex);
|
server.getLogger().log(Level.SEVERE, "Error occurred while disabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
loaders.remove(jPlugin.getDescription().getName());
|
loaders.remove(jPlugin.getDescription().getName());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user