Search in sources :

Example 1 with BugCollectionBugReporter

use of edu.umd.cs.findbugs.BugCollectionBugReporter in project spotbugs by spotbugs.

the class BugLoader method doAnalysis.

/**
 * Performs an analysis and returns the BugSet created
 *
 * @param p
 *            The Project to run the analysis on
 * @param progressCallback
 *            the progressCallBack is supposed to be supplied by analyzing
 *            dialog, FindBugs supplies progress information while it runs
 *            the analysis
 * @return the bugs found
 * @throws InterruptedException
 * @throws IOException
 */
public static BugCollection doAnalysis(@Nonnull Project p, FindBugsProgress progressCallback) throws IOException, 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());
    fb.setProgressCallback(progressCallback);
    fb.setProjectName(p.getProjectName());
    fb.execute();
    String warnings = stringWriter.toString();
    if (warnings.length() > 0) {
        JTextArea tp = new JTextArea(warnings);
        tp.setEditable(false);
        JScrollPane pane = new JScrollPane(tp);
        pane.setPreferredSize(new Dimension(600, 400));
        JOptionPane.showMessageDialog(MainFrame.getInstance(), pane, "Analysis errors", JOptionPane.WARNING_MESSAGE);
    }
    return pcb.getBugCollection();
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) StringWriter(java.io.StringWriter) IFindBugsEngine(edu.umd.cs.findbugs.IFindBugsEngine) Dimension(java.awt.Dimension) BugCollectionBugReporter(edu.umd.cs.findbugs.BugCollectionBugReporter) PrintWriter(java.io.PrintWriter)

Example 2 with BugCollectionBugReporter

use of edu.umd.cs.findbugs.BugCollectionBugReporter in project spotbugs by spotbugs.

the class AnalysisRunner method run.

@Nonnull
public BugCollectionBugReporter run(Consumer<IFindBugsEngine> engineCustomization, 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);
        engineCustomization.accept(engine);
        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;
    }
}
Also used : UserPreferences(edu.umd.cs.findbugs.config.UserPreferences) Project(edu.umd.cs.findbugs.Project) FindBugs2(edu.umd.cs.findbugs.FindBugs2) IOException(java.io.IOException) DetectorFactoryCollection(edu.umd.cs.findbugs.DetectorFactoryCollection) BugCollectionBugReporter(edu.umd.cs.findbugs.BugCollectionBugReporter) Nonnull(javax.annotation.Nonnull)

Aggregations

BugCollectionBugReporter (edu.umd.cs.findbugs.BugCollectionBugReporter)2 DetectorFactoryCollection (edu.umd.cs.findbugs.DetectorFactoryCollection)1 FindBugs2 (edu.umd.cs.findbugs.FindBugs2)1 IFindBugsEngine (edu.umd.cs.findbugs.IFindBugsEngine)1 Project (edu.umd.cs.findbugs.Project)1 UserPreferences (edu.umd.cs.findbugs.config.UserPreferences)1 Dimension (java.awt.Dimension)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Nonnull (javax.annotation.Nonnull)1 JScrollPane (javax.swing.JScrollPane)1 JTextArea (javax.swing.JTextArea)1