Search in sources :

Example 16 with Project

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

the class MergeSummarizeAndView method union.

public static SortedBugCollection union(SortedBugCollection origCollection, SortedBugCollection newCollection) {
    SortedBugCollection result = origCollection.duplicate();
    for (Iterator<BugInstance> i = newCollection.iterator(); i.hasNext(); ) {
        BugInstance bugInstance = i.next();
        result.add(bugInstance);
    }
    ProjectStats stats = result.getProjectStats();
    ProjectStats stats2 = newCollection.getProjectStats();
    stats.addStats(stats2);
    Project project = result.getProject();
    project.add(newCollection.getProject());
    return result;
}
Also used : Project(edu.umd.cs.findbugs.Project) ProjectStats(edu.umd.cs.findbugs.ProjectStats) SortedBugCollection(edu.umd.cs.findbugs.SortedBugCollection) BugInstance(edu.umd.cs.findbugs.BugInstance)

Example 17 with Project

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

the class MergeSummarizeAndView method load.

private void load() {
    if (options.workingDirList.isEmpty()) {
        String userDir = System.getProperty("user.dir");
        if (null != userDir && !"".equals(userDir)) {
            options.workingDirList.add(userDir);
        }
    }
    IGuiCallback cliUiCallback = new CommandLineUiCallback();
    for (String analysisFile : options.analysisFiles) {
        try {
            SortedBugCollection more = createPreconfiguredBugCollection(options.workingDirList, options.srcDirList, cliUiCallback);
            more.readXML(analysisFile);
            BugRanker.trimToMaxRank(more, options.maxConsideredRank);
            if (results != null) {
                results = union(results, more);
            } else {
                results = more;
            }
        } catch (IOException e) {
            System.err.println("Trouble reading " + analysisFile);
        } catch (DocumentException e) {
            System.err.println("Trouble parsing " + analysisFile);
        }
    }
    if (results == null) {
        throw new RuntimeException("No files successfully read");
    }
    Project project = results.getProject();
    long old = System.currentTimeMillis() - options.maxAge * (24 * 3600 * 1000L);
    if (options.baselineDate != null) {
        long old2 = options.baselineDate.getTime();
        if (old2 > old) {
            old = old2;
        }
    }
    scaryBugs = results.createEmptyCollectionWithMetadata();
    for (BugInstance warning : results.getCollection()) {
        if (!project.getSuppressionFilter().match(warning)) {
            int rank = BugRanker.findRank(warning);
            if (rank > BugRanker.VISIBLE_RANK_MAX) {
                continue;
            }
            boolean highRank = rank > options.maxRank;
            if (highRank) {
                numLowConfidence++;
            } else {
                scaryBugs.add(warning);
            }
        }
    }
}
Also used : Project(edu.umd.cs.findbugs.Project) CommandLineUiCallback(edu.umd.cs.findbugs.CommandLineUiCallback) SortedBugCollection(edu.umd.cs.findbugs.SortedBugCollection) DocumentException(org.dom4j.DocumentException) IGuiCallback(edu.umd.cs.findbugs.IGuiCallback) BugInstance(edu.umd.cs.findbugs.BugInstance) IOException(java.io.IOException)

Example 18 with Project

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

the class FindNonShortCircuitTest method setup.

@Before
public void setup() {
    PrintingBugReporter bugReporter = new PrintingBugReporter();
    ctx = AnalysisContext.currentAnalysisContext();
    if (ctx == null) {
        AnalysisContext.setCurrentAnalysisContext(new AnalysisContext(new Project()));
    }
    check = new FindNonShortCircuit(bugReporter);
}
Also used : Project(edu.umd.cs.findbugs.Project) AnalysisContext(edu.umd.cs.findbugs.ba.AnalysisContext) PrintingBugReporter(edu.umd.cs.findbugs.PrintingBugReporter) Before(org.junit.Before)

Example 19 with Project

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

the class FindbugsConfigurationTest method should_set_class_path.

@Test
void should_set_class_path() throws IOException {
    File classpath = new File(temp, "classpath");
    when(javaResourceLocator.classpath()).thenReturn(ImmutableList.of(classpath));
    try (Project findbugsProject = new Project()) {
        conf.initializeFindbugsProject(findbugsProject);
        assertThat(findbugsProject.getAuxClasspathEntryList()).contains(classpath.getCanonicalPath());
        conf.stop();
    }
}
Also used : Project(edu.umd.cs.findbugs.Project) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 20 with Project

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

the class FindbugsConfigurationTest method should_warn_of_missing_precompiled_jsp.

@Test
void should_warn_of_missing_precompiled_jsp() throws IOException {
    setupJspProject(false);
    try (Project project = new Project()) {
        conf.initializeFindbugsProject(project);
    }
    // There should be two warnings:
    // - There are JSP but they are not precompiled
    // - Findbugs needs sources to be compiled
    assertThat(logTester.getLogs(LoggerLevel.WARN)).hasSize(2);
}
Also used : Project(edu.umd.cs.findbugs.Project) Test(org.junit.jupiter.api.Test)

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