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();
}
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;
}
}
Aggregations