From 3720dddcd5afdc649349beb0a50c5d5c437e9fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Franco?= Date: Wed, 27 May 2015 11:01:01 +0100 Subject: [PATCH] Add Plugin status provider --- .../fortsoft/pf4j/DefaultPluginManager.java | 44 ++++++++++++++----- .../fortsoft/pf4j/PluginStatusProvider.java | 33 ++++++++++++++ 2 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 pf4j/src/main/java/ro/fortsoft/pf4j/PluginStatusProvider.java 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(); + +}