From: Mário Franco Date: Wed, 27 May 2015 10:01:01 +0000 (+0100) Subject: Add Plugin status provider X-Git-Tag: release-0.10.0~22^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3720dddcd5afdc649349beb0a50c5d5c437e9fa7;p=pf4j.git Add Plugin status provider --- diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java index d2fcd3b..4af3947 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java @@ -658,6 +658,37 @@ public class DefaultPluginManager implements PluginManager { return new PluginClasspath(); } + protected PluginStatusProvider createPluginStatusProvider() { + return new PluginStatusProvider() { + + @Override + public List getEnabledPlugins() { + List enabledPlugins = Collections.emptyList(); + try { + // create a list with plugin identifiers that should be only accepted by this manager (whitelist from plugins/enabled.txt file) + enabledPlugins = FileUtils.readLines(new File(pluginsDirectory, "enabled.txt"), true); + log.info("Enabled plugins: {}", enabledPlugins); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + return enabledPlugins; + } + + @Override + public List getDisabledPlugins() { + List disabledPlugins = Collections.emptyList(); + try { + // create a list with plugin identifiers that should not be accepted by this manager (blacklist from plugins/disabled.txt file) + disabledPlugins = FileUtils.readLines(new File(pluginsDirectory, "disabled.txt"), true); + log.info("Disabled plugins: {}", disabledPlugins); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + return disabledPlugins; + } + }; + } + protected boolean isPluginDisabled(String pluginId) { if (enabledPlugins.isEmpty()) { return disabledPlugins.contains(pluginId); @@ -740,17 +771,10 @@ public class DefaultPluginManager implements PluginManager { pluginDescriptorFinder = createPluginDescriptorFinder(); extensionFinder = createExtensionFinder(); - try { - // create a list with plugin identifiers that should be only accepted by this manager (whitelist from plugins/enabled.txt file) - enabledPlugins = FileUtils.readLines(new File(pluginsDirectory, "enabled.txt"), true); - log.info("Enabled plugins: {}", enabledPlugins); + PluginStatusProvider statusLists = createPluginStatusProvider(); - // create a list with plugin identifiers that should not be accepted by this manager (blacklist from plugins/disabled.txt file) - disabledPlugins = FileUtils.readLines(new File(pluginsDirectory, "disabled.txt"), true); - log.info("Disabled plugins: {}", disabledPlugins); - } catch (IOException e) { - log.error(e.getMessage(), e); - } + enabledPlugins = statusLists.getEnabledPlugins(); + disabledPlugins = statusLists.getDisabledPlugins(); System.setProperty("pf4j.pluginsDir", pluginsDirectory.getAbsolutePath()); } diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginStatusProvider.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginStatusProvider.java new file mode 100644 index 0000000..e0d93dd --- /dev/null +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginStatusProvider.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012 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; + +import java.util.List; + +/** + * @author Decebal Suiu + * @author Mário Franco + */ +public interface PluginStatusProvider { + + /** + * Retrieves a list with plugin identifiers that should be only accepted by this manager + */ + public List getEnabledPlugins(); + + /** + * Retrieves a list with plugin identifiers that should not be accepted by this manager + */ + public List getDisabledPlugins(); + +}