/** Loads all plugins, calling onLoad, &c. */ private void loadPlugins() { // clear the map commandMap.clearCommands(); commandMap.register("glowstone", new ColorCommand("colors")); commandMap.register("glowstone", new TellrawCommand()); File folder = new File(config.getString(ServerConfig.Key.PLUGIN_FOLDER)); if (!folder.isDirectory() && !folder.mkdirs()) { logger.log(Level.SEVERE, "Could not create plugins directory: " + folder); } // clear plugins and prepare to load pluginManager.clearPlugins(); pluginManager.registerInterface(JavaPluginLoader.class); Plugin[] plugins = pluginManager.loadPlugins(folder); // call onLoad methods for (Plugin plugin : plugins) { try { plugin.onLoad(); } catch (Exception ex) { logger.log(Level.SEVERE, "Error loading " + plugin.getDescription().getFullName(), ex); } } }
private static void updateExistingPluginInfo( IdeaPluginDescriptor descr, IdeaPluginDescriptor existing) { int state = StringUtil.compareVersionNumbers(descr.getVersion(), existing.getVersion()); final PluginId pluginId = existing.getPluginId(); final String idString = pluginId.getIdString(); final JDOMExternalizableStringList installedPlugins = PluginManagerUISettings.getInstance().getInstalledPlugins(); if (!installedPlugins.contains(idString) && !((IdeaPluginDescriptorImpl) existing).isDeleted()) { installedPlugins.add(idString); } final PluginManagerUISettings updateSettings = PluginManagerUISettings.getInstance(); if (state > 0 && !PluginManager.isIncompatible(descr) && !updatedPlugins.contains(descr.getPluginId())) { NewVersions2Plugins.put(pluginId, 1); if (!updateSettings.myOutdatedPlugins.contains(idString)) { updateSettings.myOutdatedPlugins.add(idString); } final IdeaPluginDescriptorImpl plugin = (IdeaPluginDescriptorImpl) existing; plugin.setDownloadsCount(descr.getDownloads()); plugin.setVendor(descr.getVendor()); plugin.setVendorEmail(descr.getVendorEmail()); plugin.setVendorUrl(descr.getVendorUrl()); plugin.setUrl(descr.getUrl()); } else { updateSettings.myOutdatedPlugins.remove(idString); if (NewVersions2Plugins.remove(pluginId) != null) { updatedPlugins.add(pluginId); } } }
public void setUp() throws Exception { super.setUp(); tempDirPath = getTempDir().getAbsolutePath() + File.separator; theDaemon = getMockLockssDaemon(); theDaemon.getAlertManager(); theDaemon.getPluginManager().setLoadablePluginsReady(true); theDaemon.getHashService(); MockSystemMetrics metrics = new MyMockSystemMetrics(); metrics.initService(theDaemon); theDaemon.setSystemMetrics(metrics); theDaemon.setDaemonInited(true); Properties props = new Properties(); props.setProperty(SystemMetrics.PARAM_HASH_TEST_DURATION, "1000"); props.setProperty(SystemMetrics.PARAM_HASH_TEST_BYTE_STEP, "1024"); props.setProperty(ConfigManager.PARAM_PLATFORM_DISK_SPACE_LIST, tempDirPath); ConfigurationUtil.setCurrentConfigFromProps(props); pluginMgr = theDaemon.getPluginManager(); pluginMgr.startService(); theDaemon.getHashService().startService(); metrics.startService(); metrics.setHashSpeed(100); simPlugin = PluginTestUtil.findPlugin(SimulatedPlugin.class); }
private void updatePluginDependencies() { myDependentToRequiredListMap.clear(); final int rowCount = getRowCount(); for (int i = 0; i < rowCount; i++) { final IdeaPluginDescriptor descriptor = getObjectAt(i); final PluginId pluginId = descriptor.getPluginId(); myDependentToRequiredListMap.remove(pluginId); if (descriptor instanceof IdeaPluginDescriptorImpl && ((IdeaPluginDescriptorImpl) descriptor).isDeleted()) continue; final Boolean enabled = myEnabled.get(pluginId); if (enabled == null || enabled.booleanValue()) { PluginManager.checkDependants( descriptor, new Function<PluginId, IdeaPluginDescriptor>() { @Nullable public IdeaPluginDescriptor fun(final PluginId pluginId) { return PluginManager.getPlugin(pluginId); } }, new Condition<PluginId>() { public boolean value(final PluginId dependantPluginId) { final Boolean enabled = myEnabled.get(dependantPluginId); if (enabled == null || !enabled.booleanValue()) { Set<PluginId> required = myDependentToRequiredListMap.get(pluginId); if (required == null) { required = new HashSet<PluginId>(); myDependentToRequiredListMap.put(pluginId, required); } required.add(dependantPluginId); // return false; } return true; } }); if (enabled == null && !myDependentToRequiredListMap.containsKey(pluginId) && !PluginManager.isIncompatible(descriptor)) { myEnabled.put(pluginId, true); } } } }
private void setEnabled(IdeaPluginDescriptor ideaPluginDescriptor, final boolean enabled) { final Collection<String> disabledPlugins = PluginManager.getDisabledPlugins(); final PluginId pluginId = ideaPluginDescriptor.getPluginId(); if (!enabled && !disabledPlugins.contains(pluginId.toString())) { myEnabled.put(pluginId, null); } else { myEnabled.put(pluginId, enabled); } }
// {{{ handleMessage() method @Override public void handleMessage(EBMessage message) { if (message.getSource() == PluginManager.getInstance()) { chooseButton.path = jEdit.getProperty(PluginManager.PROPERTY_PLUGINSET, ""); if (chooseButton.path.length() > 0) { loadPluginSet(chooseButton.path); pluginModel.restoreSelection(new HashSet<String>(), new HashSet<String>()); chooseButton.updateUI(); } } } // }}}
@Override public Set<String> getResourcePaths(String s) { final String pluginPath = "/plugins/" + pluginManager.getName(plugin) + "/"; final Set<String> proxyResults = proxy.getResourcePaths(pluginPath + s); final Set<String> results = new HashSet<>(); for (final String proxyResult : proxyResults) { results.add(proxyResult.replaceFirst(pluginPath, "")); } return results; }
public void appendOrUpdateDescriptor(IdeaPluginDescriptor descriptor) { final PluginId descrId = descriptor.getPluginId(); final IdeaPluginDescriptor existing = PluginManager.getPlugin(descrId); if (existing != null) { updateExistingPlugin(descriptor, existing); } else { myInstalled.add(descriptor); view.add(descriptor); setEnabled(descriptor, true); fireTableDataChanged(); } }
ArchivalUnit getAu() { if (StringUtil.isNullString(formAuid)) { errMsg = "Select an AU"; return null; } ArchivalUnit au = pluginMgr.getAuFromId(formAuid); if (au == null) { errMsg = "No such AU. Select an AU"; return null; } return au; }
private void runPlugin(String pluginName) { ConnectInfo[] friends = null; Plugin plugin = PluginManager.getInstance().getPlugin(pluginName); // get users if (plugin.isStandalone()) friends = new ConnectInfo[0]; else { ListBox userList = new ListBox( null, plugin.getTitle(), tr("msg.selectUsers"), Client.getInstance().getUserList()); Object[] users = userList.selectItems(); if (users != null) { friends = new ConnectInfo[users.length]; for (int i = 0; i < friends.length; i++) friends[i] = Communicator.getInstance().getConnectInfo((String) users[i]); } } // run the plugin if the user didn't click on cancel if (friends != null) PluginManager.getInstance().run(pluginName, friends); }
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); }
public InstalledPluginsTableModel() { super.columns = new ColumnInfo[] {new EnabledPluginInfo(), new MyPluginManagerColumnInfo()}; view = new ArrayList<IdeaPluginDescriptor>(Arrays.asList(PluginManager.getPlugins())); view.addAll(myInstalled); reset(view); ApplicationInfoEx applicationInfo = ApplicationInfoEx.getInstanceEx(); for (Iterator<IdeaPluginDescriptor> iterator = view.iterator(); iterator.hasNext(); ) { @NonNls final String s = iterator.next().getPluginId().getIdString(); if ("com.intellij".equals(s) || applicationInfo.isEssentialPlugin(s)) iterator.remove(); } setSortKey(new RowSorter.SortKey(getNameColumn(), SortOrder.ASCENDING)); }
private void crawlPluginRegistries() { StringBuilder sb = new StringBuilder(); for (ArchivalUnit au : pluginMgr.getAllRegistryAus()) { sb.append(au.getName()); sb.append(": "); try { startCrawl(au, true, false); sb.append("Queued."); } catch (CrawlManagerImpl.NotEligibleException e) { sb.append("Failed: "); sb.append(e.getMessage()); } sb.append("\n"); } statusMsg = sb.toString(); }
/** Show a dialog asking for the friend name */ public void start() { if (this.trayIcon == null) { // no user message if we aren't on windows if (System.getProperty("os.name").startsWith("Win")) DialogBox.error(tr("err.noTray")); else Logging.getLogger().info("Not on windows, running MainInterface instead of QuickLaunch"); PluginManager.getInstance().run(MAIN_INTERFACE, new ConnectInfo[0]); Client.getInstance().setStartupPlugin(MAIN_INTERFACE); return; } addMenuToTray(); this.trayIcon.addMouseListener(this); this.trayIcon.setVisible(true); this.trayIcon.showInfo(tr("lucane.is.ready"), "Lucane Groupware"); }
/** Stops this server. */ @Override public void shutdown() { // Just in case this gets called twice if (isShuttingDown) { return; } isShuttingDown = true; logger.info("The server is shutting down..."); // Disable plugins pluginManager.clearPlugins(); // Kick all players (this saves their data too) for (Player player : getOnlinePlayers()) { player.kickPlayer(getShutdownMessage()); } // Stop the network servers - starts the shutdown process // It may take a second or two for Netty to totally clean up networkServer.shutdown(); if (queryServer != null) { queryServer.shutdown(); } if (rconServer != null) { rconServer.shutdown(); } // Save worlds for (World world : getWorlds()) { logger.info("Saving world: " + world.getName()); unloadWorld(world, true); } // Stop scheduler and console scheduler.stop(); consoleManager.stop(); // Wait for a while and terminate any rogue threads new ShutdownMonitorThread().start(); }
public void updatePluginsList(List<IdeaPluginDescriptor> list) { // For each downloadable plugin we need to know whether its counterpart // is already installed, and if yes compare the difference in versions: // availability of newer versions will be indicated separately. for (IdeaPluginDescriptor descr : list) { PluginId descrId = descr.getPluginId(); IdeaPluginDescriptor existing = PluginManager.getPlugin(descrId); if (existing != null) { if (descr instanceof PluginNode) { updateExistingPluginInfo(descr, existing); } else { view.add(descr); setEnabled(descr); } } } for (IdeaPluginDescriptor descriptor : myInstalled) { if (!view.contains(descriptor)) { view.add(descriptor); } } fireTableDataChanged(); }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component orig = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (myPluginDescriptor != null) { myNameLabel.setText(myPluginDescriptor.getName()); final PluginId pluginId = myPluginDescriptor.getPluginId(); final String idString = pluginId.getIdString(); if (myPluginDescriptor.isBundled()) { myBundledLabel.setText("Bundled"); } else { final String host = myPlugin2host.get(idString); if (host != null) { String presentableUrl = VfsUtil.urlToPath(host); final int idx = presentableUrl.indexOf('/'); if (idx > -1) { presentableUrl = presentableUrl.substring(0, idx); } myBundledLabel.setText("From " + presentableUrl); } else { if (PluginManagerUISettings.getInstance().getInstalledPlugins().contains(idString)) { myBundledLabel.setText("From repository"); } else { myBundledLabel.setText("Custom"); } } } if (myPluginDescriptor instanceof IdeaPluginDescriptorImpl && ((IdeaPluginDescriptorImpl) myPluginDescriptor).isDeleted()) { myNameLabel.setIcon(AllIcons.Actions.Clean); } else if (hasNewerVersion(pluginId)) { myNameLabel.setIcon(AllIcons.Nodes.Pluginobsolete); myPanel.setToolTipText("Newer version of the plugin is available"); } else { myNameLabel.setIcon(AllIcons.Nodes.Plugin); } final Color fg = orig.getForeground(); final Color bg = orig.getBackground(); final Color grayedFg = isSelected ? fg : Color.GRAY; myPanel.setBackground(bg); myNameLabel.setBackground(bg); myBundledLabel.setBackground(bg); myNameLabel.setForeground(fg); final boolean wasUpdated = wasUpdated(pluginId); if (wasUpdated || PluginManager.getPlugin(pluginId) == null) { if (!isSelected) { myNameLabel.setForeground(FileStatus.COLOR_ADDED); } if (wasUpdated) { myPanel.setToolTipText( "Plugin was updated to the newest version. Changes will be available after restart"); } else { myPanel.setToolTipText("Plugin will be activated after restart."); } } myBundledLabel.setForeground(grayedFg); final Set<PluginId> required = myDependentToRequiredListMap.get(pluginId); if (required != null && required.size() > 0) { myNameLabel.setForeground(Color.RED); final StringBuilder s = new StringBuilder(); if (myEnabled.get(pluginId) == null) { s.append("Plugin was not loaded.\n"); } if (required.contains(PluginId.getId("com.intellij.modules.ultimate"))) { s.append("The plugin requires IntelliJ IDEA Ultimate"); } else { s.append("Required plugin").append(required.size() == 1 ? " \"" : "s \""); s.append( StringUtil.join( required, new Function<PluginId, String>() { @Override public String fun(final PluginId id) { final IdeaPluginDescriptor plugin = PluginManager.getPlugin(id); return plugin == null ? id.getIdString() : plugin.getName(); } }, ",")); s.append(required.size() == 1 ? "\" is not enabled!" : "\" are not enabled!"); } myPanel.setToolTipText(s.toString()); } if (PluginManager.isIncompatible(myPluginDescriptor)) { myPanel.setToolTipText( IdeBundle.message( "plugin.manager.incompatible.tooltip.warning", ApplicationNamesInfo.getInstance().getFullProductName())); myNameLabel.setForeground(Color.red); } } return myPanel; }
private void warnAboutMissedDependencies( final Boolean newVal, final IdeaPluginDescriptor... ideaPluginDescriptors) { final Set<PluginId> deps = new HashSet<PluginId>(); final List<IdeaPluginDescriptor> descriptorsToCheckDependencies = new ArrayList<IdeaPluginDescriptor>(); if (newVal) { Collections.addAll(descriptorsToCheckDependencies, ideaPluginDescriptors); } else { descriptorsToCheckDependencies.addAll(view); descriptorsToCheckDependencies.addAll(filtered); descriptorsToCheckDependencies.removeAll(Arrays.asList(ideaPluginDescriptors)); for (Iterator<IdeaPluginDescriptor> iterator = descriptorsToCheckDependencies.iterator(); iterator.hasNext(); ) { IdeaPluginDescriptor descriptor = iterator.next(); final Boolean enabled = myEnabled.get(descriptor.getPluginId()); if (enabled == null || !enabled.booleanValue()) { iterator.remove(); } } } for (final IdeaPluginDescriptor ideaPluginDescriptor : descriptorsToCheckDependencies) { PluginManager.checkDependants( ideaPluginDescriptor, new Function<PluginId, IdeaPluginDescriptor>() { @Nullable public IdeaPluginDescriptor fun(final PluginId pluginId) { return PluginManager.getPlugin(pluginId); } }, new Condition<PluginId>() { public boolean value(final PluginId pluginId) { Boolean enabled = myEnabled.get(pluginId); if (enabled == null) { return false; } if (newVal && !enabled.booleanValue()) { deps.add(pluginId); } if (!newVal) { final PluginId pluginDescriptorId = ideaPluginDescriptor.getPluginId(); for (IdeaPluginDescriptor descriptor : ideaPluginDescriptors) { if (pluginId.equals(descriptor.getPluginId())) { deps.add(pluginDescriptorId); break; } } } return true; } }); } if (!deps.isEmpty()) { final String listOfSelectedPlugins = StringUtil.join( ideaPluginDescriptors, new Function<IdeaPluginDescriptor, String>() { @Override public String fun(IdeaPluginDescriptor pluginDescriptor) { return pluginDescriptor.getName(); } }, ", "); final Set<IdeaPluginDescriptor> pluginDependencies = new HashSet<IdeaPluginDescriptor>(); final String listOfDependencies = StringUtil.join( deps, new Function<PluginId, String>() { public String fun(final PluginId pluginId) { final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(pluginId); assert pluginDescriptor != null; pluginDependencies.add(pluginDescriptor); return pluginDescriptor.getName(); } }, "<br>"); final String message = !newVal ? "<html>The following plugins <br>" + listOfDependencies + "<br>are enabled and depend" + (deps.size() == 1 ? "s" : "") + " on selected plugins. " + "<br>Would you like to disable them too?</html>" : "<html>The following plugins on which " + listOfSelectedPlugins + " depend" + (ideaPluginDescriptors.length == 1 ? "s" : "") + " are disabled:<br>" + listOfDependencies + "<br>Would you like to enable them?</html>"; if (Messages.showOkCancelDialog( message, newVal ? "Enable Dependant Plugins" : "Disable Plugins with Dependency on this", Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE) { for (PluginId pluginId : deps) { myEnabled.put(pluginId, newVal); } updatePluginDependencies(); hideNotApplicablePlugins( newVal, pluginDependencies.toArray(new IdeaPluginDescriptor[pluginDependencies.size()])); } } }
/** * Enable all plugins of the given load order type. * * @param type The type of plugin to enable. */ private void enablePlugins(PluginLoadOrder type) { if (type == PluginLoadOrder.STARTUP) { helpMap.clear(); helpMap.initializeGeneralTopics(); } // load all the plugins Plugin[] plugins = pluginManager.getPlugins(); for (Plugin plugin : plugins) { if (!plugin.isEnabled() && plugin.getDescription().getLoad() == type) { List<Permission> perms = plugin.getDescription().getPermissions(); for (Permission perm : perms) { try { pluginManager.addPermission(perm); } catch (IllegalArgumentException ex) { getLogger() .log( Level.WARNING, "Plugin " + plugin.getDescription().getFullName() + " tried to register permission '" + perm.getName() + "' but it's already registered", ex); } } try { pluginManager.enablePlugin(plugin); } catch (Throwable ex) { logger.log(Level.SEVERE, "Error loading " + plugin.getDescription().getFullName(), ex); } } } if (type == PluginLoadOrder.POSTWORLD) { commandMap.setFallbackCommands(); commandMap.registerServerAliases(); DefaultPermissions.registerCorePermissions(); helpMap.initializeCommands(); // load permissions.yml ConfigurationSection permConfig = config.getConfigFile(ServerConfig.Key.PERMISSIONS_FILE); List<Permission> perms = Permission.loadPermissions( permConfig.getValues(false), "Permission node '%s' in permissions config is invalid", PermissionDefault.OP); for (Permission perm : perms) { try { pluginManager.addPermission(perm); } catch (IllegalArgumentException ex) { getLogger() .log( Level.WARNING, "Permission config tried to register '" + perm.getName() + "' but it's already registered", ex); } } } }
@Override public ClassLoader getClassLoader() { return pluginManager.getPluginClassloader(plugin); }
@Override public InputStream getResourceAsStream(String s) { return pluginManager.getPluginClassloader(plugin).getResourceAsStream(stripLeadingSlash(s)); }
@Override public URL getResource(String s) throws MalformedURLException { return pluginManager.getPluginClassloader(plugin).getResource(stripLeadingSlash(s)); }
public void install(@Nullable final Runnable onSuccess, boolean confirmed) { IdeaPluginDescriptor[] selection = getPluginTable().getSelectedObjects(); if (confirmed || userConfirm(selection)) { final List<PluginNode> list = new ArrayList<PluginNode>(); for (IdeaPluginDescriptor descr : selection) { PluginNode pluginNode = null; if (descr instanceof PluginNode) { pluginNode = (PluginNode) descr; } else if (descr instanceof IdeaPluginDescriptorImpl) { PluginId pluginId = descr.getPluginId(); pluginNode = new PluginNode(pluginId); pluginNode.setName(descr.getName()); pluginNode.setDepends( Arrays.asList(descr.getDependentPluginIds()), descr.getOptionalDependentPluginIds()); pluginNode.setSize("-1"); pluginNode.setRepositoryName(PluginInstaller.UNKNOWN_HOST_MARKER); } if (pluginNode != null) { list.add(pluginNode); ourInstallingNodes.add(pluginNode); } } final InstalledPluginsTableModel installedModel = (InstalledPluginsTableModel) myInstalled.getPluginsModel(); final Set<IdeaPluginDescriptor> disabled = new HashSet<IdeaPluginDescriptor>(); final Set<IdeaPluginDescriptor> disabledDependants = new HashSet<IdeaPluginDescriptor>(); for (PluginNode node : list) { final PluginId pluginId = node.getPluginId(); if (installedModel.isDisabled(pluginId)) { disabled.add(node); } final List<PluginId> depends = node.getDepends(); if (depends != null) { final Set<PluginId> optionalDeps = new HashSet<PluginId>(Arrays.asList(node.getOptionalDependentPluginIds())); for (PluginId dependantId : depends) { if (optionalDeps.contains(dependantId)) continue; final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(dependantId); if (pluginDescriptor != null && installedModel.isDisabled(dependantId)) { disabledDependants.add(pluginDescriptor); } } } } if (suggestToEnableInstalledPlugins(installedModel, disabled, disabledDependants, list)) { myInstalled.setRequireShutdown(true); } try { Runnable onInstallRunnable = new Runnable() { @Override public void run() { for (PluginNode node : list) { installedModel.appendOrUpdateDescriptor(node); } if (!myInstalled.isDisposed()) { getPluginTable().updateUI(); myInstalled.setRequireShutdown(true); } else { boolean needToRestart = false; for (PluginNode node : list) { final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(node.getPluginId()); if (pluginDescriptor == null || pluginDescriptor.isEnabled()) { needToRestart = true; break; } } if (needToRestart) { PluginManagerMain.notifyPluginsUpdated(null); } } if (onSuccess != null) { onSuccess.run(); } } }; Runnable cleanupRunnable = new Runnable() { @Override public void run() { ourInstallingNodes.removeAll(list); } }; PluginManagerMain.downloadPlugins( list, myHost.getPluginsModel().getAllPlugins(), onInstallRunnable, cleanupRunnable); } catch (final IOException e1) { ourInstallingNodes.removeAll(list); PluginManagerMain.LOG.error(e1); //noinspection SSBasedInspection SwingUtilities.invokeLater( new Runnable() { @Override public void run() { IOExceptionDialog.showErrorDialog( IdeBundle.message("action.download.and.install.plugin"), IdeBundle.message("error.plugin.download.failed")); } }); } } }