All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.starblues.integration.pf4j.ConfigPluginStatusProvider Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package com.gitee.starblues.integration.pf4j;

import org.pf4j.PluginStatusProvider;

import java.util.HashSet;
import java.util.Set;

/**
 * @author starBlues
 * @version 2.4.0
 */
public class ConfigPluginStatusProvider implements PluginStatusProvider {

    private Set enablePluginIds = new HashSet<>();
    private Set disabledPlugins = new HashSet<>();

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy