aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMário Franco <mario.ffranco@gmail.com>2015-05-27 11:01:01 +0100
committerMário Franco <mario.ffranco@gmail.com>2015-05-27 17:19:46 +0100
commit3720dddcd5afdc649349beb0a50c5d5c437e9fa7 (patch)
treec2d5a8735403a05d7c90b5a82292dcbf2a1657e8
parent3aeefcd772a6aab5966b67401da38bdb4b95e82a (diff)
downloadpf4j-3720dddcd5afdc649349beb0a50c5d5c437e9fa7.tar.gz
pf4j-3720dddcd5afdc649349beb0a50c5d5c437e9fa7.zip
Add Plugin status provider
-rw-r--r--pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java44
-rw-r--r--pf4j/src/main/java/ro/fortsoft/pf4j/PluginStatusProvider.java33
2 files changed, 67 insertions, 10 deletions
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<String> getEnabledPlugins() {
+ List<String> 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<String> getDisabledPlugins() {
+ List<String> 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<String> getEnabledPlugins();
+
+ /**
+ * Retrieves a list with plugin identifiers that should not be accepted by this manager
+ */
+ public List<String> getDisabledPlugins();
+
+}