diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2014-04-07 01:02:29 +0300 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2014-04-08 23:17:33 +0300 |
commit | 33baceffd7560ca997db696b086bc263574039be (patch) | |
tree | d4c675ecf6f8bc80fdadf65dc4af66612d54ad1f /pf4j | |
parent | 0cf3fc42ff8d3a71ba10bb599a5ec64885c86681 (diff) | |
download | pf4j-33baceffd7560ca997db696b086bc263574039be.tar.gz pf4j-33baceffd7560ca997db696b086bc263574039be.zip |
use PluginState.DISABLE instead of PluginManger.isPluginDisabled()
Diffstat (limited to 'pf4j')
4 files changed, 21 insertions, 47 deletions
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<PluginWrapper> 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<URL> 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 @@ -50,6 +50,14 @@ public interface PluginManager { public List<PluginWrapper> getStartedPlugins(); /** + * Retrieves the plugin with this id. + * + * @param pluginId + * @return the plugin + */ + public PluginWrapper getPlugin(String pluginId); + + /** * Load plugins. */ public void loadPlugins(); @@ -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<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins(); - for (PluginWrapper plugin: startedPlugins) { - if (pluginId.equals(plugin.getPluginId())) { - return PluginState.STARTED == plugin.getPluginState(); - } - } - - return false; - } - -} |