Search in sources :

Example 1 with ProjectStats

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

the class DefectDensity method main.

public static void main(String[] args) throws Exception {
    if (args.length > 1 || (args.length > 0 && "-help".equals(args[0]))) {
        System.err.println("Usage: " + DefectDensity.class.getName() + " [<infile>]");
        System.exit(1);
    }
    FindBugs.setNoAnalysis();
    BugCollection origCollection = new SortedBugCollection();
    int argCount = 0;
    if (argCount == args.length) {
        origCollection.readXML(System.in);
    } else {
        origCollection.readXML(args[argCount]);
    }
    ProjectStats stats = origCollection.getProjectStats();
    printRow("kind", "name", "density/KNCSS", "bugs", "NCSS");
    double projectDensity = density(stats.getTotalBugs(), stats.getCodeSize());
    printRow("project", origCollection.getCurrentAppVersion().getReleaseName(), projectDensity, stats.getTotalBugs(), stats.getCodeSize());
    for (PackageStats p : stats.getPackageStats()) {
        if (p.getTotalBugs() > 4) {
            double packageDensity = density(p.getTotalBugs(), p.size());
            if (Double.isNaN(packageDensity) || packageDensity < projectDensity) {
                continue;
            }
            printRow("package", p.getPackageName(), packageDensity, p.getTotalBugs(), p.size());
            for (ClassStats c : p.getSortedClassStats()) {
                if (c.getTotalBugs() > 4) {
                    double density = density(c.getTotalBugs(), c.size());
                    if (Double.isNaN(density) || density < packageDensity) {
                        continue;
                    }
                    printRow("class", c.getName(), density, c.getTotalBugs(), c.size());
                }
            }
        }
    }
}
Also used : SortedBugCollection(edu.umd.cs.findbugs.SortedBugCollection) BugCollection(edu.umd.cs.findbugs.BugCollection) ProjectStats(edu.umd.cs.findbugs.ProjectStats) SortedBugCollection(edu.umd.cs.findbugs.SortedBugCollection) PackageStats(edu.umd.cs.findbugs.PackageStats) ClassStats(edu.umd.cs.findbugs.PackageStats.ClassStats)

Example 2 with ProjectStats

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

the class ListBugDatabaseInfo method listVersion.

private static void listVersion(PrintWriter out, @CheckForNull String fileName, boolean formatDates) throws IOException, DocumentException {
    SortedBugCollection origCollection;
    origCollection = new SortedBugCollection();
    if (fileName == null) {
        origCollection.readXML(System.in);
    } else {
        origCollection.readXML(fileName);
    }
    AppVersion appVersion = origCollection.getCurrentAppVersion();
    ProjectStats stats = origCollection.getProjectStats();
    out.print(appVersion.getReleaseName());
    out.print('\t');
    if (formatDates) {
        out.print("\"" + new Date(appVersion.getTimestamp()) + "\"");
    } else {
        out.print(appVersion.getTimestamp());
    }
    out.print('\t');
    out.print(appVersion.getNumClasses());
    out.print('\t');
    out.print(appVersion.getCodeSize());
    out.print('\t');
    out.print(origCollection.getErrors().size());
    out.print('\t');
    out.print(stats.getTotalBugs());
    out.print('\t');
    out.print(stats.getBugsOfPriority(Priorities.HIGH_PRIORITY));
    out.print('\t');
    out.print(stats.getBugsOfPriority(Priorities.NORMAL_PRIORITY));
    out.print('\t');
    out.print(stats.getBugsOfPriority(Priorities.LOW_PRIORITY));
    if (fileName != null) {
        out.print('\t');
        out.print(fileName);
    }
    out.println();
}
Also used : AppVersion(edu.umd.cs.findbugs.AppVersion) ProjectStats(edu.umd.cs.findbugs.ProjectStats) SortedBugCollection(edu.umd.cs.findbugs.SortedBugCollection) Date(java.util.Date)

Example 3 with ProjectStats

use of edu.umd.cs.findbugs.ProjectStats 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 4 with ProjectStats

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

the class Filter method main.

