Browse Source

Add Plugin status provider

pull/40/head
Mário Franco 10 years ago
parent
commit
3720dddcd5
  1. 44
      pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java
  2. 33
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginStatusProvider.java

44
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());
}

33
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();
}
Loading…
Cancel
Save