org.zodiac.plugin.integration.pf4j.ConfigPluginStatusProvider Maven / Gradle / Ivy
package org.zodiac.plugin.integration.pf4j;
import org.pf4j.PluginStatusProvider;
import org.zodiac.sdk.toolkit.util.collection.CollUtil;
import java.util.Set;
public class ConfigPluginStatusProvider implements PluginStatusProvider {
private Set enablePluginIds = CollUtil.set();
private Set disabledPlugins = CollUtil.set();
public ConfigPluginStatusProvider() {
this(null, null);
}
public ConfigPluginStatusProvider(Set enablePluginIds, Set disabledPluginIds) {
if (enablePluginIds != null && !enablePluginIds.isEmpty()) {
this.enablePluginIds.addAll(enablePluginIds);
}
if (disabledPluginIds != null && !disabledPluginIds.isEmpty()) {
this.disabledPlugins.addAll(disabledPluginIds);
}
}
@Override
public boolean isPluginDisabled(String pluginId) {
if (disabledPlugins.contains("*")) {
return true;
}
if (disabledPlugins.contains(pluginId)) {
return true;
}
return !enablePluginIds.isEmpty() && !enablePluginIds.contains(pluginId);
}
@Override
public void disablePlugin(String pluginId) {
if (isPluginDisabled(pluginId)) {
return;
}
disabledPlugins.add(pluginId);
enablePluginIds.remove(pluginId);
}
@Override
public void enablePlugin(String pluginId) {
if (!isPluginDisabled(pluginId)) {
return;
}
disabledPlugins.remove(pluginId);
enablePluginIds.add(pluginId);
}
}