]> source.dussan.org Git - pf4j.git/commitdiff
Convert PluginException in PluginRuntimeException and use unchecked exceptions
authorDecebal Suiu <decebal.suiu@gmail.com>
Sat, 8 Jun 2019 19:49:38 +0000 (22:49 +0300)
committerDecebal Suiu <decebal.suiu@gmail.com>
Sat, 8 Jun 2019 19:49:54 +0000 (22:49 +0300)
30 files changed:
pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
pf4j/src/main/java/org/pf4j/BasePluginRepository.java
pf4j/src/main/java/org/pf4j/CompoundPluginDescriptorFinder.java
pf4j/src/main/java/org/pf4j/CompoundPluginRepository.java
pf4j/src/main/java/org/pf4j/DefaultExtensionFactory.java
pf4j/src/main/java/org/pf4j/DefaultPluginManager.java
pf4j/src/main/java/org/pf4j/DefaultPluginRepository.java
pf4j/src/main/java/org/pf4j/DefaultPluginStatusProvider.java
pf4j/src/main/java/org/pf4j/DependencyResolver.java
pf4j/src/main/java/org/pf4j/ExtensionFactory.java
pf4j/src/main/java/org/pf4j/ExtensionWrapper.java
pf4j/src/main/java/org/pf4j/ManifestPluginDescriptorFinder.java
pf4j/src/main/java/org/pf4j/Plugin.java
pf4j/src/main/java/org/pf4j/PluginAlreadyLoadedException.java
pf4j/src/main/java/org/pf4j/PluginDescriptorFinder.java
pf4j/src/main/java/org/pf4j/PluginException.java [deleted file]
pf4j/src/main/java/org/pf4j/PluginManager.java
pf4j/src/main/java/org/pf4j/PluginRepository.java
pf4j/src/main/java/org/pf4j/PluginRuntimeException.java [new file with mode: 0644]
pf4j/src/main/java/org/pf4j/PluginStatusProvider.java
pf4j/src/main/java/org/pf4j/PropertiesPluginDescriptorFinder.java
pf4j/src/main/java/org/pf4j/SingletonExtensionFactory.java
pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java
pf4j/src/test/java/org/pf4j/DefaultExtensionFactoryTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java
pf4j/src/test/java/org/pf4j/LoadPluginsTest.java
pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java
pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java
pf4j/src/test/java/org/pf4j/SingletonExtensionFactoryTest.java

index 6039b51ab0613088fd4abaee80d5fc43458957db..6bd61707b9749a6ec973e4734f784756fca6a3bb 100644 (file)
@@ -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);
             }
         }
index 64c996b803713590616009362960749512831a63..8c856f808d5d21a8ec0748c521eaf61b708e26c2 100644 (file)
@@ -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);
         }
     }
 
index 751ad5e075404e9d0e1930ec9db3f41f66c1314c..6fe1ff2f1522586389ad6380a2f958e3cd3164df 100644 (file)
@@ -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);
     }
 
 }
index 600f00ccd8cb938f23752f47ce8027c1c333e4dc..a36b00ae0a7498e92cb93b1ce4ae46df19ef621f 100644 (file)
@@ -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;
index fbcba27ad86c5e50b7355af98a47cd6dc4292e30..66e50549b5efa812df8c11a3ef1cf44750cdbd89 100644 (file)
@@ -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);
         }
     }
 
index cafdb4ec25ab25ce49c330683ee35a0274bfec65..9cad187610decc00475d852ba0fec856cc0c1f8e 100644 (file)
@@ -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);
index 70a4bb956b1692004d2ed2a843a70e9a73f3b6d0..2fafbc7a266a01cbd0aacf6b493cec07c4f0253f 100644 (file)
@@ -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);
     }
index 823a29c84e6c940502318842e486c0c0f32bc419..0b88fe8f0241706667dff9987effc0135301aa24 100644 (file)
@@ -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);
         }
     }
 
index a3aa9f6b35a5fec13d2f6f7863baeeaa2d239a9d..45005e2db8755f0651c0c746a2f9264066e3d175 100644 (file)
@@ -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;
 
index 42b0de8279f163299d419649fec7591362103ae8..176c6ffee16b3dee314a6a5c4a0031e2aeb65e16 100644 (file)
@@ -20,6 +20,6 @@ package org.pf4j;
  */
 public interface ExtensionFactory {
 
-    <T> T create(Class<T> extensionClass) throws PluginException;
+    <T> T create(Class<T> extensionClass);
 
 }
index 85c5b91f5755043134b41b395f4042ac391cb032..3899d5fd1947c3a8dd6c03107f95a791a9028058 100644 (file)
@@ -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);
         }
index 20810ba679650514eb7f4d457f6ae89dc069b608..650b2d712b436787e2a785e61510911e0a9af9c9 100644 (file)
@@ -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);
         }
     }
 
