From edba2eca2e1b1a9d16efd1cc8af7e4120aa60cc5 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 5 Aug 2017 16:21:02 -0700 Subject: [PATCH] Make loading plugins a non-core part of Abacus, avoiding desktop APIs. --- src/main/java/org/nwapw/abacus/Abacus.java | 12 +----------- .../java/org/nwapw/abacus/fx/AbacusController.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/nwapw/abacus/Abacus.java b/src/main/java/org/nwapw/abacus/Abacus.java index a801343..8d21cb4 100644 --- a/src/main/java/org/nwapw/abacus/Abacus.java +++ b/src/main/java/org/nwapw/abacus/Abacus.java @@ -6,7 +6,6 @@ import org.nwapw.abacus.number.NumberInterface; import org.nwapw.abacus.parsing.LexerTokenizer; import org.nwapw.abacus.parsing.ShuntingYardParser; import org.nwapw.abacus.parsing.TreeBuilder; -import org.nwapw.abacus.plugin.ClassFinder; import org.nwapw.abacus.plugin.NumberImplementation; import org.nwapw.abacus.plugin.PluginManager; import org.nwapw.abacus.plugin.StandardPlugin; @@ -14,7 +13,6 @@ import org.nwapw.abacus.tree.NumberReducer; import org.nwapw.abacus.tree.TreeNode; import java.io.File; -import java.io.IOException; /** * The main calculator class. This is responsible @@ -64,16 +62,8 @@ public class Abacus { ShuntingYardParser shuntingYardParser = new ShuntingYardParser(this); treeBuilder = new TreeBuilder<>(lexerTokenizer, shuntingYardParser); - pluginManager.addListener(lexerTokenizer); pluginManager.addListener(shuntingYardParser); - pluginManager.addInstantiated(new StandardPlugin(pluginManager)); - try { - ClassFinder.loadJars("plugins") - .forEach(plugin -> pluginManager.addClass(plugin)); - } catch (IOException | ClassNotFoundException e) { - e.printStackTrace(); - } - pluginManager.load(); + pluginManager.addListener(lexerTokenizer); } public static void main(String[] args) { diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java index 85846a4..829c39d 100644 --- a/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -12,10 +12,13 @@ import javafx.util.StringConverter; import org.nwapw.abacus.Abacus; import org.nwapw.abacus.config.Configuration; import org.nwapw.abacus.number.NumberInterface; +import org.nwapw.abacus.plugin.ClassFinder; import org.nwapw.abacus.plugin.PluginListener; import org.nwapw.abacus.plugin.PluginManager; +import org.nwapw.abacus.plugin.StandardPlugin; import org.nwapw.abacus.tree.TreeNode; +import java.io.IOException; import java.util.Set; @@ -173,8 +176,15 @@ public class AbacusController implements PluginListener { }); abacus = new Abacus(); - abacus.getPluginManager().addListener(this); - abacus.getPluginManager().reload(); + PluginManager abacusPluginManager = abacus.getPluginManager(); + abacusPluginManager.addListener(this); + abacusPluginManager.addInstantiated(new StandardPlugin(abacus.getPluginManager())); + try { + ClassFinder.loadJars("plugins").forEach(abacusPluginManager::addClass); + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); + } + abacusPluginManager.reload(); changesMade = false; reloadAlertShown = false;