diff --git a/core/.classpath b/core/.classpath index fb297f54e..5a8600e02 100644 --- a/core/.classpath +++ b/core/.classpath @@ -30,5 +30,9 @@ + + + + diff --git a/core/example.jar b/core/example.jar new file mode 100644 index 000000000..bf2b50c97 Binary files /dev/null and b/core/example.jar differ diff --git a/core/lib/aopalliance.jar b/core/lib/aopalliance.jar new file mode 100644 index 000000000..578b1a0c3 Binary files /dev/null and b/core/lib/aopalliance.jar differ diff --git a/core/lib/guice-3.0.jar b/core/lib/guice-3.0.jar new file mode 100644 index 000000000..76be5e0dd Binary files /dev/null and b/core/lib/guice-3.0.jar differ diff --git a/core/lib/guice-multibindings-3.0.jar b/core/lib/guice-multibindings-3.0.jar new file mode 100644 index 000000000..f2ec19a2a Binary files /dev/null and b/core/lib/guice-multibindings-3.0.jar differ diff --git a/core/lib/javax.inject.jar b/core/lib/javax.inject.jar new file mode 100644 index 000000000..a9dfb86d2 Binary files /dev/null and b/core/lib/javax.inject.jar differ diff --git a/core/src/net/sf/openrocket/gui/plugin/DoSomethingPlugin.java b/core/src/net/sf/openrocket/gui/plugin/DoSomethingPlugin.java deleted file mode 100644 index d238c4eb6..000000000 --- a/core/src/net/sf/openrocket/gui/plugin/DoSomethingPlugin.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.sf.openrocket.gui.plugin; - -import javax.swing.Action; - -import net.sf.openrocket.document.OpenRocketDocument; -import net.sf.openrocket.gui.main.BasicFrame; - -public class DoSomethingPlugin extends OpenRocketSwingMenuPlugin { - - @Override - public Action getAction(BasicFrame frame, OpenRocketDocument document) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/core/src/net/sf/openrocket/gui/plugin/OpenRocketSwingMenuPlugin.java b/core/src/net/sf/openrocket/gui/plugin/OpenRocketSwingMenuPlugin.java deleted file mode 100644 index e76e64a20..000000000 --- a/core/src/net/sf/openrocket/gui/plugin/OpenRocketSwingMenuPlugin.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.sf.openrocket.gui.plugin; - -import java.util.List; - -import net.sf.openrocket.plugin.framework.Service; - -public abstract class OpenRocketSwingMenuPlugin implements Service, SwingMenuPlugin { - - @Override - public String[] getMenuPosition() { - // TODO Auto-generated method stub - return null; - } - - - @Override - public List getPlugins(Class type, Object... args) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/core/src/net/sf/openrocket/gui/plugin/SwingMenuPlugin.java b/core/src/net/sf/openrocket/gui/plugin/SwingMenuPlugin.java deleted file mode 100644 index e27b78ac6..000000000 --- a/core/src/net/sf/openrocket/gui/plugin/SwingMenuPlugin.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.sf.openrocket.gui.plugin; - -import javax.swing.Action; - -import net.sf.openrocket.document.OpenRocketDocument; -import net.sf.openrocket.gui.main.BasicFrame; - -/** - * A plugin that provides a menu item to the Swing GUI menus. - * This may open a dialog window or perform some other action on - * the current document. - *

- * During plugin discovery, the BasicFrame and OpenRocketDocument - * objects are passed to the plugin. - * - * @author Sampo Niskanen - */ -public interface SwingMenuPlugin { - - /** - * Return the menu position where the action is placed. - * The first string in the array indicates the menu to place - * the item in, the second is the sub-menu, the third is the - * sub-sub-menu etc. - *

- * The strings are translated menu names. - * - * @return the menu position for the action - */ - public String[] getMenuPosition(); - - /** - * Return the Action that the menu item performs. This contains - * the menu item text and may contain an icon. - * - * @return the action to perform on the menu item. - */ - public Action getAction(BasicFrame frame, OpenRocketDocument document); - -} diff --git a/core/src/net/sf/openrocket/plugin/Configurable.java b/core/src/net/sf/openrocket/plugin/Configurable.java deleted file mode 100644 index b8ebf6e2c..000000000 --- a/core/src/net/sf/openrocket/plugin/Configurable.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.sf.openrocket.plugin; - -public interface Configurable { - - - /** - * Return the plugin ID. This is a text string uniquely identifying this plugin. - * The recommended format is similar to the fully-qualified class name of the - * plugin, though a shorter format starting with the developer's domain name - * is also possible for future compatibility. - * - * @return the plugin ID - */ - public String getPluginID(); - - /** - * Test whether this plugin provides functionality corresponding to the specified - * plugin ID. This provides backwards compatibility if the plugin ID should change. - * - * @param pluginID the plugin ID to test - * @return whether this plugin provides the requested functionality - */ - public boolean isCompatible(String pluginID); - - public void loadFromXML(Object... objects); - - public void saveToXML(Object... objects); - -} diff --git a/core/src/net/sf/openrocket/plugin/CopyOfExamplePluginImpl.java b/core/src/net/sf/openrocket/plugin/CopyOfExamplePluginImpl.java new file mode 100644 index 000000000..8abe0020d --- /dev/null +++ b/core/src/net/sf/openrocket/plugin/CopyOfExamplePluginImpl.java @@ -0,0 +1,10 @@ +package net.sf.openrocket.plugin; + +public class CopyOfExamplePluginImpl implements ExamplePlugin { + + @Override + public void doit() { + System.out.println("CopyOfExamplePluginImpl.doit() called"); + } + +} diff --git a/core/src/net/sf/openrocket/plugin/ExamplePlugin.java b/core/src/net/sf/openrocket/plugin/ExamplePlugin.java new file mode 100644 index 000000000..b69950e80 --- /dev/null +++ b/core/src/net/sf/openrocket/plugin/ExamplePlugin.java @@ -0,0 +1,8 @@ +package net.sf.openrocket.plugin; + +@Plugin +public interface ExamplePlugin { + + public void doit(); + +} diff --git a/core/src/net/sf/openrocket/plugin/ExamplePluginImpl.java b/core/src/net/sf/openrocket/plugin/ExamplePluginImpl.java new file mode 100644 index 000000000..05a0aeb5b --- /dev/null +++ b/core/src/net/sf/openrocket/plugin/ExamplePluginImpl.java @@ -0,0 +1,10 @@ +package net.sf.openrocket.plugin; + +public class ExamplePluginImpl implements ExamplePlugin { + + @Override + public void doit() { + System.out.println("ExamplePluginImpl.doit() called"); + } + +} diff --git a/core/src/net/sf/openrocket/plugin/Plugin.java b/core/src/net/sf/openrocket/plugin/Plugin.java new file mode 100644 index 000000000..de8eb4cdd --- /dev/null +++ b/core/src/net/sf/openrocket/plugin/Plugin.java @@ -0,0 +1,19 @@ +package net.sf.openrocket.plugin; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation that defines an interface to be a plugin interface. + * Plugin interfaces are automatically discovered from plugin JARs and + * registered as plugins in Guice. + * + * @author Sampo Niskanen + */ +@Target(value = { ElementType.TYPE }) +@Retention(value = RetentionPolicy.RUNTIME) +public @interface Plugin { + +} diff --git a/core/src/net/sf/openrocket/plugin/PluginModule.java b/core/src/net/sf/openrocket/plugin/PluginModule.java new file mode 100644 index 000000000..88daae2e0 --- /dev/null +++ b/core/src/net/sf/openrocket/plugin/PluginModule.java @@ -0,0 +1,122 @@ +package net.sf.openrocket.plugin; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import com.google.inject.AbstractModule; +import com.google.inject.multibindings.Multibinder; + +/** + * Guice module definition that searches for plugins in a list of provided + * JAR files and registers each found plugin to the corresponding plugin interface. + * + * @author Sampo Niskanen + */ +public class PluginModule extends AbstractModule { + + private final File[] jars; + private final ClassLoader classLoader; + + private Map, Multibinder> binders = new HashMap, Multibinder>(); + + + /** + * Sole constructor. + * + * @param jars the JAR files to search for plugins + * @param classLoader the class loader used to load classes from the JAR files + */ + public PluginModule(File[] jars, ClassLoader classLoader) { + this.jars = jars.clone(); + this.classLoader = classLoader; + } + + + @Override + protected void configure() { + for (File jar : jars) { + List classNames = readClassNames(jar); + for (String className : classNames) { + checkForPlugin(className); + } + } + } + + + + @SuppressWarnings("unchecked") + private void checkForPlugin(String className) { + try { + + Class c = classLoader.loadClass(className); + for (Class intf : c.getInterfaces()) { + System.out.println("Testing class " + c + " interface " + intf); + + if (isPluginInterface(intf)) { + System.out.println("BINDING"); + // Ugly hack to enable dynamic binding... Can this be done type-safely? + Multibinder binder = (Multibinder) findBinder(intf); + binder.addBinding().to(c); + } + } + + } catch (ClassNotFoundException e) { + System.err.println("Could not load class " + className + ": " + e); + } + } + + + private boolean isPluginInterface(Class intf) { + return intf.isAnnotationPresent(Plugin.class); + } + + + private Multibinder findBinder(Class intf) { + Multibinder binder = binders.get(intf); + if (binder == null) { + binder = Multibinder.newSetBinder(binder(), intf); + binders.put(intf, binder); + } + return binder; + } + + + private List readClassNames(File jar) { + List classNames = new ArrayList(); + + JarFile file = null; + try { + file = new JarFile(jar); + Enumeration entries = file.entries(); + while (entries.hasMoreElements()) { + JarEntry entry = entries.nextElement(); + String name = entry.getName(); + if (name.toLowerCase().endsWith(".class") && !name.contains("$")) { + name = name.substring(0, name.length() - 6); + name = name.replace('/', '.'); + classNames.add(name); + } + } + } catch (IOException e) { + System.err.println("Error reading JAR file " + jar); + } finally { + if (file != null) { + try { + file.close(); + } catch (IOException e) { + // Curse all checked exceptions... + } + } + } + + return classNames; + } + +} diff --git a/core/src/net/sf/openrocket/plugin/SwingConfigurator.java b/core/src/net/sf/openrocket/plugin/SwingConfigurator.java deleted file mode 100644 index 86ba323e0..000000000 --- a/core/src/net/sf/openrocket/plugin/SwingConfigurator.java +++ /dev/null @@ -1,37 +0,0 @@ -package net.sf.openrocket.plugin; - -import java.awt.Component; - -import net.xeoh.plugins.base.Plugin; - -/** - * Interface that defined a Swing configurator for a plugin. - * The implemeting class should be a plugin that provides the - * capability ":config" where is the - * plugin ID of the plugin to configure. - *

- * - * @param

The plugin class that is being configured - * @author Sampo Niskanen - */ -public interface SwingConfigurator

extends Plugin { - - /** - * Return whether this plugin is configurable or not. - * - * @param plugin the plugin to test. - * @return whether the plugin has a configuration component. - */ - public boolean isConfigurable(P plugin); - - /** - * Return the configuration component for configuring the - * provided plugin. - * - * @param plugin the plugin to configure. - * @return a Swing component for configuring the plugin. - */ - public Component getConfigurationComponent(P plugin); - - -} diff --git a/core/src/net/sf/openrocket/plugin/Test.java b/core/src/net/sf/openrocket/plugin/Test.java new file mode 100644 index 000000000..e49e189a7 --- /dev/null +++ b/core/src/net/sf/openrocket/plugin/Test.java @@ -0,0 +1,35 @@ +package net.sf.openrocket.plugin; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Set; + +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.Injector; + +public class Test { + + @Inject + private Set impls; + + + public void run() { + System.out.println("Plugin count: " + impls.size()); + for (ExamplePlugin i : impls) { + i.doit(); + } + } + + + public static void main(String[] args) throws MalformedURLException { + + File[] jars = { new File("/home/sampo/Projects/OpenRocket/core/example.jar") }; + URL[] urls = { new File("/home/sampo/Projects/OpenRocket/core/example.jar").toURL() }; + URLClassLoader classLoader = new URLClassLoader(urls); + Injector injector = Guice.createInjector(new PluginModule(jars, classLoader)); + injector.getInstance(Test.class).run(); + } +} diff --git a/core/src/net/sf/openrocket/plugin/example/AirStartSimulationExtension.java b/core/src/net/sf/openrocket/plugin/example/AirStartSimulationExtension.java deleted file mode 100644 index 7d14f5fd2..000000000 --- a/core/src/net/sf/openrocket/plugin/example/AirStartSimulationExtension.java +++ /dev/null @@ -1,42 +0,0 @@ -package net.sf.openrocket.plugin.example; - -import java.awt.Component; - -public class AirStartSimulationExtension extends OpenRocketSimulationListener { - - @Override - public String getName() { - return "Air-start"; - } - - @Override - public String[] getMenuPosition() { - return null; - } - - @Override - public void loadFromXML(Object... objects) { - // TODO Auto-generated method stub - - } - - @Override - public void saveToXML(Object... objects) { - // TODO Auto-generated method stub - - } - - @Override - public boolean isConfigurable() { - // TODO Auto-generated method stub - return false; - } - - @Override - public Component getConfigurationComponent() { - // TODO Auto-generated method stub - return null; - } - - -} diff --git a/core/src/net/sf/openrocket/plugin/example/ExampleMain.java b/core/src/net/sf/openrocket/plugin/example/ExampleMain.java deleted file mode 100644 index aea94be68..000000000 --- a/core/src/net/sf/openrocket/plugin/example/ExampleMain.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.sf.openrocket.plugin.example; - -import net.sf.openrocket.plugin.framework.JSPFPluginFactory; -import net.sf.openrocket.plugin.framework.PluginFactory; - -public class ExampleMain { - - - public static void main(String[] args) { - PluginFactory factory = new JSPFPluginFactory(); - - System.out.println("Plugins:"); - System.out.println("---------"); - for (ExamplePluginInterface plugin : factory.getPlugins(ExamplePluginInterface.class)) { - plugin.print(); - } - System.out.println("---------"); - } - - -} diff --git a/core/src/net/sf/openrocket/plugin/example/ExamplePlugin.java b/core/src/net/sf/openrocket/plugin/example/ExamplePlugin.java deleted file mode 100644 index 4579f9e3d..000000000 --- a/core/src/net/sf/openrocket/plugin/example/ExamplePlugin.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.sf.openrocket.plugin.example; - - -public class ExamplePlugin implements ExamplePluginInterface { - - private final String str; - - public ExamplePlugin(String str) { - this.str = str; - } - - @Override - public void print() { - System.out.println("ExamplePlugin: " + str); - } - -} diff --git a/core/src/net/sf/openrocket/plugin/example/ExamplePluginInterface.java b/core/src/net/sf/openrocket/plugin/example/ExamplePluginInterface.java deleted file mode 100644 index ddf157dc6..000000000 --- a/core/src/net/sf/openrocket/plugin/example/ExamplePluginInterface.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.sf.openrocket.plugin.example; - -import net.xeoh.plugins.base.Plugin; - -public interface ExamplePluginInterface extends Plugin { - - public void print(); - -} diff --git a/core/src/net/sf/openrocket/plugin/example/ExampleService.java b/core/src/net/sf/openrocket/plugin/example/ExampleService.java deleted file mode 100644 index 8a6317b38..000000000 --- a/core/src/net/sf/openrocket/plugin/example/ExampleService.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.sf.openrocket.plugin.example; - -import java.util.ArrayList; -import java.util.List; - -import net.sf.openrocket.plugin.framework.AbstractService; -import net.xeoh.plugins.base.annotations.PluginImplementation; - -@PluginImplementation -public class ExampleService extends AbstractService { - - protected ExampleService() { - super(ExamplePluginInterface.class); - } - - @Override - protected List getPlugins(Object... args) { - List plugins = new ArrayList(); - plugins.add(new ExamplePlugin("a")); - plugins.add(new ExamplePlugin("b")); - return plugins; - } - -} diff --git a/core/src/net/sf/openrocket/plugin/example/ExampleSingletonPlugin.java b/core/src/net/sf/openrocket/plugin/example/ExampleSingletonPlugin.java deleted file mode 100644 index aa015180e..000000000 --- a/core/src/net/sf/openrocket/plugin/example/ExampleSingletonPlugin.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.sf.openrocket.plugin.example; - -import net.xeoh.plugins.base.annotations.PluginImplementation; - -@PluginImplementation -public class ExampleSingletonPlugin implements ExamplePluginInterface { - - @Override - public void print() { - System.out.println("ExampleSingletonPlugin"); - } - -} diff --git a/core/src/net/sf/openrocket/plugin/example/OpenRocketSimulationListener.java b/core/src/net/sf/openrocket/plugin/example/OpenRocketSimulationListener.java deleted file mode 100644 index ea178c096..000000000 --- a/core/src/net/sf/openrocket/plugin/example/OpenRocketSimulationListener.java +++ /dev/null @@ -1,88 +0,0 @@ -package net.sf.openrocket.plugin.example; - -import java.awt.Component; -import java.util.Arrays; -import java.util.List; - -import net.sf.openrocket.plugin.Configurable; -import net.sf.openrocket.plugin.SwingConfigurator; -import net.sf.openrocket.plugin.framework.Service; -import net.sf.openrocket.simulation.listeners.AbstractSimulationListener; -import net.sf.openrocket.util.BugException; -import net.xeoh.plugins.base.Plugin; -import net.xeoh.plugins.base.annotations.Capabilities; - -public abstract class OpenRocketSimulationListener extends AbstractSimulationListener - implements Plugin, Service, SwingConfigurator, Configurable { - - private final String[] ids; - private final String[] capabilities; - - public OpenRocketSimulationListener(String... ids) { - if (ids.length == 0) { - ids = new String[] { this.getClass().getCanonicalName() }; - } - - this.ids = ids.clone(); - this.capabilities = new String[ids.length * 2]; - for (int i = 0; i < ids.length; i++) { - capabilities[i * 2] = ids[i] + ":service"; - capabilities[i * 2 + 1] = ids[i] + ":config"; - } - - } - - @Capabilities - public String[] capabilities() { - return capabilities.clone(); - } - - @SuppressWarnings("unchecked") - @Override - public List getPlugins(Class e, Object... args) { - if (e != this.getClass()) { - throw new BugException("Attempting to get plugin of type " + e + " but I am of type " + this.getClass()); - } - try { - return (List) Arrays.asList(this.getClass().newInstance()); - } catch (IllegalAccessException e1) { - throw new BugException("Could not instantiate new object of type " + this.getClass(), e1); - } catch (InstantiationException e2) { - throw new BugException("Could not instantiate new object of type " + this.getClass(), e2); - } - } - - - @Override - public boolean isConfigurable(OpenRocketSimulationListener plugin) { - return plugin.isConfigurable(); - } - - @Override - public Component getConfigurationComponent(OpenRocketSimulationListener plugin) { - return plugin.getConfigurationComponent(); - } - - public abstract boolean isConfigurable(); - - public abstract Component getConfigurationComponent(); - - - - @Override - public String getPluginID() { - return ids[0]; - } - - @Override - public boolean isCompatible(String pluginID) { - for (String id : ids) { - if (pluginID.equals(id)) { - return true; - } - } - return false; - } - - -} diff --git a/core/src/net/sf/openrocket/plugin/example/stuff.txt b/core/src/net/sf/openrocket/plugin/example/stuff.txt deleted file mode 100644 index e4a4fc3c3..000000000 --- a/core/src/net/sf/openrocket/plugin/example/stuff.txt +++ /dev/null @@ -1,135 +0,0 @@ - - - -Plugin: - -foo() -bar() -getValue() -setValue() - - - -Service: - -getPlugins(args...) -capabilities() -> "pluginid:service" - - - -SwingConfigurator: - -getConfigurationComponent(plugin) -capabilities() -> "pluginid:config" - - - - -OpenRocketSimulationListener extends SimulationListener implements Service, SwingConfigurator: - - -constructor: - pluginid = class name - - -getPlugins(): - return new this - -capabilities: pluginid:service, pluginid:config - -getConfigurationComponent(plugin) - plugin.getConfigurationComponent() - -abstract getConfigurationComponent() - - - - - -Types of plugins: - - -AtmosphericModel - - Name -> dropdown - - Config component -> dialog window (or button) - - stateful, non-dynamic - - stored - - -SimulationListener - - Name + menu position -> Add extension menu - - Config component -> dialog after edit button - - stateful, (dynamic?) - - stored - - -OptimizationModifier - - contains its own name, description, related object - - config N/A - - stateful, dynamic - - not stored - - -OptimizationParameter - - name - - config N/A - - stateful, (dynamic?) - - not stored - - -PluginDialogWindow - - name + menu position -> Menu - - stateful, non-dynamic - - not stored - - -Motor - - Name -> Config tab - - Config component -> tab contents ???? - - or a separate configuration interface? - - stored - - - -Name is common - out, instead have name separately in plugin interfaces? -Menu position used twice - out - -Leave common configuration out - -> :config supported by those that make sense - -> may have separate interface from SwingConfigurator (e.g. SwingMotorConfigurator) - -Motor - -> :loader separately? for injecting placeholders - or store data and call loaders later - - - - - - 100.0 - - Gold - bulk - 16000 - - - - - - 100.0 - - Gold - bulk - 16000 - - - - - - - - - - - - diff --git a/core/src/net/sf/openrocket/plugin/framework/AbstractService.java b/core/src/net/sf/openrocket/plugin/framework/AbstractService.java deleted file mode 100644 index eca8a2a0d..000000000 --- a/core/src/net/sf/openrocket/plugin/framework/AbstractService.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.sf.openrocket.plugin.framework; - -import java.util.Collections; -import java.util.List; - -import net.sf.openrocket.util.BugException; - -/** - * An abstract service implementation that returns plugins of type P. - * - * @param

the plugin type that this service returns. - * @author Sampo Niskanen - */ -public abstract class AbstractService

implements Service { - - private final Class

type; - - protected AbstractService(Class

type) { - this.type = type; - } - - @SuppressWarnings("unchecked") - @Override - public List getPlugins(Class e, Object... args) { - - if (e != type) { - return Collections.emptyList(); - } - - List

plugins = getPlugins(args); - - // Check list content types to avoid mysterious bugs later on - for (P p : plugins) { - if (!type.isInstance(p)) { - throw new BugException("Requesting plugins of type " + type + " but received " + - ((p != null) ? p.getClass() : "null")); - } - } - - return (List) plugins; - } - - protected abstract List

getPlugins(Object... args); - -} diff --git a/core/src/net/sf/openrocket/plugin/framework/JSPFPluginFactory.java b/core/src/net/sf/openrocket/plugin/framework/JSPFPluginFactory.java deleted file mode 100644 index f75cf36cf..000000000 --- a/core/src/net/sf/openrocket/plugin/framework/JSPFPluginFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -package net.sf.openrocket.plugin.framework; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; - -import net.sf.openrocket.util.BugException; -import net.xeoh.plugins.base.Plugin; -import net.xeoh.plugins.base.PluginManager; -import net.xeoh.plugins.base.impl.PluginManagerFactory; -import net.xeoh.plugins.base.util.JSPFProperties; -import net.xeoh.plugins.base.util.PluginManagerUtil; - -public class JSPFPluginFactory implements PluginFactory { - - private final PluginManager pluginManager; - - public JSPFPluginFactory() { - - final JSPFProperties props = new JSPFProperties(); - - // props.setProperty(PluginManager.class, "cache.enabled", "true"); - // props.setProperty(PluginManager.class, "cache.mode", "weak"); //optional - // props.setProperty(PluginManager.class, "cache.file", "jspf.cache"); - - try { - pluginManager = PluginManagerFactory.createPluginManager(props); - pluginManager.addPluginsFrom(new URI("classpath://*")); - } catch (URISyntaxException e) { - throw new BugException(e); - } - } - - @Override - public List getPlugins(Class e, Object... args) { - - List plugins = new ArrayList(); - - PluginManagerUtil pluginManagerUtil = new PluginManagerUtil(pluginManager); - plugins.addAll(pluginManagerUtil.getPlugins(e)); - - for (Service s : pluginManagerUtil.getPlugins(Service.class)) { - plugins.addAll(s.getPlugins(e, args)); - } - - return plugins; - - } -} diff --git a/core/src/net/sf/openrocket/plugin/framework/PluginFactory.java b/core/src/net/sf/openrocket/plugin/framework/PluginFactory.java deleted file mode 100644 index 25b6cbfd3..000000000 --- a/core/src/net/sf/openrocket/plugin/framework/PluginFactory.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sf.openrocket.plugin.framework; - -import java.util.List; - -import net.xeoh.plugins.base.Plugin; - -public interface PluginFactory { - - public List getPlugins(Class e, Object... args); - -} diff --git a/core/src/net/sf/openrocket/plugin/framework/Service.java b/core/src/net/sf/openrocket/plugin/framework/Service.java deleted file mode 100644 index ee56b8e4e..000000000 --- a/core/src/net/sf/openrocket/plugin/framework/Service.java +++ /dev/null @@ -1,30 +0,0 @@ -package net.sf.openrocket.plugin.framework; - -import java.util.List; - -import net.xeoh.plugins.base.Plugin; - -/** - * A discovery service that returns plugins of a specified type with - * provided arguments. - * - * @author Sampo Niskanen - */ -public interface Service extends Plugin { - - /** - * Return the plugins that match the provided type and are applicable - * for the arguments. The arguments depend on the class type. - *

- * This method may return different plugins for different arguments. - * For example, if the arguments contain the OpenRocketDocument, the - * service may return only plugins applicable for the specified document. - * - * @param type the plugin interface type - * @param args arguments for the interface. - * @return the plugin instances applicable. - */ - public List getPlugins(Class type, Object... args); - - -}