diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2019-06-08 22:49:38 +0300 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2019-06-08 22:49:54 +0300 |
commit | e81d9054f721dbd2900fb6190b4326e47dd0f1fd (patch) | |
tree | baf44fb745746f6e8fba09339a6ec679411671ed /pf4j/src | |
parent | 553a0753f59870b29515b05013ad4f1a0ef547d7 (diff) | |
download | pf4j-e81d9054f721dbd2900fb6190b4326e47dd0f1fd.tar.gz pf4j-e81d9054f721dbd2900fb6190b4326e47dd0f1fd.zip |
Convert PluginException in PluginRuntimeException and use unchecked exceptions
Diffstat (limited to 'pf4j/src')
29 files changed, 105 insertions, 103 deletions
diff --git a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java index 6039b51..6bd6170 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java +++ b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java @@ -180,7 +180,7 @@ public abstract class AbstractPluginManager implements PluginManager { } @Override - public String loadPlugin(Path pluginPath) throws PluginException { + public String loadPlugin(Path pluginPath) { if ((pluginPath == null) || Files.notExists(pluginPath)) { throw new IllegalArgumentException(String.format("Specified plugin %s does not exist!", pluginPath)); } @@ -222,7 +222,7 @@ public abstract class AbstractPluginManager implements PluginManager { for (Path pluginPath : pluginPaths) { try { loadPluginFromPath(pluginPath); - } catch (PluginException e) { + } catch (PluginRuntimeException e) { log.error(e.getMessage(), e); } } @@ -230,7 +230,7 @@ public abstract class AbstractPluginManager implements PluginManager { // resolve plugins try { resolvePlugins(); - } catch (PluginException e) { + } catch (PluginRuntimeException e) { log.error(e.getMessage(), e); } } @@ -239,11 +239,11 @@ public abstract class AbstractPluginManager implements PluginManager { * Unload the specified plugin and it's dependents. */ @Override - public boolean unloadPlugin(String pluginId) throws PluginException { + public boolean unloadPlugin(String pluginId) { return unloadPlugin(pluginId, true); } - private boolean unloadPlugin(String pluginId, boolean unloadDependents) throws PluginException { + private boolean unloadPlugin(String pluginId, boolean unloadDependents) { try { if (unloadDependents) { List<String> dependents = dependencyResolver.getDependents(pluginId); @@ -276,7 +276,7 @@ public abstract class AbstractPluginManager implements PluginManager { try { ((Closeable) classLoader).close(); } catch (IOException e) { - throw new PluginException("Cannot close classloader", e); + throw new PluginRuntimeException(e, "Cannot close classloader"); } } } @@ -290,7 +290,7 @@ public abstract class AbstractPluginManager implements PluginManager { } @Override - public boolean deletePlugin(String pluginId) throws PluginException { + public boolean deletePlugin(String pluginId) { checkPluginId(pluginId); PluginWrapper pluginWrapper = getPlugin(pluginId); @@ -344,7 +344,7 @@ public abstract class AbstractPluginManager implements PluginManager { * Start the specified plugin and its dependencies. */ @Override - public PluginState startPlugin(String pluginId) throws PluginException { + public PluginState startPlugin(String pluginId) { checkPluginId(pluginId); PluginWrapper pluginWrapper = getPlugin(pluginId); @@ -400,7 +400,7 @@ public abstract class AbstractPluginManager implements PluginManager { itr.remove(); firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState)); - } catch (PluginException e) { + } catch (PluginRuntimeException e) { log.error(e.getMessage(), e); } } @@ -411,11 +411,11 @@ public abstract class AbstractPluginManager implements PluginManager { * Stop the specified plugin and it's dependents. */ @Override - public PluginState stopPlugin(String pluginId) throws PluginException { + public PluginState stopPlugin(String pluginId) { return stopPlugin(pluginId, true); } - private PluginState stopPlugin(String pluginId, boolean stopDependents) throws PluginException { + private PluginState stopPlugin(String pluginId, boolean stopDependents) { checkPluginId(pluginId); PluginWrapper pluginWrapper = getPlugin(pluginId); @@ -458,7 +458,7 @@ public abstract class AbstractPluginManager implements PluginManager { } @Override - public boolean disablePlugin(String pluginId) throws PluginException { + public boolean disablePlugin(String pluginId) { checkPluginId(pluginId); PluginWrapper pluginWrapper = getPlugin(pluginId); @@ -484,7 +484,7 @@ public abstract class AbstractPluginManager implements PluginManager { } @Override - public boolean enablePlugin(String pluginId) throws PluginException { + public boolean enablePlugin(String pluginId) { checkPluginId(pluginId); PluginWrapper pluginWrapper = getPlugin(pluginId); @@ -560,7 +560,7 @@ public abstract class AbstractPluginManager implements PluginManager { for (ExtensionWrapper extensionWrapper : extensionsWrapper) { try { extensions.add(extensionWrapper.getExtension()); - } catch (PluginException e) { + } catch (PluginRuntimeException e) { log.error("Cannot retrieve extension", e); } } @@ -732,7 +732,7 @@ public abstract class AbstractPluginManager implements PluginManager { return pluginStatusProvider.isPluginDisabled(pluginId); } - protected void resolvePlugins() throws PluginException { + protected void resolvePlugins() { // retrieves the plugins descriptors List<PluginDescriptor> descriptors = new ArrayList<>(); for (PluginWrapper plugin : plugins.values()) { @@ -781,7 +781,7 @@ public abstract class AbstractPluginManager implements PluginManager { } } - protected PluginWrapper loadPluginFromPath(Path pluginPath) throws PluginException { + protected PluginWrapper loadPluginFromPath(Path pluginPath) { // Test for plugin path duplication String pluginId = idForPath(pluginPath); if (pluginId != null) { @@ -799,7 +799,7 @@ public abstract class AbstractPluginManager implements PluginManager { pluginId = pluginDescriptor.getPluginId(); if (plugins.containsKey(pluginId)) { PluginWrapper loadedPlugin = getPlugin(pluginId); - throw new PluginException("There is an already loaded plugin ({}) " + throw new PluginRuntimeException("There is an already loaded plugin ({}) " + "with the same id ({}) as the plugin at path '{}'. Simultaneous loading " + "of plugins with the same PluginId is not currently supported.\n" + "As a workaround you may include PluginVersion and PluginProvider " @@ -867,15 +867,15 @@ public abstract class AbstractPluginManager implements PluginManager { * Override this to change the validation criteria. * * @param descriptor the plugin descriptor to validate - * @throws PluginException if validation fails + * @throws PluginRuntimeException if validation fails */ - protected void validatePluginDescriptor(PluginDescriptor descriptor) throws PluginException { + protected void validatePluginDescriptor(PluginDescriptor descriptor) { if (StringUtils.isNullOrEmpty(descriptor.getPluginId())) { - throw new PluginException("Field 'id' cannot be empty"); + throw new PluginRuntimeException("Field 'id' cannot be empty"); } if (descriptor.getVersion() == null) { - throw new PluginException("Field 'version' cannot be empty"); + throw new PluginRuntimeException("Field 'version' cannot be empty"); } } @@ -925,7 +925,7 @@ public abstract class AbstractPluginManager implements PluginManager { for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) { try { extensions.add(extensionWrapper.getExtension()); - } catch (PluginException e) { + } catch (PluginRuntimeException e) { log.error("Cannot retrieve extension", e); } } diff --git a/pf4j/src/main/java/org/pf4j/BasePluginRepository.java b/pf4j/src/main/java/org/pf4j/BasePluginRepository.java index 64c996b..8c856f8 100644 --- a/pf4j/src/main/java/org/pf4j/BasePluginRepository.java +++ b/pf4j/src/main/java/org/pf4j/BasePluginRepository.java @@ -86,7 +86,7 @@ public class BasePluginRepository implements PluginRepository { } @Override - public boolean deletePluginPath(Path pluginPath) throws PluginException { + public boolean deletePluginPath(Path pluginPath) { if (!filter.accept(pluginPath.toFile())) { return false; } @@ -97,7 +97,7 @@ public class BasePluginRepository implements PluginRepository { } catch (NoSuchFileException e) { return false; // Return false on not found to be compatible with previous API (#135) } catch (IOException e) { - throw new PluginException(e); + throw new PluginRuntimeException(e); } } diff --git a/pf4j/src/main/java/org/pf4j/CompoundPluginDescriptorFinder.java b/pf4j/src/main/java/org/pf4j/CompoundPluginDescriptorFinder.java index 751ad5e..6fe1ff2 100644 --- a/pf4j/src/main/java/org/pf4j/CompoundPluginDescriptorFinder.java +++ b/pf4j/src/main/java/org/pf4j/CompoundPluginDescriptorFinder.java @@ -57,7 +57,7 @@ public class CompoundPluginDescriptorFinder implements PluginDescriptorFinder { } @Override - public PluginDescriptor find(Path pluginPath) throws PluginException { + public PluginDescriptor find(Path pluginPath) { for (PluginDescriptorFinder finder : finders) { if (finder.isApplicable(pluginPath)) { log.debug("'{}' is applicable for plugin '{}'", finder, pluginPath); @@ -81,7 +81,7 @@ public class CompoundPluginDescriptorFinder implements PluginDescriptorFinder { } } - throw new PluginException("No PluginDescriptorFinder for plugin '{}'", pluginPath); + throw new PluginRuntimeException("No PluginDescriptorFinder for plugin '{}'", pluginPath); } } diff --git a/pf4j/src/main/java/org/pf4j/CompoundPluginRepository.java b/pf4j/src/main/java/org/pf4j/CompoundPluginRepository.java index 600f00c..a36b00a 100644 --- a/pf4j/src/main/java/org/pf4j/CompoundPluginRepository.java +++ b/pf4j/src/main/java/org/pf4j/CompoundPluginRepository.java @@ -66,7 +66,7 @@ public class CompoundPluginRepository implements PluginRepository { } @Override - public boolean deletePluginPath(Path pluginPath) throws PluginException { + public boolean deletePluginPath(Path pluginPath) { for (PluginRepository repository : repositories) { if (repository.deletePluginPath(pluginPath)) { return true; diff --git a/pf4j/src/main/java/org/pf4j/DefaultExtensionFactory.java b/pf4j/src/main/java/org/pf4j/DefaultExtensionFactory.java index fbcba27..66e5054 100644 --- a/pf4j/src/main/java/org/pf4j/DefaultExtensionFactory.java +++ b/pf4j/src/main/java/org/pf4j/DefaultExtensionFactory.java @@ -32,12 +32,12 @@ public class DefaultExtensionFactory implements ExtensionFactory { * Creates an extension instance. */ @Override - public <T> T create(Class<T> extensionClass) throws PluginException { + public <T> T create(Class<T> extensionClass) { log.debug("Create instance for extension '{}'", extensionClass.getName()); try { return extensionClass.newInstance(); } catch (Exception e) { - throw new PluginException(e); + throw new PluginRuntimeException(e); } } diff --git a/pf4j/src/main/java/org/pf4j/DefaultPluginManager.java b/pf4j/src/main/java/org/pf4j/DefaultPluginManager.java index cafdb4e..9cad187 100644 --- a/pf4j/src/main/java/org/pf4j/DefaultPluginManager.java +++ b/pf4j/src/main/java/org/pf4j/DefaultPluginManager.java @@ -111,13 +111,14 @@ public class DefaultPluginManager extends AbstractPluginManager { } /** - * Load a plugin from disk. If the path is a zip file, first unpack + * Load a plugin from disk. If the path is a zip file, first unpack. + * * @param pluginPath plugin location on disk * @return PluginWrapper for the loaded plugin or null if not loaded - * @throws PluginException if problems during load + * @throws PluginRuntimeException if problems during load */ @Override - protected PluginWrapper loadPluginFromPath(Path pluginPath) throws PluginException { + protected PluginWrapper loadPluginFromPath(Path pluginPath) { // First unzip any ZIP files try { pluginPath = FileUtils.expandIfZip(pluginPath); diff --git a/pf4j/src/main/java/org/pf4j/DefaultPluginRepository.java b/pf4j/src/main/java/org/pf4j/DefaultPluginRepository.java index 70a4bb9..2fafbc7 100644 --- a/pf4j/src/main/java/org/pf4j/DefaultPluginRepository.java +++ b/pf4j/src/main/java/org/pf4j/DefaultPluginRepository.java @@ -24,7 +24,6 @@ import org.pf4j.util.OrFileFilter; import org.pf4j.util.ZipFileFilter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.pf4j.util.NameFileFilter; import java.io.File; import java.io.FileFilter; @@ -54,7 +53,7 @@ public class DefaultPluginRepository extends BasePluginRepository { } @Override - public boolean deletePluginPath(Path pluginPath) throws PluginException { + public boolean deletePluginPath(Path pluginPath) { FileUtils.optimisticDelete(FileUtils.findWithEnding(pluginPath, ".zip", ".ZIP", ".Zip")); return super.deletePluginPath(pluginPath); } diff --git a/pf4j/src/main/java/org/pf4j/DefaultPluginStatusProvider.java b/pf4j/src/main/java/org/pf4j/DefaultPluginStatusProvider.java index 823a29c..0b88fe8 100644 --- a/pf4j/src/main/java/org/pf4j/DefaultPluginStatusProvider.java +++ b/pf4j/src/main/java/org/pf4j/DefaultPluginStatusProvider.java @@ -66,22 +66,22 @@ public class DefaultPluginStatusProvider implements PluginStatusProvider { } @Override - public void disablePlugin(String pluginId) throws PluginException { + public void disablePlugin(String pluginId) { disabledPlugins.add(pluginId); try { FileUtils.writeLines(disabledPlugins, pluginsRoot.resolve("disabled.txt").toFile()); } catch (IOException e) { - throw new PluginException(e); + throw new PluginRuntimeException(e); } } @Override - public void enablePlugin(String pluginId) throws PluginException { + public void enablePlugin(String pluginId) { disabledPlugins.remove(pluginId); try { FileUtils.writeLines(disabledPlugins, pluginsRoot.resolve("disabled.txt").toFile()); } catch (IOException e) { - throw new PluginException(e); + throw new PluginRuntimeException(e); } } diff --git a/pf4j/src/main/java/org/pf4j/DependencyResolver.java b/pf4j/src/main/java/org/pf4j/DependencyResolver.java index a3aa9f6..45005e2 100644 --- a/pf4j/src/main/java/org/pf4j/DependencyResolver.java +++ b/pf4j/src/main/java/org/pf4j/DependencyResolver.java @@ -272,7 +272,7 @@ public class DependencyResolver { /** * It will be thrown if a cyclic dependency is detected. */ - public static class CyclicDependencyException extends PluginException { + public static class CyclicDependencyException extends PluginRuntimeException { public CyclicDependencyException() { super("Cyclic dependencies"); @@ -283,7 +283,7 @@ public class DependencyResolver { /** * Indicates that the dependencies required were not found. */ - public static class DependenciesNotFoundException extends PluginException { + public static class DependenciesNotFoundException extends PluginRuntimeException { private List<String> dependencies; @@ -302,7 +302,7 @@ public class DependencyResolver { /** * Indicates that some dependencies have wrong version. */ - public static class DependenciesWrongVersionException extends PluginException { + public static class DependenciesWrongVersionException extends PluginRuntimeException { private List<WrongDependencyVersion> dependencies; diff --git a/pf4j/src/main/java/org/pf4j/ExtensionFactory.java b/pf4j/src/main/java/org/pf4j/ExtensionFactory.java index 42b0de8..176c6ff 100644 --- a/pf4j/src/main/java/org/pf4j/ExtensionFactory.java +++ b/pf4j/src/main/java/org/pf4j/ExtensionFactory.java @@ -20,6 +20,6 @@ package org.pf4j; */ public interface ExtensionFactory { - <T> T create(Class<T> extensionClass) throws PluginException; + <T> T create(Class<T> extensionClass); } diff --git a/pf4j/src/main/java/org/pf4j/ExtensionWrapper.java b/pf4j/src/main/java/org/pf4j/ExtensionWrapper.java index 85c5b91..3899d5f 100644 --- a/pf4j/src/main/java/org/pf4j/ExtensionWrapper.java +++ b/pf4j/src/main/java/org/pf4j/ExtensionWrapper.java @@ -32,7 +32,7 @@ public class ExtensionWrapper<T> implements Comparable<ExtensionWrapper<T>> { } @SuppressWarnings("unchecked") - public T getExtension() throws PluginException { + public T getExtension() { if (extension == null) { extension = (T) extensionFactory.create(descriptor.extensionClass); } diff --git a/pf4j/src/main/java/org/pf4j/ManifestPluginDescriptorFinder.java b/pf4j/src/main/java/org/pf4j/ManifestPluginDescriptorFinder.java index 20810ba..650b2d7 100644 --- a/pf4j/src/main/java/org/pf4j/ManifestPluginDescriptorFinder.java +++ b/pf4j/src/main/java/org/pf4j/ManifestPluginDescriptorFinder.java @@ -52,13 +52,13 @@ public class ManifestPluginDescriptorFinder implements PluginDescriptorFinder { } @Override - public PluginDescriptor find(Path pluginPath) throws PluginException { + public PluginDescriptor find(Path pluginPath) { Manifest manifest = readManifest(pluginPath); return createPluginDescriptor(manifest); } - protected Manifest readManifest(Path pluginPath) throws PluginException { + protected Manifest readManifest(Path pluginPath) { if (FileUtils.isJarFile(pluginPath)) { try (JarFile jar = new JarFile(pluginPath.toFile())) { Manifest manifest = jar.getManifest(); @@ -66,24 +66,24 @@ public class ManifestPluginDescriptorFinder implements PluginDescriptorFinder { return manifest; } } catch (IOException e) { - throw new PluginException(e); + throw new PluginRuntimeException(e); } } Path manifestPath = getManifestPath(pluginPath); if (manifestPath == null) { - throw new PluginException("Cannot find the manifest path"); + throw new PluginRuntimeException("Cannot find the manifest path"); } log.debug("Lookup plugin descriptor in '{}'", manifestPath); if (Files.notExists(manifestPath)) { - throw new PluginException("Cannot find '{}' path", manifestPath); + throw new PluginRuntimeException("Cannot find '{}' path", manifestPath); } try (InputStream input = Files.newInputStream(manifestPath)) { return new Manifest(input); } catch (IOException e) { - throw new PluginException(e); + throw new PluginRuntimeException(e); } } diff --git a/pf4j/src/main/java/org/pf4j/Plugin.java b/pf4j/src/main/java/org/pf4j/Plugin.java index b648b64..e3dd449 100644 --- a/pf4j/src/main/java/org/pf4j/Plugin.java +++ b/pf4j/src/main/java/org/pf4j/Plugin.java @@ -60,21 +60,21 @@ public class Plugin { * This method is called by the application when the plugin is started. * See {@link PluginManager#startPlugin(String)}. */ - public void start() throws PluginException { + public void start() { } /** * This method is called by the application when the plugin is stopped. * See {@link PluginManager#stopPlugin(String)}. */ - public void stop() throws PluginException { + public void stop() { } /** * This method is called by the application when the plugin is deleted. * See {@link PluginManager#deletePlugin(String)}. */ - public void delete() throws PluginException { + public void delete() { } } diff --git a/pf4j/src/main/java/org/pf4j/PluginAlreadyLoadedException.java b/pf4j/src/main/java/org/pf4j/PluginAlreadyLoadedException.java index adfd90b..411756c 100644 --- a/pf4j/src/main/java/org/pf4j/PluginAlreadyLoadedException.java +++ b/pf4j/src/main/java/org/pf4j/PluginAlreadyLoadedException.java @@ -20,7 +20,7 @@ import java.nio.file.Path; /** * @author Decebal Suiu */ -public class PluginAlreadyLoadedException extends PluginException { +public class PluginAlreadyLoadedException extends PluginRuntimeException { private final String pluginId; private final Path pluginPath; diff --git a/pf4j/src/main/java/org/pf4j/PluginDescriptorFinder.java b/pf4j/src/main/java/org/pf4j/PluginDescriptorFinder.java index 3b9f600..35185af 100644 --- a/pf4j/src/main/java/org/pf4j/PluginDescriptorFinder.java +++ b/pf4j/src/main/java/org/pf4j/PluginDescriptorFinder.java @@ -29,12 +29,9 @@ public interface PluginDescriptorFinder { /** * Returns true if this finder is applicable to the given {@link Path}. - * - * @param pluginPath - * @return */ boolean isApplicable(Path pluginPath); - PluginDescriptor find(Path pluginPath) throws PluginException; + PluginDescriptor find(Path pluginPath); } diff --git a/pf4j/src/main/java/org/pf4j/PluginManager.java b/pf4j/src/main/java/org/pf4j/PluginManager.java index 0fb9b1f..a937f22 100644 --- a/pf4j/src/main/java/org/pf4j/PluginManager.java +++ b/pf4j/src/main/java/org/pf4j/PluginManager.java @@ -69,11 +69,10 @@ public interface PluginManager { * Load a plugin. * * @param pluginPath the plugin location - * @return the pluginId of the installed plugin as specified in - * its {@linkplain PluginDescriptor metadata} - * @throws PluginException if load of plugin fails + * @return the pluginId of the installed plugin as specified in its {@linkplain PluginDescriptor metadata} + * @throws PluginRuntimeException if something goes wrong */ - String loadPlugin(Path pluginPath) throws PluginException; + String loadPlugin(Path pluginPath); /** * Start all active plugins. @@ -84,8 +83,9 @@ public interface PluginManager { * Start the specified plugin and its dependencies. * * @return the plugin state + * @throws PluginRuntimeException if something goes wrong */ - PluginState startPlugin(String pluginId) throws PluginException; + PluginState startPlugin(String pluginId); /** * Stop all active plugins. @@ -96,40 +96,45 @@ public interface PluginManager { * Stop the specified plugin and its dependencies. * * @return the plugin state + * @throws PluginRuntimeException if something goes wrong */ - PluginState stopPlugin(String pluginId) throws PluginException; + PluginState stopPlugin(String pluginId); /** * Unload a plugin. * * @param pluginId the unique plugin identifier, specified in its metadata * @return true if the plugin was unloaded + * @throws PluginRuntimeException if something goes wrong */ - boolean unloadPlugin(String pluginId) throws PluginException; + boolean unloadPlugin(String pluginId); /** * Disables a plugin from being loaded. * * @param pluginId the unique plugin identifier, specified in its metadata * @return true if plugin is disabled + * @throws PluginRuntimeException if something goes wrong */ - boolean disablePlugin(String pluginId) throws PluginException; + boolean disablePlugin(String pluginId); /** * Enables a plugin that has previously been disabled. * * @param pluginId the unique plugin identifier, specified in its metadata * @return true if plugin is enabled + * @throws PluginRuntimeException if something goes wrong */ - boolean enablePlugin(String pluginId) throws PluginException; + boolean enablePlugin(String pluginId); /** * Deletes a plugin. * * @param pluginId the unique plugin identifier, specified in its metadata * @return true if the plugin was deleted + * @throws PluginRuntimeException if something goes wrong */ - boolean deletePlugin(String pluginId) throws PluginException; + boolean deletePlugin(String pluginId); ClassLoader getPluginClassLoader(String pluginId); @@ -195,7 +200,8 @@ public interface PluginManager { String getSystemVersion(); /** - * Gets the path of the folder where plugins are installed + * Gets the path of the folder where plugins are installed. + * * @return Path of plugins root */ Path getPluginsRoot(); diff --git a/pf4j/src/main/java/org/pf4j/PluginRepository.java b/pf4j/src/main/java/org/pf4j/PluginRepository.java index 9b4298a..6bc2356 100644 --- a/pf4j/src/main/java/org/pf4j/PluginRepository.java +++ b/pf4j/src/main/java/org/pf4j/PluginRepository.java @@ -38,7 +38,8 @@ public interface PluginRepository { * * @param pluginPath the plugin path * @return true if deleted + * @throws PluginRuntimeException if something goes wrong */ - boolean deletePluginPath(Path pluginPath) throws PluginException; + boolean deletePluginPath(Path pluginPath); } diff --git a/pf4j/src/main/java/org/pf4j/PluginException.java b/pf4j/src/main/java/org/pf4j/PluginRuntimeException.java index d1ba6f2..5d5ede9 100644 --- a/pf4j/src/main/java/org/pf4j/PluginException.java +++ b/pf4j/src/main/java/org/pf4j/PluginRuntimeException.java @@ -23,29 +23,25 @@ import org.pf4j.util.StringUtils; * * @author Decebal Suiu */ -public class PluginException extends Exception { +public class PluginRuntimeException extends RuntimeException { - public PluginException() { + public PluginRuntimeException() { super(); } - public PluginException(String message) { + public PluginRuntimeException(String message) { super(message); } - public PluginException(Throwable cause) { + public PluginRuntimeException(Throwable cause) { super(cause); } - public PluginException(String message, Throwable cause) { - super(message, cause); - } - - public PluginException(Throwable cause, String message, Object... args) { + public PluginRuntimeException(Throwable cause, String message, Object... args) { super(StringUtils.format(message, args), cause); } - public PluginException(String message, Object... args) { + public PluginRuntimeException(String message, Object... args) { super(StringUtils.format(message, args)); } diff --git a/pf4j/src/main/java/org/pf4j/PluginStatusProvider.java b/pf4j/src/main/java/org/pf4j/PluginStatusProvider.java index 228575f..46967b2 100644 --- a/pf4j/src/main/java/org/pf4j/PluginStatusProvider.java +++ b/pf4j/src/main/java/org/pf4j/PluginStatusProvider.java @@ -33,14 +33,16 @@ public interface PluginStatusProvider { * Disables a plugin from being loaded. * * @param pluginId the unique plugin identifier, specified in its metadata + * @throws PluginRuntimeException if something goes wrong */ - void disablePlugin(String pluginId) throws PluginException; + void disablePlugin(String pluginId); /** * Enables a plugin that has previously been disabled. * * @param pluginId the unique plugin identifier, specified in its metadata + * @throws PluginRuntimeException if something goes wrong */ - void enablePlugin(String pluginId) throws PluginException; + void enablePlugin(String pluginId); } diff --git a/pf4j/src/main/java/org/pf4j/PropertiesPluginDescriptorFinder.java b/pf4j/src/main/java/org/pf4j/PropertiesPluginDescriptorFinder.java index 31afee9..6789a5f 100644 --- a/pf4j/src/main/java/org/pf4j/PropertiesPluginDescriptorFinder.java +++ b/pf4j/src/main/java/org/pf4j/PropertiesPluginDescriptorFinder.java @@ -63,34 +63,34 @@ public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder } @Override - public PluginDescriptor find(Path pluginPath) throws PluginException { + public PluginDescriptor find(Path pluginPath) { Properties properties = readProperties(pluginPath); return createPluginDescriptor(properties); } - protected Properties readProperties(Path pluginPath) throws PluginException { + protected Properties readProperties(Path pluginPath) { Path propertiesPath = getPropertiesPath(pluginPath, propertiesFileName); if (propertiesPath == null) { - throw new PluginException("Cannot find the properties path"); + throw new PluginRuntimeException("Cannot find the properties path"); } log.debug("Lookup plugin descriptor in '{}'", propertiesPath); if (Files.notExists(propertiesPath)) { - throw new PluginException("Cannot find '{}' path", propertiesPath); + throw new PluginRuntimeException("Cannot find '{}' path", propertiesPath); } Properties properties = new Properties(); try (InputStream input = Files.newInputStream(propertiesPath)) { properties.load(input); } catch (IOException e) { - throw new PluginException(e); + throw new PluginRuntimeException(e); } return properties; } - protected Path getPropertiesPath(Path pluginPath, String propertiesFileName) throws PluginException { + protected Path getPropertiesPath(Path pluginPath, String propertiesFileName) { if (Files.isDirectory(pluginPath)) { return pluginPath.resolve(Paths.get(propertiesFileName)); } else { @@ -98,7 +98,7 @@ public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder try { return FileUtils.getPath(pluginPath, propertiesFileName); } catch (IOException e) { - throw new PluginException(e); + throw new PluginRuntimeException(e); } } } diff --git a/pf4j/src/main/java/org/pf4j/SingletonExtensionFactory.java b/pf4j/src/main/java/org/pf4j/SingletonExtensionFactory.java index 3da97d0..725b9a7 100644 --- a/pf4j/src/main/java/org/pf4j/SingletonExtensionFactory.java +++ b/pf4j/src/main/java/org/pf4j/SingletonExtensionFactory.java @@ -40,7 +40,7 @@ public class SingletonExtensionFactory extends DefaultExtensionFactory { @Override @SuppressWarnings("unchecked") - public <T> T create(Class<T> extensionClass) throws PluginException { + public <T> T create(Class<T> extensionClass) { String extensionClassName = extensionClass.getName(); if (cache.containsKey(extensionClassName)) { return (T) cache.get(extensionClassName); diff --git a/pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java b/pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java index d74bea3..c16839e 100644 --- a/pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java @@ -87,7 +87,7 @@ public class CompoundPluginDescriptorFinderTest { @Test public void testNotFound() { PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder(); - assertThrows(PluginException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3"))); + assertThrows(PluginRuntimeException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3"))); } @Test diff --git a/pf4j/src/test/java/org/pf4j/DefaultExtensionFactoryTest.java b/pf4j/src/test/java/org/pf4j/DefaultExtensionFactoryTest.java index 207c178..150828f 100644 --- a/pf4j/src/test/java/org/pf4j/DefaultExtensionFactoryTest.java +++ b/pf4j/src/test/java/org/pf4j/DefaultExtensionFactoryTest.java @@ -45,7 +45,7 @@ public class DefaultExtensionFactoryTest { * Test of create method, of class DefaultExtensionFactory. */ @Test - public void testCreate() throws PluginException { + public void testCreate() { assertNotNull(extensionFactory.create(TestExtension.class)); } @@ -54,7 +54,7 @@ public class DefaultExtensionFactoryTest { */ @Test public void testCreateFailConstructor() { - assertThrows(PluginException.class, () -> extensionFactory.create(FailTestExtension.class)); + assertThrows(PluginRuntimeException.class, () -> extensionFactory.create(FailTestExtension.class)); } } diff --git a/pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java b/pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java index ced9b4e..8cb9b27 100644 --- a/pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java +++ b/pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java @@ -65,24 +65,24 @@ public class DefaultPluginManagerTest { } @Test - public void validateOK() throws PluginException { + public void validateOK() { pluginManager.validatePluginDescriptor(pluginDescriptor); } @Test public void validateFailsOnId() { pluginDescriptor.setPluginId(""); - assertThrows(PluginException.class, () -> pluginManager.validatePluginDescriptor(pluginDescriptor)); + assertThrows(PluginRuntimeException.class, () -> pluginManager.validatePluginDescriptor(pluginDescriptor)); } @Test public void validateFailsOnVersion() { pluginDescriptor.setPluginVersion(null); - assertThrows(PluginException.class, () -> pluginManager.validatePluginDescriptor(pluginDescriptor)); + assertThrows(PluginRuntimeException.class, () -> pluginManager.validatePluginDescriptor(pluginDescriptor)); } @Test - public void validateNoPluginClass() throws PluginException { + public void validateNoPluginClass() { pluginManager.validatePluginDescriptor(pluginDescriptor); assertEquals(Plugin.class.getName(), pluginDescriptor.getPluginClass()); } diff --git a/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java b/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java index 3474aa6..c564543 100644 --- a/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java +++ b/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java @@ -67,7 +67,7 @@ public class DefaultPluginRepositoryTest { * Test of {@link DefaultPluginRepository#deletePluginPath(Path)} method. */ @Test - public void testDeletePluginPath() throws PluginException { + public void testDeletePluginPath() { PluginRepository repository = new DefaultPluginRepository(pluginsPath); assertTrue(Files.exists(pluginsPath.resolve("plugin-1.zip"))); diff --git a/pf4j/src/test/java/org/pf4j/LoadPluginsTest.java b/pf4j/src/test/java/org/pf4j/LoadPluginsTest.java index d2a7e25..e3dac02 100644 --- a/pf4j/src/test/java/org/pf4j/LoadPluginsTest.java +++ b/pf4j/src/test/java/org/pf4j/LoadPluginsTest.java @@ -102,7 +102,7 @@ public class LoadPluginsTest { // Verify the second plugin is not loaded as it has the same metadata pluginManager.loadPluginFromPath(plugin2.path()); fail("Expected loadPluginFromPath to fail"); - } catch (PluginException e) { + } catch (PluginRuntimeException e) { // Check the path of the loaded plugin remains the same PluginWrapper loadedPlugin = pluginManager.getPlugin(pluginId); assertThat(loadedPlugin.getPluginPath(), equalTo(loadedPlugin1Path)); @@ -141,7 +141,7 @@ public class LoadPluginsTest { // Verify the second plugin is not loaded as it has the same pluginId pluginManager.loadPluginFromPath(plugin2.path()); fail("Expected loadPluginFromPath to fail"); - } catch (PluginException e) { + } catch (PluginRuntimeException e) { // Check the path and version of the loaded plugin remain the same PluginWrapper loadedPlugin = pluginManager.getPlugin(pluginId); assertThat(loadedPlugin.getPluginPath(), equalTo(loadedPlugin1Path)); diff --git a/pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java b/pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java index 2ffe01b..468f2fb 100644 --- a/pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java @@ -107,7 +107,7 @@ public class ManifestPluginDescriptorFinderTest { @Test public void testFindNotFound() { PluginDescriptorFinder descriptorFinder = new ManifestPluginDescriptorFinder(); - assertThrows(PluginException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3"))); + assertThrows(PluginRuntimeException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3"))); } private Manifest getPlugin1Manifest() { diff --git a/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java b/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java index 1f51e95..bc91a7f 100644 --- a/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java @@ -104,7 +104,7 @@ public class PropertiesPluginDescriptorFinderTest { @Test public void testNotFound() { PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder(); - assertThrows(PluginException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3"))); + assertThrows(PluginRuntimeException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3"))); } private Properties getPlugin1Properties() { diff --git a/pf4j/src/test/java/org/pf4j/SingletonExtensionFactoryTest.java b/pf4j/src/test/java/org/pf4j/SingletonExtensionFactoryTest.java index 97e98cf..80e7ab0 100644 --- a/pf4j/src/test/java/org/pf4j/SingletonExtensionFactoryTest.java +++ b/pf4j/src/test/java/org/pf4j/SingletonExtensionFactoryTest.java @@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertSame; public class SingletonExtensionFactoryTest { @Test - public void create() throws PluginException { + public void create() { ExtensionFactory extensionFactory = new SingletonExtensionFactory(); Object extensionOne = extensionFactory.create(TestExtension.class); Object extensionTwo = extensionFactory.create(TestExtension.class); @@ -36,7 +36,7 @@ public class SingletonExtensionFactoryTest { } @Test - public void createNewEachTime() throws PluginException { + public void createNewEachTime() { ExtensionFactory extensionFactory = new SingletonExtensionFactory(FailTestExtension.class.getName()); Object extensionOne = extensionFactory.create(TestExtension.class); Object extensionTwo = extensionFactory.create(TestExtension.class); |