public static void main(String[] args) throws Exception { FindBugs.setNoAnalysis(); DetectorFactoryCollection.instance(); if (args.length != 2) { System.out.println(USAGE); return; } new CopyBuggySource(args).execute(); }
@Nonnull public BugCollectionBugReporter run(Path... files) { DetectorFactoryCollection.resetInstance(new DetectorFactoryCollection()); try (FindBugs2 engine = new FindBugs2(); Project project = createProject(files)) { engine.setProject(project); final DetectorFactoryCollection detectorFactoryCollection = DetectorFactoryCollection.instance(); engine.setDetectorFactoryCollection(detectorFactoryCollection); BugCollectionBugReporter bugReporter = new BugCollectionBugReporter(project); bugReporter.setPriorityThreshold(Priorities.LOW_PRIORITY); bugReporter.setRankThreshold(BugRanker.VISIBLE_RANK_MAX); engine.setBugReporter(bugReporter); final UserPreferences preferences = UserPreferences.createDefaultUserPreferences(); preferences.getFilterSettings().clearAllCategories(); preferences.enableAllDetectors(true); engine.setUserPreferences(preferences); try { engine.execute(); } catch (final IOException | InterruptedException e) { throw new AssertionError("Analysis failed with exception", e); } if (!bugReporter.getQueuedErrors().isEmpty()) { bugReporter.reportQueuedErrors(); throw new AssertionError( "Analysis failed with exception. Check stderr for detail."); } return bugReporter; } }
/** * Constructor. This is not meant to be called directly; use one of the * factory methods instead. */ private ProjectFilterSettings() { DetectorFactoryCollection.instance(); // ensure detectors loaded // initially all known bug categories are active // using SortedSet to allow better revision control on saved sorted // properties this.activeBugCategorySet = new TreeSet<>(DetectorFactoryCollection.instance().getBugCategories()); this.hiddenBugCategorySet = new HashSet<>(); activeBugCategorySet.remove("NOISE"); hiddenBugCategorySet.add("NOISE"); setMinRank(DEFAULT_MIN_RANK); setMinPriority(DEFAULT_PRIORITY); this.displayFalseWarnings = false; }
/** * Get the BugCode */ public @Nonnull BugCode getBugCode() { return DetectorFactoryCollection.instance().getBugCode(abbrev); } /**
/** * Get the description of a bug category. Returns the category if no * description can be found. * * @param category * the category * @return the description of the category */ public String getBugCategoryDescription(String category) { BugCategory bc = DetectorFactoryCollection.instance().getBugCategory(category); return (bc != null ? bc.getShortDescription() : category); } }
/** * Get set of all BugPatterns this detector reports. An empty set means that * we don't know what kind of bug patterns might be reported. */ public Set<BugPattern> getReportedBugPatterns() { Set<BugPattern> result = new TreeSet<>(); StringTokenizer tok = new StringTokenizer(reports, ","); while (tok.hasMoreTokens()) { String type = tok.nextToken(); BugPattern bugPattern = DetectorFactoryCollection.instance().lookupBugPattern(type); if (bugPattern != null) { result.add(bugPattern); } } return result; }
public static void main(String[] argv) throws Exception { DetectorFactoryCollection detectorFactoryCollection = DetectorFactoryCollection.instance(); ExecutionPlan execPlan = new ExecutionPlan(); for (String pluginId : argv) { Plugin plugin = detectorFactoryCollection.getPluginById(pluginId); if (plugin != null) { execPlan.addPlugin(plugin); } } execPlan.build(); System.out.println(execPlan.getNumPasses() + " passes in plan"); execPlan.print(); } }
while (tok.hasMoreTokens()) { String visitorName = tok.nextToken().trim(); DetectorFactory factory = DetectorFactoryCollection.instance().getFactory(visitorName); if (factory == null) { throw new IllegalArgumentException("Unknown detector: " + visitorName); DetectorFactory factory = DetectorFactoryCollection.instance().getFactory(what); if (factory == null) { throw new IllegalArgumentException("Unknown detector: " + what); Plugin plugin = DetectorFactoryCollection.instance().getPluginById(what); if (plugin == null) { throw new IllegalArgumentException("Unknown plugin: " + what); DetectorFactory factory = DetectorFactoryCollection.instance().getFactory(adjustmentTarget); if (factory != null) { factory.setPriorityAdjustment(adjustmentAmount); } else { DetectorFactoryCollection i18n = DetectorFactoryCollection.instance(); BugPattern pattern = i18n.lookupBugPattern(adjustmentTarget); if (pattern == null) { throw new IllegalArgumentException("Unknown detector: " + adjustmentTarget);
@Override public void finishPass() { HashSet<BugPattern> claimedReported = new HashSet<>(); for (DetectorFactory d : DetectorFactoryCollection.instance().getFactories()) { claimedReported.addAll(d.getReportedBugPatterns()); } for (BugPattern b : DetectorFactoryCollection.instance().getBugPatterns()) { String category = b.getCategory(); if (!b.isDeprecated() && !"EXPERIMENTAL".equals(category) && !claimedReported.contains(b)) { AnalysisContext.logError("No detector claims " + b.getType()); } } }
public SuppressionDecorator(ComponentPlugin<BugReporterDecorator> plugin, BugReporter delegate) { super(plugin, delegate); category = plugin.getProperties().getProperty("category"); if (DetectorFactoryCollection.instance().getBugCategory(category) == null) { throw new IllegalArgumentException("Unable to find category " + category); u = plugin.getPlugin().getResource(adjustmentSource); if (u == null) { u = DetectorFactoryCollection.getCoreResource(adjustmentSource);
public void setCloudId(@Nullable String cloudId) { if (cloudId != null && cloudId.indexOf('.') == -1) { Map<String, CloudPlugin> registeredClouds = DetectorFactoryCollection.instance().getRegisteredClouds(); String check = "." + cloudId; int count = 0; String result = cloudId; for(String name : registeredClouds.keySet()) { if (name.endsWith(check)) { count++; result = name; } } if (count == 1) { cloudId = result; } } this.cloudId = cloudId; }
void loadPlugin(Plugin plugin) { if (FindBugs.DEBUG) { System.out.println("Loading " + plugin.getPluginId()); } pluginByIdMap.put(plugin.getPluginId(), plugin); setGlobalOptions(); // Register all of the detectors that this plugin contains for (DetectorFactory factory : plugin.getDetectorFactories()) { registerDetector(factory); } for (BugCategory bugCategory : plugin.getBugCategories()) { registerBugCategory(bugCategory); } // Register the BugPatterns for (BugPattern bugPattern : plugin.getBugPatterns()) { registerBugPattern(bugPattern); } // Register the BugCodes for (BugCode bugCode : plugin.getBugCodes()) { registerBugCode(bugCode); } }
this.engine.setProject(project); DetectorFactoryCollection detectorFactoryCollection = DetectorFactoryCollection.instance(); engine.setDetectorFactoryCollection(detectorFactoryCollection); UserPreferences preferences = UserPreferences.createDefaultUserPreferences(); for (String factory : enabledDetectors) { DetectorFactory detFactory = detectorFactoryCollection.getFactory(factory); preferences.enableDetector(detFactory, true);
private void addCategoryKey(String argument) { DetectorFactoryCollection i18n = DetectorFactoryCollection.instance(); for (String x : argument.split("[,|]")) { for (BugCategory category : i18n.getBugCategoryObjects()) { if (category.getAbbrev().equals(x) || category.getCategory().equals(x)) { this.categoryKey.add(category.getCategory()); break; } } } }
public static @CheckForNull Plugin addCustomPlugin(URL u, ClassLoader parent) throws PluginException { PluginLoader pluginLoader = PluginLoader.getPluginLoader(u, parent, false, true); Plugin plugin = pluginLoader.loadPlugin(); if (plugin != null) { DetectorFactoryCollection.instance().loadPlugin(plugin); } return plugin; }
public static synchronized void removeCustomPlugin(Plugin plugin) { Set<Entry<URI, Plugin>> entrySet = Plugin.allPlugins.entrySet(); for (Entry<URI, Plugin> entry : entrySet) { if(entry.getValue() == plugin) { Plugin.allPlugins.remove(entry.getKey()); PluginLoader.loadedPluginIds.remove(plugin.getPluginId()); break; } } DetectorFactoryCollection.instance().unLoadPlugin(plugin); }
/** * @param detectorName */ public void adjustForDetector(String detectorName) { DetectorFactory factory = DetectorFactoryCollection.instance().getFactoryByClassName(detectorName); detectorFactory = factory; if (factory != null) { this.priority += factory.getPriorityAdjustment(); boundPriority(); BugPattern bugPattern = getBugPattern(); if (SystemProperties.ASSERTIONS_ENABLED && !"EXPERIMENTAL".equals(bugPattern.getCategory()) && !factory.getReportedBugPatterns().contains(bugPattern)) { AnalysisContext.logError(factory.getShortName() + " doesn't note that it reports " + bugPattern + " in category " + bugPattern.getCategory()); } } }
/** * Get a description for given "bug type". FIXME: this is referred to * elsewhere as the "bug code" or "bug abbrev". Should make the terminology * consistent everywhere. In this case, the bug type refers to the short * prefix code prepended to the long and short bug messages. * * @param shortBugType * the short bug type code * @return the description of that short bug type code means */ public @Nonnull String getBugTypeDescription(String shortBugType) { BugCode bugCode = DetectorFactoryCollection.instance().lookupBugCode(shortBugType); if (bugCode == null) { return L10N.getLocalString("err.missing_code", "Error: missing bug code for key") + " " + shortBugType; } return bugCode.getDescription(); }
while (tok.hasMoreTokens()) { String visitorName = tok.nextToken().trim(); DetectorFactory factory = DetectorFactoryCollection.instance().getFactory(visitorName); if (factory == null) { throw new IllegalArgumentException("Unknown detector: " + visitorName); DetectorFactory factory = DetectorFactoryCollection.instance().getFactory(adjustmentTarget); if (factory != null) { factory.setPriorityAdjustment(adjustmentAmount); } else { DetectorFactoryCollection i18n = DetectorFactoryCollection.instance(); BugPattern pattern = i18n.lookupBugPattern(adjustmentTarget); if (pattern == null) { throw new IllegalArgumentException("Unknown detector: " + adjustmentTarget);
System.out.println("Available plugins:"); int count = 0; for (Iterator<Plugin> i = DetectorFactoryCollection.instance().pluginIterator(); i.hasNext();) { Plugin plugin = i.next(); System.out.println(" " + plugin.getPluginId() + " (default: " + (plugin.isEnabledByDefault() ? "enabled" : "disabled")