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