Search in sources :

Example 26 with Project

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

the class MainFrame method shouldDisplayIssueIgnoringPackagePrefixes.

// @SuppressWarnings({ "SimplifiableIfStatement" })
private boolean shouldDisplayIssueIgnoringPackagePrefixes(BugInstance b) {
    Project project = getProject();
    Filter suppressionFilter = project.getSuppressionFilter();
    if (null == getBugCollection() || suppressionFilter.match(b)) {
        return false;
    }
    return viewFilter.showIgnoringPackagePrefixes(b);
}
Also used : Project(edu.umd.cs.findbugs.Project) Filter(edu.umd.cs.findbugs.filter.Filter)

Example 27 with Project

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

the class BugLoader method loadProject.

@CheckForNull
public static Project loadProject(MainFrame mainFrame, File f) {
    try {
        Project project = Project.readXML(f);
        project.setGuiCallback(mainFrame.getGuiCallback());
        return project;
    } catch (IOException e) {
        JOptionPane.showMessageDialog(mainFrame, "Could not read " + f + "; " + e.getMessage());
    } catch (SAXException | ParserConfigurationException e) {
        JOptionPane.showMessageDialog(mainFrame, "Could not read  project from " + f + "; " + e.getMessage());
    }
    return null;
}
Also used : Project(edu.umd.cs.findbugs.Project) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) CheckForNull(javax.annotation.CheckForNull)

Example 28 with Project

use of edu.umd.cs.findbugs.Project 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)

Example 29 with Project

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

the class AnalysisRunner method createProject.

@CheckReturnValue
private Project createProject(Path[] files) {
    final Project project = new Project();
    project.setProjectName(getClass().getSimpleName());
    if (PLUGIN_JAR != null) {
        try {
            String pluginId = Plugin.addCustomPlugin(PLUGIN_JAR.toURI()).getPluginId();
            project.setPluginStatusTrinary(pluginId, Boolean.TRUE);
        } catch (PluginException e) {
            throw new AssertionError("Failed to load plugin", e);
        }
    }
    for (Path file : files) {
        project.addFile(file.toAbsolutePath().toString());
    }
    for (Path auxClasspathEntry : auxClasspathEntries) {
        project.addAuxClasspathEntry(auxClasspathEntry.toAbsolutePath().toString());
    }
    return project;
}
Also used : Path(java.nio.file.Path) Project(edu.umd.cs.findbugs.Project) PluginException(edu.umd.cs.findbugs.PluginException) CheckReturnValue(edu.umd.cs.findbugs.annotations.CheckReturnValue)

Example 30 with Project

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

the class UnionResults method merge.

public static void merge(HashSet<String> hashes, SortedBugCollection into, SortedBugCollection from) {
    for (BugInstance bugInstance : from.getCollection()) {
        if (hashes == null || hashes.add(bugInstance.getInstanceHash())) {
            into.add(bugInstance);
        }
    }
    ProjectStats stats = into.getProjectStats();
    ProjectStats stats2 = from.getProjectStats();
    stats.addStats(stats2);
    Project project = into.getProject();
    Project project2 = from.getProject();
    project.add(project2);
    for (AnalysisError error : from.getErrors()) {
        into.addError(error);
    }
    return;
}
Also used : Project(edu.umd.cs.findbugs.Project) ProjectStats(edu.umd.cs.findbugs.ProjectStats) AnalysisError(edu.umd.cs.findbugs.AnalysisError) BugInstance(edu.umd.cs.findbugs.BugInstance)

Aggregations

Project (edu.umd.cs.findbugs.Project)35 SortedBugCollection (edu.umd.cs.findbugs.SortedBugCollection)8 File (java.io.File)8 BugInstance (edu.umd.cs.findbugs.BugInstance)6 AnalysisContext (edu.umd.cs.findbugs.ba.AnalysisContext)4 Test (org.junit.jupiter.api.Test)4 DetectorFactoryCollection (edu.umd.cs.findbugs.DetectorFactoryCollection)3 FindBugs2 (edu.umd.cs.findbugs.FindBugs2)3 Plugin (edu.umd.cs.findbugs.Plugin)3 ProjectStats (edu.umd.cs.findbugs.ProjectStats)3 UserPreferences (edu.umd.cs.findbugs.config.UserPreferences)3 Filter (edu.umd.cs.findbugs.filter.Filter)3 GridBagConstraints (java.awt.GridBagConstraints)3 Insets (java.awt.Insets)3 IOException (java.io.IOException)3 Reporter (de.tobject.findbugs.reporter.Reporter)2 StopTimer (de.tobject.findbugs.util.Util.StopTimer)2 ClassAnnotation (edu.umd.cs.findbugs.ClassAnnotation)2 PackageStats (edu.umd.cs.findbugs.PackageStats)2 PluginException (edu.umd.cs.findbugs.PluginException)2