diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java index c9b63b2..cf02045 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java @@ -126,10 +126,6 @@ public class DefaultPluginManager implements PluginManager { return resolvedPlugins; } - public PluginWrapper getPlugin(String pluginId) { - return plugins.get(pluginId); - } - @Override public List getUnresolvedPlugins() { return unresolvedPlugins; @@ -140,6 +136,11 @@ public class DefaultPluginManager implements PluginManager { return startedPlugins; } + @Override + public PluginWrapper getPlugin(String pluginId) { + return plugins.get(pluginId); + } + @Override public String loadPlugin(File pluginArchiveFile) { if (pluginArchiveFile == null || !pluginArchiveFile.exists()) { @@ -588,8 +589,7 @@ public class DefaultPluginManager implements PluginManager { return new PluginClasspath(); } - @Override - public boolean isPluginDisabled(String pluginId) { + protected boolean isPluginDisabled(String pluginId) { if (enabledPlugins.isEmpty()) { return disabledPlugins.contains(pluginId); } diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java index 0252d8f..3fd7572 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java @@ -96,7 +96,7 @@ public class PluginClassLoader extends URLClassLoader { @Override public URL getResource(String name) { - if (pluginManager.isPluginDisabled(pluginDescriptor.getPluginId())) { + if (PluginState.DISABLED == getPlugin().getPluginState()) { return null; } @@ -105,10 +105,15 @@ public class PluginClassLoader extends URLClassLoader { @Override public Enumeration getResources(String name) throws IOException { - if (pluginManager.isPluginDisabled(pluginDescriptor.getPluginId())) { + if (PluginState.DISABLED == getPlugin().getPluginState()) { return Collections.emptyEnumeration(); } return super.getResources(name); } + + private PluginWrapper getPlugin() { + return pluginManager.getPlugin(pluginDescriptor.getPluginId()); + } + } diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java index 36defe5..f656313 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java @@ -49,6 +49,14 @@ public interface PluginManager { */ public List getStartedPlugins(); + /** + * Retrieves the plugin with this id. + * + * @param pluginId + * @return the plugin + */ + public PluginWrapper getPlugin(String pluginId); + /** * Load plugins. */ @@ -94,8 +102,6 @@ public interface PluginManager { */ public boolean unloadPlugin(String pluginId); - public boolean isPluginDisabled(String pluginId); - /** * Disables a plugin from being loaded. * diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/util/PluginUtils.java b/pf4j/src/main/java/ro/fortsoft/pf4j/util/PluginUtils.java deleted file mode 100644 index bfe6287..0000000 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/util/PluginUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2014 Decebal Suiu - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with - * the License. You may obtain a copy of the License in the LICENSE file, or 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 ro.fortsoft.pf4j.util; - -import ro.fortsoft.pf4j.PluginManager; -import ro.fortsoft.pf4j.PluginState; -import ro.fortsoft.pf4j.PluginWrapper; - -import java.util.List; - -/** - * @author Decebal Suiu - */ -public class PluginUtils { - - public static boolean isPluginStarted(PluginManager pluginManager, String pluginId) { - List startedPlugins = pluginManager.getStartedPlugins(); - for (PluginWrapper plugin: startedPlugins) { - if (pluginId.equals(plugin.getPluginId())) { - return PluginState.STARTED == plugin.getPluginState(); - } - } - - return false; - } - -}