/** * Loads the given plugin and enables it for the given project. */ public static Plugin loadCustomPlugin(URL urlString, @CheckForNull Project project) throws PluginException { Plugin plugin = addCustomPlugin(urlString); if (project != null) { project.setPluginStatusTrinary(plugin.getPluginId(), true); } return plugin; }
/** * Loads the given plugin and enables it for the given project. * * @param f * A non-null jar file of custom plugin. * @param project * A nullable target project */ public static Plugin loadCustomPlugin(File f, @CheckForNull Project project) throws PluginException { URL urlString; try { urlString = f.toURI().toURL(); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } return loadCustomPlugin(urlString, project); }
Plugin existingPlugin = Plugin.getByPluginId(pluginId); URL u = existingPlugin == null ? null : existingPlugin.getPluginLoader().getURL(); if (cannotDisable && initialPlugin) { throw new DuplicatePluginIdError(pluginId, loadedFrom, u); Plugin constructedPlugin = new Plugin(pluginId, version, parsedDate, this, !optionalPlugin, cannotDisable); constructedPlugin.setProvider(provider); constructedPlugin.setWebsite(website); } catch (URISyntaxException e1) { AnalysisContext.logError("Plugin " + constructedPlugin.getPluginId() + " has invalid website: " + website, e1); if (!"".equals(updateUrl)) { try { constructedPlugin.setUpdateUrl(updateUrl); } catch (URISyntaxException e1) { AnalysisContext.logError("Plugin " + constructedPlugin.getPluginId() + " has invalid update check URL: " + website, e1); constructedPlugin.setShortDescription(pluginShortDesc.getText().trim()); constructedPlugin.setDetailedDescription(detailedDescription.getText().trim()); String key = optionNode.valueOf("@key"); String value = optionNode.getText().trim(); constructedPlugin.setMyGlobalOption(key, value);
/** * Enable or disable all known Detectors. * * @param enable * true if all detectors should be enabled, false if they should * all be disabled */ public void enableAllDetectors(boolean enable) { detectorEnablementMap.clear(); Collection<Plugin> allPlugins = Plugin.getAllPlugins(); for (Plugin plugin : allPlugins) { for (DetectorFactory factory : plugin.getDetectorFactories()) { detectorEnablementMap.put(factory.getShortName(), enable); } } }
return; for (Plugin plugin : Plugin.getAllPlugins()) { LOG.info("Plugin {}, version {}, loaded from {}", plugin.getPluginId(), plugin.getVersion(), plugin.getPluginLoader().getURL()); if (plugin.isCorePlugin()) { LOG.info(" is core plugin"); if (plugin.isInitialPlugin()) { LOG.info(" is initial plugin"); if (plugin.isEnabledByDefault()) { LOG.info(" is enabled by default"); if (plugin.isGloballyEnabled()) { LOG.info(" is globally enabled"); Plugin parent = plugin.getParentPlugin(); if (parent != null) { LOG.info(" has parent plugin {}", parent.getPluginId()); for (DetectorFactory factory : plugin.getDetectorFactories()) { LOG.info(" detector {}", factory.getShortName());
@DottedClassName String componentKindname = componentNode.valueOf("@componentKind"); if (componentKindname == null) { throw new PluginException("Missing @componentKind for " + plugin.getPluginId() + " loaded from " + loadedFrom); throw new PluginException("Missing @componentClassname for " + plugin.getPluginId() + " loaded from " + loadedFrom); throw new PluginException("Missing @id for " + plugin.getPluginId() + " loaded from " + loadedFrom); URL properiesURL = classLoaderForResources.getResource(propertiesLocation); if (properiesURL == null) { AnalysisContext.logError("Could not load properties for " + plugin.getPluginId() + " component " + componentId + " from " + propertiesLocation); continue; String className = main.valueOf("@class"); if (className == null) { throw new PluginException("Missing @class for FindBugsMain in plugin" + plugin.getPluginId() + " loaded from " + loadedFrom); throw new PluginException("Missing @cmd for for FindBugsMain in plugin " + plugin.getPluginId() + " loaded from " + loadedFrom); try { Class<?> mainClass = classLoader.loadClass(className); plugin.addFindBugsMain(mainClass, cmd, description, kind, analysis); } catch (Exception e) {
void unLoadPlugin(Plugin plugin) { pluginByIdMap.remove(plugin.getPluginId()); setGlobalOptions(); for (DetectorFactory factory : plugin.getDetectorFactories()) { unRegisterDetector(factory); } for (BugCategory bugCategory : plugin.getBugCategories()) { unRegisterBugCategory(bugCategory); } for (BugPattern bugPattern : plugin.getBugPatterns()) { unRegisterBugPattern(bugPattern); } for (BugCode bugCode : plugin.getBugCodes()) { unRegisterBugCode(bugCode); } }
@Override public String toString() { String s = "All reporting detectors"; if (plugin != null) { s += " in plugin " + plugin.getPluginId(); } return s; } }
} else if ("-plugins".equals(arg)) { DetectorFactoryCollection.instance(); for(Plugin p : Plugin.getAllPlugins()) { LOG.info("Plugin: {}", p.getPluginId()); LOG.info(" description: {}", p.getShortDescription()); LOG.info(" provider: {}", p.getProvider()); String version = p.getVersion(); if (version != null && version.length() > 0) { LOG.info(" version: {}", version); String website = p.getWebsite(); if (website != null && website.length() > 0) { LOG.info(" website: {}", website);
String pluginId = pluginLoader.getPlugin().getPluginId(); assert pluginLoader.hasParent(); String parentid = pluginLoader.parentId; Plugin parent = Plugin.getByPluginId(parentid); if (parent != null) { i.remove(); try { URL[] loaderURLs = PluginLoader.createClassloaderUrls(pluginLoader.loadedFrom); pluginLoader.classLoader = new URLClassLoader(loaderURLs, parent.getClassLoader()); pluginLoader.loadPluginComponents(); Plugin.putPlugin(pluginLoader.loadedFromUri, pluginLoader.plugin); } catch (PluginException e) { throw new RuntimeException("Unable to load plugin " + pluginId, e); System.err.println(msg); AnalysisContext.logError(msg); msg = "Available plugins are " + Plugin.getAllPluginIds(); System.err.println(msg); AnalysisContext.logError(msg); Plugin.removePlugin(pluginLoader.loadedFromUri);
for (Iterator<Plugin> i = DetectorFactoryCollection.instance().pluginIterator(); i.hasNext();) { Plugin plugin = i.next(); System.out.println(" " + plugin.getPluginId() + " (default: " + (plugin.isEnabledByDefault() ? "enabled" : "disabled") + ")"); if (plugin.getShortDescription() != null) { System.out.println(" Description: " + plugin.getShortDescription()); if (plugin.getProvider() != null) { System.out.println(" Provider: " + plugin.getProvider()); if (plugin.getWebsite() != null) { System.out.println(" Website: " + plugin.getWebsite());
pluginPanelCenter.add(new JLabel("Project Setting"), g); Collection<Plugin> plugins = Plugin.getAllPlugins(); int added = 0; for (final Plugin plugin : plugins) { if (plugin.isCorePlugin()) { continue; String text = plugin.getShortDescription(); String id = plugin.getPluginId(); if (text == null) { text = id; final URL url = plugin.getPluginLoader().getURL(); String pluginUrlStr = url.toExternalForm(); if ("file".equals(url.getProtocol())) { final boolean cannotDisable = plugin.isEnabledByDefault() && plugin.cannotDisable(); if (cannotDisable) { if (!enabled.global) { throw new IllegalStateException( plugin.getPluginId() + " is enabled by default and cannot be disabled, but is disabled"); String longText = plugin.getDetailedDescription(); if (longText != null) { checkGlobal.setToolTipText("<html>" + longText + "</html>");
/** * Add a Plugin whose Detectors should be added to the execution plan. */ public void addPlugin(Plugin plugin) throws OrderingConstraintException { if (DEBUG) { System.out.println("Adding plugin " + plugin.getPluginId() + " to execution plan"); } pluginList.add(plugin); // Add ordering constraints copyTo(plugin.interPassConstraintIterator(), interPassConstraintList); copyTo(plugin.intraPassConstraintIterator(), intraPassConstraintList); // Add detector factories for (DetectorFactory factory : plugin.getDetectorFactories()) { if (DEBUG) { System.out.println(" Detector factory " + factory.getShortName()); } if (factoryMap.put(factory.getFullName(), factory) != null) { throw new OrderingConstraintException("Detector " + factory.getFullName() + " is defined by more than one plugin"); } } }
public static @CheckForNull Plugin addCustomPlugin(URI u) throws PluginException { return addCustomPlugin(u, PluginLoader.class.getClassLoader()); }
private static int findRankUnknownPlugin(BugPattern pattern) { List<BugRanker> rankers = new ArrayList<>(); pluginLoop: for (Plugin plugin : Plugin.getAllPlugins()) { if (plugin.isCorePlugin()) { continue; } if (false) { rankers.add(plugin.getBugRanker()); continue pluginLoop; } for (DetectorFactory df : plugin.getDetectorFactories()) { if (df.getReportedBugPatterns().contains(pattern)) { if (PLUGIN_DEBUG) { System.out.println("Bug rank match " + plugin + " " + df + " for " + pattern); } rankers.add(plugin.getBugRanker()); continue pluginLoop; } } if (PLUGIN_DEBUG) { System.out.println("plugin " + plugin + " doesn't match " + pattern); } } rankers.add(getCoreRanker()); return rankBugPattern(pattern, rankers.toArray(new BugRanker[rankers.size()])); }
private void setGlobalOptions() { globalOptions.clear(); globalOptionsSetter.clear(); for(Plugin p : plugins()) { if (p.isGloballyEnabled()) { for(Map.Entry<String, String> e : p.getMyGlobalOptions().entrySet()) { String key = e.getKey(); String value = e.getValue(); String oldValue = globalOptions.get(key); if (oldValue != null) { if (oldValue.equals(value)) { continue; } Plugin oldP = globalOptionsSetter.get(key); throw new RuntimeException( "Incompatible global options for " + key + "; conflict between " + oldP.getPluginId() + " and " + p.getPluginId()); } globalOptions.put(key, value); globalOptionsSetter.put(key, p); } } } }
Plugin fakePlugin = new Plugin("edu.umd.cs.findbugs.fakeplugin", null, null, fakeLoader, true, false); fakePlugin.addDetectorFactory(detectorFactory); dfc.registerDetector(detectorFactory); if (!dfc.factoryIterator().hasNext() || fakePlugin.getDetectorFactories().isEmpty()) { throw new IllegalStateException();
private static void enablePlugins(Iterable<String> plugins, boolean enabled) { for (String pid : plugins) { Plugin plugin = Plugin.getByPluginId(pid); if (plugin != null) { if (!enabled && plugin.cannotDisable()) { JOptionPane.showMessageDialog(null, "Cannot disable plugin: " + plugin.getPluginId() + "\n" + plugin.getShortDescription(), "Cannot disable plugin", JOptionPane.ERROR_MESSAGE); } else { plugin.setGloballyEnabled(enabled); } } } }
try { Plugin plugin = Plugin.loadCustomPlugin(f, PreferencesFrame.this.getCurrentProject()); guiSaveState.setPluginEnabled(plugin.getPluginId()); plugin.setGloballyEnabled(true); guiSaveState.save(); pluginsAdded = true;
for (Plugin plugin : plugins) { xmlOutput.startTag("plugin"); xmlOutput.addAttribute("id", plugin.getPluginId()); xmlOutput.addAttribute("name", plugin.getShortDescription()); xmlOutput.addAttribute("version", plugin.getVersion()); Date date = plugin.getReleaseDate(); if (date != null) { xmlOutput.addAttribute("release-date", Long.toString(date.getTime()));