/* * (non-Javadoc) * * @see jframe.core.plugin.PluginContext#regPlugins(java.util.Collection, * java.util.Comparator) */ public void regPlugins(Collection<Plugin> plugins, Comparator<? super Plugin> comparator) { if (plugins == null || plugins.size() == 0) return; if (comparator == null) { comparator = new PluginComparator(PluginComparator.TYPE.START); } TreeSet<Plugin> set = new TreeSet<Plugin>(comparator); for (Plugin p : plugins) { if (!set.add(p)) _LOG.warn("Found repeated plugin: " + p.getName()); } Iterator<Plugin> iter = set.iterator(); Plugin p = null; while (iter.hasNext()) { p = iter.next(); try { regPlugin(p); } catch (Exception e) { _LOG.error( "When invoke pluginContext.regPlugin(), plugin name is " + p.getName() + " " + e.getMessage()); unregPlugin(p); } iter.remove(); } }
public PluginRef regPlugin(Plugin plugin) { if (plugin == null) return null; plugin.setID(newPluginID()); try { plugin.init(this); } catch (Exception e) { _LOG.error(e.getMessage()); return null; // TODO } // reg ref before start PluginRef ref = null; synchronized (_plugins) { ref = containRef(plugin); if (ref == null) { ref = new DefPluginRef(this, plugin.getName()); _plugins.put(plugin.getID(), ref); } } ref.setPlugin(plugin); // handleAnnation regDispatch(ref); // set updating false if (ref.isUpdating()) ref.setUpdating(false); // start plugin try { plugin.start(); } catch (PluginException e) { unregPlugin(plugin); _LOG.error("Plugin start error: " + plugin.getName() + e.getLocalizedMessage()); return null; } return ref; }
/** * Unloads the plugin. The effectively shuts the plugin down and removes it from the * PluginRegistry's resource loaders. * * @throws Exception */ public synchronized void unload() throws Exception { if (plugin != null) { plugin.stop(); // it's important that the plugin be removed from the resource loading system after shutdown // in // case the plugin needs to access the resource loader during shutdown registry.removeResourceLoader(plugin.getName()); } loaded = false; }
/** * (non-Javadoc) * * @see jframe.core.plugin.PluginContext#containRef(jframe.core.plugin.Plugin) * @return if find PluginRef return it, or return null */ private PluginRef containRef(Plugin plugin) { Iterator<PluginRef> iter = _plugins.values().iterator(); PluginRef ref = null; while (iter.hasNext()) { ref = iter.next(); if (ref.getPluginName().equals(plugin.getName())) { return ref; } } return null; }
private WPPluginManager(UUID uuid, String logPrefix, ClassLoader classLoader) { allPlugins = org.pepsoft.util.PluginManager.findPlugins(Plugin.class, FILENAME, classLoader); Set<String> namesEncountered = new HashSet<>(); for (Iterator<Plugin> i = allPlugins.iterator(); i.hasNext(); ) { Plugin plugin = i.next(); if ((plugin.getUUIDs() != null) && (uuid != null) && (!plugin.getUUIDs().contains(uuid))) { logger.error( logPrefix + plugin.getName() + " plugin is not authorised for this installation; not loading it"); i.remove(); continue; } String name = plugin.getName(); if (namesEncountered.contains(name)) { throw new RuntimeException("Multiple plugins with the same name (" + name + ") detected!"); } else { namesEncountered.add(name); } logger.info(logPrefix + "Loaded plugin: " + name + " (version " + plugin.getVersion() + ")"); } }
private void addMenuToTray() { HashMap categories = new HashMap(); // create menu list Iterator plugins = PluginManager.getInstance().getAvailablePlugins(); plugins = PluginComparator.sortPlugins(plugins); while (plugins.hasNext()) { Plugin p = (Plugin) plugins.next(); JMenu category = (JMenu) categories.get(p.getCategory()); if (category == null) { category = new JMenu(p.getCategory()); categories.put(p.getCategory(), category); // copy menu to real one if (!p.getCategory().equals("Invisible")) this.trayIcon.add(category); } ImageIcon icon = new ImageIcon(); try { icon = new ImageIcon(new URL(p.getDirectory() + p.getIcon())); icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH)); } catch (Exception e) { // error at icon loading } JMenuItem menu = new JMenuItem(p.getTitle(), icon); menu.setName(p.getName()); menu.setToolTipText(p.getToolTip()); menu.addActionListener(this); category.add(menu); } this.trayIcon.addSeparator(); // windows this.trayIcon.add(new WindowMenu(this)); // open main interface JMenuItem menu = new JMenuItem(tr("open")); menu.setName("org.lucane.applications.maininterface"); menu.addActionListener(this); this.trayIcon.add(menu); // exit menu = new JMenuItem(tr("exit")); menu.setName("exit"); menu.addActionListener(this); this.trayIcon.add(menu); }
/* * (non-Javadoc) * * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(Plugin o1, Plugin o2) { int v = 0; jframe.core.plugin.annotation.Plugin ap1 = o1.getClass().getAnnotation(jframe.core.plugin.annotation.Plugin.class); jframe.core.plugin.annotation.Plugin ap2 = o2.getClass().getAnnotation(jframe.core.plugin.annotation.Plugin.class); switch (type) { case START: { v = minus(ap1.startOrder(), ap2.startOrder()); break; } case STOP: { v = minus(ap1.stopOrder(), ap2.stopOrder()); break; } } if (v == 0) { v = o1.getName().compareTo(o2.getName()); } return v; }
public String getLoadPluginJavaScript() { StringBuffer loadPluginJavaScript = new StringBuffer(); if (plugins.size() > 0) { Iterator<Plugin> iterator = plugins.iterator(); while (iterator.hasNext()) { Plugin plugin = iterator.next(); String pluginPath = plugin.getPluginPath(); if (pluginPath != null && pluginPath.equals("") == false) { loadPluginJavaScript.append("tinymce.PluginManager.load('"); loadPluginJavaScript.append(plugin.getName()); loadPluginJavaScript.append("','"); loadPluginJavaScript.append(pluginPath); loadPluginJavaScript.append("');\n"); } } } return loadPluginJavaScript.toString(); }
void addPlugins(StringBuffer buffer) { if (plugins.size() > 0) { buffer.append(",\n\t").append("plugins : ").append("\""); Iterator<Plugin> iterator = plugins.iterator(); int count = 0; while (iterator.hasNext()) { Plugin plugin = iterator.next(); if (count > 0) buffer.append(", "); // if the plugin has a plugin path set, assume it's external // and will be loaded by tinymce.PluginManager.load String pluginPath = plugin.getPluginPath(); if (pluginPath != null && !pluginPath.equals("")) { buffer.append("-"); // do not load twice! } buffer.append(plugin.getName()); count++; } buffer.append("\""); } }
@Test public void testHotDeploy() throws Exception { // Grab the ServerPluginRegistry PluginRegistry theRegistry = PluginUtils.getPluginRegistry(); assertNotNull("PluginRegistry should exist.", theRegistry); assertTrue(theRegistry instanceof ServerPluginRegistry); ServerPluginRegistry registry = (ServerPluginRegistry) theRegistry; // Let's shut down the asynchronous reloader and hot deployer because we want to do this // synchronously. HotDeployer hotDeployer = registry.getHotDeployer(); Reloader reloader = registry.getReloader(); registry.stopHotDeployer(); registry.stopReloader(); // Assert that there are currently no plugins assertEquals("There should be no plugins.", 0, registry.getPluginEnvironments().size()); assertEquals( "Resource loader should have no children.", 0, registry.getResourceLoaders().size()); // query the hot deployer directly about it's added and removed plugins assertEquals("There should be no plugins added.", 0, hotDeployer.getAddedPlugins().size()); assertEquals("There should be no plugins removed.", 0, hotDeployer.getRemovedPlugins().size()); hotDeployer.run(); assertEquals("There should still be no plugins.", 0, registry.getPluginEnvironments().size()); // now let's copy a plugin over and run the hot deployer String pluginZipFileLocation = getBaseDir() + "/src/test/resources/org/kuali/rice/kew/plugin/ziptest.zip"; File pluginZipFile = new File(pluginZipFileLocation); assertTrue("Plugin file '" + pluginZipFileLocation + "' should exist", pluginZipFile.exists()); assertTrue( "Plugin file '" + pluginZipFileLocation + "' should be a file", pluginZipFile.isFile()); FileUtils.copyFileToDirectory(pluginZipFile, pluginDir); assertEquals("There should be one plugin added.", 1, hotDeployer.getAddedPlugins().size()); assertEquals("There should be no plugins removed.", 0, hotDeployer.getRemovedPlugins().size()); hotDeployer.run(); // the plugin should have been hot deployed assertEquals( "Plugin should have been hot deployed.", 1, registry.getPluginEnvironments().size()); // check added plugins again, it should now indicate no new added plugins assertEquals("There should be no plugins added.", 0, hotDeployer.getAddedPlugins().size()); assertEquals("There should be no plugins removed.", 0, hotDeployer.getRemovedPlugins().size()); // verify that the resource loading and the registry are sane and properly set up with the new // plugin assertEquals( "Resource loader should have 1 plugin child.", 1, registry.getResourceLoaders().size()); Plugin plugin = (Plugin) registry.getResourceLoaders().get(0); assertEquals( "Plugin has wrong name.", new QName(CoreConfigHelper.getApplicationId(), "ziptest"), plugin.getName()); assertTrue("Plugin should be started.", plugin.isStarted()); assertEquals( "Plugin in resource loader and environment should be the same.", plugin, registry.getPluginEnvironment(plugin.getName().getLocalPart()).getPlugin()); // The reloader should have a reference to the environment assertEquals( "Reloader should have a reference to environment.", 1, reloader.getReloadables().size()); // now remove the plugin and ensure that it goes away FileUtils.forceDelete(new File(pluginDir, "ziptest.zip")); assertEquals("There should be no plugins added.", 0, hotDeployer.getAddedPlugins().size()); assertEquals("There should be one plugin removed.", 1, hotDeployer.getRemovedPlugins().size()); hotDeployer.run(); // verify that the resource loading and the registry no longer contain the plugin assertEquals("No plugins should be deployed.", 0, registry.getPluginEnvironments().size()); assertEquals( "Resource loader should have 0 plugin children.", 0, registry.getResourceLoaders().size()); // also assert that the reloader no longer has a reference to the environment assertEquals( "Reloader should no longer have reference to environment.", 0, reloader.getReloadables().size()); }
/** * Returns true if the plugin has the same name and logger repository as the testPlugin passed in. * * @param testPlugin The plugin to test equivalency against. * @return Returns true if testPlugin is considered to be equivalent. */ public boolean isEquivalent(Plugin testPlugin) { return (repository == testPlugin.getLoggerRepository()) && ((this.name == null && testPlugin.getName() == null) || (this.name != null && name.equals(testPlugin.getName()))) && this.getClass().equals(testPlugin.getClass()); }
public static void setCurrentPlugin(Plugin plugin) { Logger.debug("Setting current plugin : " + mContext.getString(plugin.getName())); mCurrentPlugin = plugin; }