From 21150fa7a2a07cfd61976d66cc2bf7e0636cb260 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 2 Aug 2017 19:06:16 -0700 Subject: [PATCH] Actually disable loading the plugin functions in the PluginManager. --- src/main/java/org/nwapw/abacus/Abacus.java | 2 +- .../nwapw/abacus/plugin/PluginManager.java | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/nwapw/abacus/Abacus.java b/src/main/java/org/nwapw/abacus/Abacus.java index bf8328f..649bb1a 100644 --- a/src/main/java/org/nwapw/abacus/Abacus.java +++ b/src/main/java/org/nwapw/abacus/Abacus.java @@ -57,7 +57,7 @@ public class Abacus { * Creates a new instance of the Abacus calculator. */ public Abacus() { - pluginManager = new PluginManager(); + pluginManager = new PluginManager(this); numberReducer = new NumberReducer(this); configuration = new Configuration(CONFIG_FILE); configuration.saveTo(CONFIG_FILE); diff --git a/src/main/java/org/nwapw/abacus/plugin/PluginManager.java b/src/main/java/org/nwapw/abacus/plugin/PluginManager.java index 1c8748e..8450bf7 100644 --- a/src/main/java/org/nwapw/abacus/plugin/PluginManager.java +++ b/src/main/java/org/nwapw/abacus/plugin/PluginManager.java @@ -1,5 +1,6 @@ package org.nwapw.abacus.plugin; +import org.nwapw.abacus.Abacus; import org.nwapw.abacus.function.Function; import org.nwapw.abacus.function.Operator; import org.nwapw.abacus.number.NumberInterface; @@ -52,11 +53,17 @@ public class PluginManager { * The list of plugin listeners attached to this instance. */ private Set listeners; + /** + * The abacus instance used to access other + * components of the application. + */ + private Abacus abacus; /** * Creates a new plugin manager. */ - public PluginManager() { + public PluginManager(Abacus abacus) { + this.abacus = abacus; loadedPluginClasses = new HashSet<>(); plugins = new HashSet<>(); cachedFunctions = new HashMap<>(); @@ -160,8 +167,13 @@ public class PluginManager { * Loads all the plugins in the PluginManager. */ public void load() { - for (Plugin plugin : plugins) plugin.enable(); + Set disabledPlugins = abacus.getConfiguration().getDisabledPlugins(); for (Plugin plugin : plugins) { + if(disabledPlugins.contains(plugin.getClass().getName())) continue; + plugin.enable(); + } + for (Plugin plugin : plugins) { + if(disabledPlugins.contains(plugin.getClass().getName())) continue; allFunctions.addAll(plugin.providedFunctions()); allOperators.addAll(plugin.providedOperators()); allNumbers.addAll(plugin.providedNumbers()); @@ -173,7 +185,11 @@ public class PluginManager { * Unloads all the plugins in the PluginManager. */ public void unload() { - for (Plugin plugin : plugins) plugin.disable(); + Set disabledPlugins = abacus.getConfiguration().getDisabledPlugins(); + for (Plugin plugin : plugins) { + if(disabledPlugins.contains(plugin.getClass().getName())) continue; + plugin.disable(); + } allFunctions.clear(); allOperators.clear(); allNumbers.clear();