提交 ace2e638 编写于 作者: A ascrutae

Add mechanism to set default status(on/off) of plugin

上级 0b4b4b17
......@@ -101,6 +101,12 @@ public class Config {
*/
public static List DISABLED_PLUGINS = new LinkedList();
/**
* Name of force enable plugin, The value spilt by <code>,</code>
* if you have multiple plugins need to enable.
*/
public static List FORCE_ENABLE_PLUGINS = new LinkedList();
public static class MongoDB {
/**
* If true, trace all the parameters, default is false.
......
......@@ -15,9 +15,15 @@ public class PluginDefine {
*/
private String defineClass;
private PluginDefine(String name, String defineClass) {
/**
* The sate of plugin.
*/
private State state;
private PluginDefine(String name, String defineClass, State state) {
this.name = name;
this.defineClass = defineClass;
this.state = state;
}
public static PluginDefine build(String define) throws IllegalPluginDefineException {
......@@ -30,16 +36,31 @@ public class PluginDefine {
throw new IllegalPluginDefineException(define);
}
return new PluginDefine(pluginDefine[0], pluginDefine[1]);
String pluginName = pluginDefine[0];
String defineClass = pluginDefine[1];
if (pluginName.toUpperCase().startsWith("[OFF]")) {
return new PluginDefine(pluginName.substring(5), defineClass, State.OFF);
} else {
return new PluginDefine(pluginName, defineClass, State.ON);
}
}
public boolean enable() {
return !Config.Plugin.DISABLED_PLUGINS.contains(name);
return !Config.Plugin.DISABLED_PLUGINS.contains(name) || forceEnable();
}
private boolean forceEnable() {
return state == State.OFF && Config.Plugin.FORCE_ENABLE_PLUGINS.contains(name);
}
public String getDefineClass() {
return defineClass;
}
private enum State {
OFF, ON;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册