@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; } }
excludeBaselineBugs(entry.getKey()); } catch (Exception e) { String message = "Unable to read filter: " + entry.getKey() + " : " + e.getMessage(); if (getBugReporter() != null) { getBugReporter().logError(message, e); } else if (deferredError == null){ deferredError = new IllegalArgumentException(message, e); addFilter(entry.getKey(), true); } catch (Exception e) { String message = "Unable to read filter: " + entry.getKey() + " : " + e.getMessage(); if (getBugReporter() != null) { getBugReporter().logError(message, e); } else if (deferredError == null){ deferredError = new IllegalArgumentException(message, e); addFilter(excludeFilterFile, false); } catch (Exception e) { String message = "Unable to read filter: " + excludeFilterFile + " : " + e.getMessage(); if (getBugReporter() != null) { getBugReporter().logError(message, e); } else if (deferredError == null){ deferredError = new IllegalArgumentException(message, e);
/** * Launch the appropriate UI. * * @throws java.lang.Exception */ public void launch() throws Exception { // Sanity-check the loaded BCEL classes if (!CheckBcel.check()) { System.exit(1); } int launchProperty = getLaunchProperty(); if (GraphicsEnvironment.isHeadless() || launchProperty == TEXTUI) { FindBugs2.main(args); } else if (launchProperty == SHOW_HELP) { ShowHelp.main(args); } else if (launchProperty == SHOW_VERSION) { Version.main(new String[] { "-release" }); } else { Class<?> launchClass = Class.forName("edu.umd.cs.findbugs.gui2.Driver"); Method mainMethod = launchClass.getMethod("main", args.getClass()); mainMethod.invoke(null, (Object) args); } }
FindBugs2 engine = new FindBugs2(); engine.setNoClassOk(true); engine.setMergeSimilarWarnings(false); engine.setBugReporter(bugReporter); engine.setProject(project); engine.setProgressCallback(mock(FindBugsProgress.class)); engine.setDetectorFactoryCollection(DetectorFactoryCollection.instance()); filter.setMinPriority("Low"); engine.setUserPreferences(prefs); engine.execute();
throw new IllegalStateException(ex); final FindBugs2 findbugs = new FindBugs2(); findbugs.setProject(project); final Collection<String> ignored = Collections2.transform( Arrays.asList(BugType.values()), reporter.getProjectStats().getProfiler().start(findbugs.getClass()); reporter.setPriorityThreshold(Detector.LOW_PRIORITY); findbugs.setBugReporter(reporter); findbugs.setDetectorFactoryCollection( DetectorFactoryCollection.instance() ); findbugs.setUserPreferences( UserPreferences.createDefaultUserPreferences() ); findbugs.setNoClassOk(true); findbugs.setScanNestedArchives(true); try { if (args.length > Tv.FOUR) { findbugs.addFilter(args[Tv.FOUR], false); findbugs.execute(); } catch (final IOException | InterruptedException ex) { throw new IllegalStateException(ex);
ExecutorService executorService = Executors.newSingleThreadExecutor(); try { final FindBugs2 engine = new FindBugs2(); engine.setProject(project); xmlBugReporter.setOutputStream(new PrintStream(xmlOutput)); engine.setBugReporter(xmlBugReporter); engine.setUserPreferences(userPreferences); engine.addFilter(configuration.saveIncludeConfigXml().getAbsolutePath(), true); engine.addFilter(filterFile.getAbsolutePath(), false); } else { LOG.warn("FindBugs filter-file not found: {}", filterFile); engine.setDetectorFactoryCollection(DetectorFactoryCollection.instance()); engine.setAnalysisFeatureSettings(FindBugs.DEFAULT_EFFORT); engine.finishSettings();
/** * Create the IFindBugsEngine that will be used to analyze the application. * * @param p * the Project * @param pcb * the PrintCallBack * @return the IFindBugsEngine */ private static IFindBugsEngine createEngine(@Nonnull Project p, BugReporter pcb) { FindBugs2 engine = new FindBugs2(); engine.setBugReporter(pcb); engine.setProject(p); engine.setDetectorFactoryCollection(DetectorFactoryCollection.instance()); // // Honor -effort option if one was given on the command line. // engine.setAnalysisFeatureSettings(Driver.getAnalysisSettingList()); return engine; }
@Override public SpotBugsResult runSpotbugs(SpotBugsSpec spec) throws IOException, InterruptedException { final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { final List<String> args = spec.getArguments(); String[] strArray = args.toArray(new String[0]); Thread.currentThread().setContextClassLoader(FindBugs2.class.getClassLoader()); FindBugs2 findBugs2 = new FindBugs2(); TextUICommandLine commandLine = new TextUICommandLine(); FindBugs.processCommandLine(commandLine, strArray, findBugs2); findBugs2.execute(); return createSpotbugsResult(findBugs2); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); } }
public static void main(String[] args) throws Exception { // Sanity-check the loaded BCEL classes if (!CheckBcel.check()) { System.exit(1); } // Create FindBugs2 engine try (FindBugs2 findBugs = new FindBugs2()) { // Parse command line and configure the engine TextUICommandLine commandLine = new TextUICommandLine(); FindBugs.processCommandLine(commandLine, args, findBugs); boolean justPrintConfiguration = commandLine.justPrintConfiguration(); if (justPrintConfiguration || commandLine.justPrintVersion()) { Version.printVersion(justPrintConfiguration); return; } // Away we go! FindBugs.runMain(findBugs, commandLine); } }
public FindBugsResult analyze() { final Project project = createProject(); final BugCollectionBugReporter bugReporter = createReporter(project); final FindBugs2 findBugs = createFindBugs(project, bugReporter); try { findBugs.execute(); } catch (IOException | InterruptedException e) { throw new AnalyzerException("Problem executing FindBugs.", e); } return createBugList(bugReporter); }
throw new IllegalStateException(ex); final FindBugs2 findbugs = new FindBugs2(); findbugs.setProject(project); final Collection<String> ignored = Collections2.transform( Arrays.asList(BugType.values()), reporter.getProjectStats().getProfiler().start(findbugs.getClass()); reporter.setPriorityThreshold(Detector.LOW_PRIORITY); findbugs.setBugReporter(reporter); findbugs.setDetectorFactoryCollection( DetectorFactoryCollection.instance() ); findbugs.setUserPreferences( UserPreferences.createDefaultUserPreferences() ); findbugs.setNoClassOk(true); findbugs.setScanNestedArchives(true); try { if (args.length > Tv.FOUR) { findbugs.addFilter(args[Tv.FOUR], false); findbugs.execute(); } catch (final IOException | InterruptedException ex) { throw new IllegalStateException(ex);
@Override public void run() { final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { final List<String> args = spec.getArguments(); String[] strArray = args.toArray(new String[0]); Thread.currentThread().setContextClassLoader(FindBugs2.class.getClassLoader()); FindBugs2 findBugs2 = new FindBugs2(); TextUICommandLine commandLine = new TextUICommandLine(); FindBugs.processCommandLine(commandLine, strArray, findBugs2); findBugs2.execute(); SpotBugsResult result = createSpotbugsResult(findBugs2); evaluateResult(result); } catch (IOException | InterruptedException e) { throw new GradleException("Error initializing SpotBugsRunner", e); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); } }
this.engine = new FindBugs2(); Project project = new Project(); project.setProjectName("spotbugsTestCases");
public FindBugsResult analyze() { final Project project = createProject(); final BugCollectionBugReporter bugReporter = createReporter(project); final FindBugs2 findBugs = createFindBugs(project, bugReporter); try { findBugs.execute(); } catch (IOException | InterruptedException e) { throw new AnalyzerException("Problem executing FindBugs.", e); } return createBugList(bugReporter); }
FindBugs2 engine = new FindBugs2(); engine.setBugReporter(new PrintingBugReporter()); project.addFile(tmpdir.getAbsolutePath()); engine.setProject(project); PluginLoader fakeLoader = new PluginLoader(true, tmpfile.toURL()); Plugin fakePlugin = new Plugin("edu.umd.cs.findbugs.fakeplugin", null, null, fakeLoader, true, false); engine.setDetectorFactoryCollection(dfc); engine.setUserPreferences(UserPreferences.createDefaultUserPreferences()); engine.execute();
public static void main(String[] args) throws Exception { // Sanity-check the loaded BCEL classes if (!CheckBcel.check()) { System.exit(1); } // Create FindBugs2 engine FindBugs2 findBugs = new FindBugs2(); // Parse command line and configure the engine TextUICommandLine commandLine = new TextUICommandLine(); FindBugs.processCommandLine(commandLine, args, findBugs); boolean justPrintConfiguration = commandLine.justPrintConfiguration(); if (justPrintConfiguration || commandLine.justPrintVersion()) { Version.printVersion(justPrintConfiguration); return; } // Away we go! FindBugs.runMain(findBugs, commandLine); }
excludeBaselineBugs(entry.getKey()); } catch (Exception e) { String message = "Unable to read filter: " + entry.getKey() + " : " + e.getMessage(); if (getBugReporter() != null) { getBugReporter().logError(message, e); } else if (deferredError == null){ deferredError = new IllegalArgumentException(message, e); addFilter(entry.getKey(), true); } catch (Exception e) { String message = "Unable to read filter: " + entry.getKey() + " : " + e.getMessage(); if (getBugReporter() != null) { getBugReporter().logError(message, e); } else if (deferredError == null){ deferredError = new IllegalArgumentException(message, e); addFilter(excludeFilterFile, false); } catch (Exception e) { String message = "Unable to read filter: " + excludeFilterFile + " : " + e.getMessage(); if (getBugReporter() != null) { getBugReporter().logError(message, e); } else if (deferredError == null){ deferredError = new IllegalArgumentException(message, e);
/** * Run findbugs on the provided directory. If findbugs fails, the first found bug is printed out as xml. */ private static void runFindbugs(File classDir) throws Exception { ClassLoader classLoader = HollowCodeGenerationCompileUtil.class.getClassLoader(); FindBugs2.main(new String[]{"-auxclasspath", System.getProperty(PROPERTY_CLASSPATH), "-output", classLoader.getResource("").getFile() + FILENAME_FINDBUGS, classDir.getAbsolutePath()}); BufferedReader reader = new BufferedReader(new InputStreamReader(classLoader.getResourceAsStream(FILENAME_FINDBUGS))); String line = ""; String foundBug = null; while ((line = reader.readLine()) != null) { // poor man's xml parser if (line.contains("<BugInstance")) { foundBug = line; } else if (foundBug != null) { foundBug += "\n" + line; } if (line.contains("</BugInstance>")) { throw new Exception("Findbugs found an error:\n" + foundBug); } } }
private FindBugs2 createFindBugs(Project project, BugCollectionBugReporter bugReporter) { final FindBugs2 findBugs = new FindBugs2(); findBugs.setProject(project); findBugs.setBugReporter(bugReporter); findBugs.setDetectorFactoryCollection(DetectorFactoryCollection.instance()); findBugs.setUserPreferences(UserPreferences.createDefaultUserPreferences()); return findBugs; }