public static void main(String[] args) throws Exception {
    FindBugs.setNoAnalysis();
    DetectorFactoryCollection.instance();
    final FilterCommandLine commandLine = new FilterCommandLine();
    int argCount = commandLine.parse(args, 0, 2, "Usage: " + Filter.class.getName() + " [options] [<orig results> [<new results>]] ");
    SortedBugCollection origCollection = new SortedBugCollection();
    if (argCount == args.length) {
        origCollection.readXML(System.in);
    } else {
        origCollection.readXML(args[argCount++]);
    }
    boolean verbose = argCount < args.length;
    SortedBugCollection resultCollection = origCollection.createEmptyCollectionWithMetadata();
    Project project = resultCollection.getProject();
    int passed = 0;
    int dropped = 0;
    resultCollection.setWithMessages(commandLine.withMessages);
    if (commandLine.hashChangedSpecified) {
        origCollection.computeBugHashes();
    }
    commandLine.adjustFilter(project, resultCollection);
    ProjectStats projectStats = resultCollection.getProjectStats();
    projectStats.clearBugCounts();
    if (commandLine.classPattern != null) {
        projectStats.purgeClassesThatDontMatch(commandLine.classPattern);
    }
    sourceSearcher = new SourceSearcher(project);
    long trimToVersion = -1;
    if (commandLine.trimToVersionAsString != null) {
        Map<String, AppVersion> versions = new HashMap<>();
        SortedMap<Long, AppVersion> timeStamps = new TreeMap<>();
        for (Iterator<AppVersion> i = origCollection.appVersionIterator(); i.hasNext(); ) {
            AppVersion v = i.next();
            versions.put(v.getReleaseName(), v);
            timeStamps.put(v.getTimestamp(), v);
        }
        // add current version to the maps
        AppVersion v = resultCollection.getCurrentAppVersion();
        versions.put(v.getReleaseName(), v);
        timeStamps.put(v.getTimestamp(), v);
        trimToVersion = edu.umd.cs.findbugs.workflow.Filter.FilterCommandLine.getVersionNum(versions, timeStamps, commandLine.trimToVersionAsString, true, v.getSequenceNumber());
        if (trimToVersion < origCollection.getSequenceNumber()) {
            String name = resultCollection.getAppVersionFromSequenceNumber(trimToVersion).getReleaseName();
            long timestamp = resultCollection.getAppVersionFromSequenceNumber(trimToVersion).getTimestamp();
            resultCollection.setReleaseName(name);
            resultCollection.setTimestamp(timestamp);
            resultCollection.trimAppVersions(trimToVersion);
        }
    }
    commandLine.getReady(origCollection);
    for (BugInstance bug : origCollection.getCollection()) {
        if (commandLine.accept(origCollection, bug)) {
            if (trimToVersion >= 0) {
                if (bug.getFirstVersion() > trimToVersion) {
                    dropped++;
                    continue;
                } else if (bug.getLastVersion() >= trimToVersion) {
                    bug.setLastVersion(-1);
                    bug.setRemovedByChangeOfPersistingClass(false);
                }
            }
            resultCollection.add(bug, false);
            passed++;
        } else {
            dropped++;
        }
    }
    if (commandLine.purgeHistorySpecified && commandLine.purgeHistory) {
        resultCollection.clearAppVersions();
        for (BugInstance bug : resultCollection.getCollection()) {
            bug.clearHistory();
        }
    }
    if (verbose) {
        System.out.println(passed + " warnings passed through, " + dropped + " warnings dropped");
    }
    if (commandLine.withSourceSpecified && commandLine.withSource && !commandLine.dontUpdateStats && projectStats.hasClassStats()) {
        for (PackageStats stats : projectStats.getPackageStats()) {
            Iterator<ClassStats> i = stats.getClassStats().iterator();
            while (i.hasNext()) {
                String className = i.next().getName();
                if (sourceSearcher.sourceNotFound.contains(className) || !sourceSearcher.sourceFound.contains(className) && !sourceSearcher.findSource(SourceLineAnnotation.createReallyUnknown(className))) {
                    i.remove();
                }
            }
        }
    }
    projectStats.recomputeFromComponents();
    if (argCount == args.length) {
        assert !verbose;
        resultCollection.writeXML(System.out);
    } else {
        resultCollection.writeXML(args[argCount++]);
    }
}
Also used : ProjectStats(edu.umd.cs.findbugs.ProjectStats) HashMap(java.util.HashMap) SortedBugCollection(edu.umd.cs.findbugs.SortedBugCollection) BugInstance(edu.umd.cs.findbugs.BugInstance) TreeMap(java.util.TreeMap) AppVersion(edu.umd.cs.findbugs.AppVersion) Project(edu.umd.cs.findbugs.Project) PackageStats(edu.umd.cs.findbugs.PackageStats) ClassStats(edu.umd.cs.findbugs.PackageStats.ClassStats)

Example 5 with ProjectStats

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

ProjectStats (edu.umd.cs.findbugs.ProjectStats)7 SortedBugCollection (edu.umd.cs.findbugs.SortedBugCollection)5 BugInstance (edu.umd.cs.findbugs.BugInstance)3 Project (edu.umd.cs.findbugs.Project)3 AppVersion (edu.umd.cs.findbugs.AppVersion)2 Footprint (edu.umd.cs.findbugs.Footprint)2 PackageStats (edu.umd.cs.findbugs.PackageStats)2 ClassStats (edu.umd.cs.findbugs.PackageStats.ClassStats)2 Profiler (edu.umd.cs.findbugs.log.Profiler)2 ConfigurableXmlOutputStream (de.tobject.findbugs.util.ConfigurableXmlOutputStream)1 AnalysisError (edu.umd.cs.findbugs.AnalysisError)1 BugCollection (edu.umd.cs.findbugs.BugCollection)1 Profile (edu.umd.cs.findbugs.log.Profiler.Profile)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1