protected BugCollection getBugCollection() { return bugReporter.getBugCollection(); }
@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; } }
@Override public void doReportBug(BugInstance bugInstance) { if (VERIFY_INTEGRITY) { checkBugInstance(bugInstance); } if (bugCollection.add(bugInstance)) { notifyObservers(bugInstance); } }
InterruptedException { StringWriter stringWriter = new StringWriter(); BugCollectionBugReporter pcb = new BugCollectionBugReporter(p, new PrintWriter(stringWriter, true)); pcb.setPriorityThreshold(Priorities.LOW_PRIORITY); IFindBugsEngine fb = createEngine(p, pcb); fb.setUserPreferences(getUserPreferences()); return pcb.getBugCollection();
private BugCollectionBugReporter createReporter(Project project) { final BugCollectionBugReporter bugReporter = new BugCollectionBugReporter(project); bugReporter.setPriorityThreshold(Priorities.LOW_PRIORITY); bugReporter.setApplySuppressions(true); return bugReporter; }
engine.setDetectorFactoryCollection(detectorFactoryCollection); bugReporter = new BugCollectionBugReporter(project); bugReporter.setPriorityThreshold(Priorities.LOW_PRIORITY); bugReporter.setRankThreshold(BugRanker.VISIBLE_RANK_MAX);
@Override public void reportMissingClass(ClassNotFoundException ex) { String missing = AbstractBugReporter.getMissingClassName(ex); if (!isValidMissingClassMessage(missing)) { return; } bugCollection.addMissingClass(missing); super.reportMissingClass(ex); }
public BugCollectionBugReporter(Project project, @CheckForNull PrintWriter writer) { this.project = project; this.bugCollection = new SortedBugCollection(getProjectStats(), project); bugCollection.setTimestamp(System.currentTimeMillis()); this.writer = writer; } public Project getProject() {
@Override public void logError(String message, Throwable e) { if (e instanceof MissingClassException) { MissingClassException e2 = (MissingClassException) e; reportMissingClass(e2.getClassNotFoundException()); return; } if (e instanceof MethodUnprofitableException) { // TODO: log this return; } bugCollection.addError(message, e); super.logError(message, e); }
private BugCollectionBugReporter createReporter(Project project) { final BugCollectionBugReporter bugReporter = new BugCollectionBugReporter(project); bugReporter.setPriorityThreshold(Priorities.LOW_PRIORITY); bugReporter.setApplySuppressions(true); return bugReporter; }
@Override public void reportMissingClass(ClassNotFoundException ex) { String missing = AbstractBugReporter.getMissingClassName(ex); if (!isValidMissingClassMessage(missing)) { return; } bugCollection.addMissingClass(missing); super.reportMissingClass(ex); }
public BugCollectionBugReporter(Project project, @CheckForNull PrintWriter writer) { this.project = project; this.bugCollection = new SortedBugCollection(getProjectStats(), project); bugCollection.setTimestamp(System.currentTimeMillis()); this.writer = writer; } public Project getProject() {
@Override public void logError(String message, Throwable e) { if (e instanceof MissingClassException) { MissingClassException e2 = (MissingClassException) e; reportMissingClass(e2.getClassNotFoundException()); return; } if (e instanceof MethodUnprofitableException) { // TODO: log this return; } bugCollection.addError(message, e); super.logError(message, e); }
/** * <p> * Run SpotBugs under given condition, and return its result. * </p> * @param paths * Paths of target class files * @return a {@link BugCollection} which contains all detected bugs. */ // TODO let users specify SlashedClassName, then find its file path automatically @Nonnull public BugCollection performAnalysis(Path... paths) { if (runner == null) { throw new IllegalStateException("Please call this performAnalysis() method in test method"); } return runner.run(paths).getBugCollection(); } }
@Override public void doReportBug(BugInstance bugInstance) { if (VERIFY_INTEGRITY) { checkBugInstance(bugInstance); } if (bugCollection.add(bugInstance)) { notifyObservers(bugInstance); } }
/** * <p> * Run SpotBugs under given condition, and return its result. * </p> * @param paths * Paths of target class files * @return a {@link BugCollection} which contains all detected bugs. */ // TODO let users specify SlashedClassName, then find its file path automatically @Nonnull public BugCollection performAnalysis(Path... paths) { if (runner == null) { throw new IllegalStateException("Please call this performAnalysis() method in test method"); } return runner.run(paths).getBugCollection(); } }
@After public void checkForUnexpectedBugs() { List<BugInstance> unexpectedBugs = new ArrayList<>(); for (BugInstance bug : bugReporter.getBugCollection()) { if (isUnexpectedBug(bug) && bug.getPriority() == Priorities.HIGH_PRIORITY) { unexpectedBugs.add(bug); System.out.println(bug.getMessageWithPriorityTypeAbbreviation()); System.out.println(" " + bug.getPrimarySourceLineAnnotation()); } } if (!unexpectedBugs.isEmpty()) { Assert.fail("Unexpected bugs (" + unexpectedBugs.size() + "):" + getBugsLocations(unexpectedBugs)); } }
/** * Test for expected warnings on ecj compiler (Eclipse) generated classes * Right now this test does nothing if Eclipse UI were not used to compile project. * The main purpose is for developers hacking in Eclipse to see if there are any unexpected * failures with Eclipse generated bytecode. It would be nice to make the test explicit by using * ecj command line compiler and *always* validate both bytecode kinds. */ @Test public void testAllRegressionFilesEcj() throws IOException, InterruptedException { setUpEngine("classesEclipse/"); engine.execute(); // If there are zero bugs, then something's wrong if (bugReporter.getBugCollection().getCollection().isEmpty()) { // TODO better to add ecj compiler and to compile classes with it on build, not with UI. System.err.println("No bugs were reported. Probably Eclipse was not used to compile the project"); } }
/** * Test for expected warnings on javac compiler generated classes */ @Test public void testAllRegressionFilesJavac() throws IOException, InterruptedException { setUpEngine("build/classes/java/main/"); engine.execute(); // If there are zero bugs, then something's wrong assertFalse("No bugs were reported. Something is wrong with the configuration", bugReporter.getBugCollection() .getCollection().isEmpty()); }
/** * <p> * Run SpotBugs under given condition, and return its result. * </p> * @param paths * Paths of target class files * @return a {@link BugCollection} which contains all detected bugs. */ // TODO let users specify SlashedClassName, then find its file path automatically @Nonnull public BugCollection performAnalysis(Path... paths) { if (runner == null) { throw new IllegalStateException("Please call this performAnalysis() method in test method"); } return runner.run(paths).getBugCollection(); } }