1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 23:40:08 -08:00

Load default plugin without jars.

This commit is contained in:
Danila Fedorin 2017-07-28 15:18:23 -07:00
parent ce9e32b08f
commit 0300bece46
2 changed files with 11 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package org.nwapw.abacus;
import org.nwapw.abacus.plugin.PluginManager; import org.nwapw.abacus.plugin.PluginManager;
//import org.nwapw.abacus.plugin.StandardPlugin; //import org.nwapw.abacus.plugin.StandardPlugin;
import org.nwapw.abacus.plugin.StandardPlugin;
import org.nwapw.abacus.window.Window; import org.nwapw.abacus.window.Window;
import org.nwapw.abacus.plugin.ClassFinder; import org.nwapw.abacus.plugin.ClassFinder;
@ -25,6 +26,7 @@ public class Abacus {
e.printStackTrace(); e.printStackTrace();
} }
manager = new PluginManager(); manager = new PluginManager();
manager.addInstantiated(new StandardPlugin(manager));
try { try {
ClassFinder.loadJars("plugins") ClassFinder.loadJars("plugins")
.forEach(plugin -> manager.addClass(plugin)); .forEach(plugin -> manager.addClass(plugin));

View File

@ -12,10 +12,14 @@ import java.util.*;
*/ */
public class PluginManager { public class PluginManager {
/**
* List of classes loaded by this manager.
*/
private Set<Class<?>> loadedPluginClasses;
/** /**
* A list of loaded plugins. * A list of loaded plugins.
*/ */
private List<Plugin> plugins; private Set<Plugin> plugins;
/** /**
* List of functions that have been cached, * List of functions that have been cached,
* that is, found in a plugin and returned. * that is, found in a plugin and returned.
@ -43,7 +47,8 @@ public class PluginManager {
* Creates a new plugin manager. * Creates a new plugin manager.
*/ */
public PluginManager(){ public PluginManager(){
plugins = new ArrayList<>(); loadedPluginClasses = new HashSet<>();
plugins = new HashSet<>();
cachedFunctions = new HashMap<>(); cachedFunctions = new HashMap<>();
cachedOperators = new HashMap<>(); cachedOperators = new HashMap<>();
allFunctions = new HashSet<>(); allFunctions = new HashSet<>();
@ -104,7 +109,9 @@ public class PluginManager {
* @param plugin the plugin to add. * @param plugin the plugin to add.
*/ */
public void addInstantiated(Plugin plugin){ public void addInstantiated(Plugin plugin){
if(loadedPluginClasses.contains(plugin.getClass())) return;
plugins.add(plugin); plugins.add(plugin);
loadedPluginClasses.add(plugin.getClass());
} }
/** /**