index b648b64d90f32d734b46ccae68c10c4096bebf82..e3dd4492b9eb998872d0f221e279e0e0f8691416 100644 (file)
@@ -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() {
     }
 
 }
index adfd90b53078ceec397e7e7e88a7771244e02dcd..411756cf8b465e371584395d274087a5c19b7964 100644 (file)
@@ -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;
index 3b9f6002b710d7edec5824c5ef83d4626438a86d..35185afc0e33285d30bd9b652b429514abedb13a 100644 (file)
@@ -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/PluginException.java b/pf4j/src/main/java/org/pf4j/PluginException.java
deleted file mode 100644 (file)
index d1ba6f2..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2012-present the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.pf4j;
-
-import org.pf4j.util.StringUtils;
-
-/**
- * An exception used to indicate that a plugin problem occurred.
- * It's a generic plugin exception class to be thrown when no more specific class is applicable.
- *
- * @author Decebal Suiu
- */
-public class PluginException extends Exception {
-
-    public PluginException() {
-        super();
-    }
-
-    public PluginException(String message) {
-        super(message);
-    }
-
-    public PluginException(Throwable cause) {
-        super(cause);
-    }
-
-    public PluginException(String message, Throwable cause) {
-        super(message, cause);
-    }
-
-    public PluginException(Throwable cause, String message, Object... args) {
-        super(StringUtils.format(message, args), cause);
-    }
-
-    public PluginException(String message, Object... args) {
-        super(StringUtils.format(message, args));
-    }
-
-}
index 0fb9b1fae666cda8acf6e9d0ac578299155bd001..a937f2290885a9f328ba8956a5ef7f46f30c71a2 100644 (file)
@@ -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();
index 9b4298aac171f72663f47b7caa5e9bd71a4272a8..6bc235603218cdec6b59f6224bd6545329d489f0 100644 (file)
@@ -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/PluginRuntimeException.java b/pf4j/src/main/java/org/pf4j/PluginRuntimeException.java
new file mode 100644 (file)
index 0000000..5d5ede9
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012-present the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.pf4j;
+
+import org.pf4j.util.StringUtils;
+
+/**
+ * An exception used to indicate that a plugin problem occurred.
+ * It's a generic plugin exception class to be thrown when no more specific class is applicable.
+ *
+ * @author Decebal Suiu
+ */
+public class PluginRuntimeException extends RuntimeException {
+
+    public PluginRuntimeException() {
+        super();
+    }
+
+    public PluginRuntimeException(String message) {
+        super(message);
+    }
+
+    public PluginRuntimeException(Throwable cause) {
+        super(cause);
+    }
+
+    public PluginRuntimeException(Throwable cause, String message, Object... args) {
+        super(StringUtils.format(message, args), cause);
+    }
+
+    public PluginRuntimeException(String message, Object... args) {
+        super(StringUtils.format(message, args));
+    }
+
+}
index 228575fe6224d1a66d2780dc1e22b13e41ec9122..46967b2d1b03fa78f235da531592f94abc19f3ad 100644 (file)
@@ -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);
 
 }
index 31afee931ff7d076d92226e77784273d1b35d872..6789a5fe2c52a6db4199f9229d530585964c79e6 100644 (file)
@@ -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);
             }
         }
     }
index 3da97d09de7145dd9c5c67a8e9e8c0b4b21b1281..725b9a7b32bd7da7b72c6fc14e8424496ca22acf 100644 (file)
@@ -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);
index d74bea3617c6d5de8455f2a1c38147caaadbaa41..c16839e21c0e121fc90393cdaf3b119cc876d6fa 100644 (file)
@@ -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
index 207c17885f5b54187f20e96a26cfdb65aec6ef04..150828f36103084b909e792d1475c701bb6b9f29 100644 (file)
@@ -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));
     }
 
 }
index ced9b4e7f8a33dae9fe8f386b7114c70a43c1313..8cb9b2769476256904d753418ae12892ac1c4bc4 100644 (file)
@@ -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());
     }
index 3474aa64c4f0edd66d80b91ee17a59c5656b1bc6..c564543c36f58f3398798baada5bb9ff246699e8 100644 (file)
@@ -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")));
index d2a7e2566b29bd4e701213a046f150805432e155..e3dac0222653da3d37ca6c0256bd9c455c9e287c 100644 (file)
@@ -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));
index 2ffe01be53d3a7b7b8c5333a3ac97b6d62f09c73..468f2fb555dd844073a5248e8c05ceda5d0ad7ac 100644 (file)
@@ -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() {
index 1f51e957b4b74713751998ce01f460c6a803cbda..bc91a7fa3568ecd2bdca9ce650d16fef20c77f04 100644 (file)
@@ -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() {
index 97e98cf977623a129b2c59f61a7d7bb04be80c57..80e7ab0bc837cc8784609096554967064a4b4717 100644 (file)
@@ -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);