1 2 19 package edu.umd.cs.findbugs.workflow; 20 21 import edu.umd.cs.findbugs.BugCollection; 22 import edu.umd.cs.findbugs.PackageStats; 23 import edu.umd.cs.findbugs.Project; 24 import edu.umd.cs.findbugs.ProjectStats; 25 import edu.umd.cs.findbugs.SortedBugCollection; 26 import edu.umd.cs.findbugs.PackageStats.ClassStats; 27 28 34 public class DefectDensity { 35 private static void printRow(Object ... values) { 36 for (Object s : values) { 37 System.out.print(s); 38 System.out.print("\t"); 39 } 40 System.out.println(); 41 42 } 43 44 public static double density(int bugs, int ncss) { 45 if (ncss == 0) return Double.NaN; 46 int bugsPer10KNCSS = 10000*bugs/ncss; 47 return bugsPer10KNCSS/10.0; 48 } 49 public static void main(String args[]) throws Exception { 50 51 if (args.length>1 || (args.length>0 && "-help".equals(args[0]))) { 52 System.err.println("Usage: " + DefectDensity.class.getName() + " [<infile>]"); 53 System.exit(1); 54 } 55 56 Project project = new Project(); 57 BugCollection origCollection = new SortedBugCollection(); 58 int argCount = 0; 59 if (argCount == args.length) 60 origCollection.readXML(System.in, project); 61 else 62 origCollection.readXML(args[argCount], project); 63 ProjectStats stats = origCollection.getProjectStats(); 64 printRow("kind", "name", "density/KNCSS", "bugs", "NCSS"); 65 double projectDensity = density(stats.getTotalBugs(), stats.getCodeSize()); 66 printRow("project", origCollection.getCurrentAppVersion().getReleaseName(), 67 projectDensity, stats.getTotalBugs(), 68 stats.getCodeSize()); 69 for (PackageStats p : stats.getPackageStats()) if (p.getTotalBugs() > 4) { 70 71 72 double packageDensity = density( p.getTotalBugs(),p.size()); 73 if (Double.isNaN(packageDensity) || packageDensity < projectDensity) continue; 74 printRow("package", p.getPackageName(), 75 packageDensity, p.getTotalBugs(), p.size()); 76 for (ClassStats c : p.getClassStats()) if (c.getTotalBugs() > 4) { 77 double density = density( c.getTotalBugs(), c.size()); 78 if (Double.isNaN(density) || density < packageDensity) continue; 79 printRow("class", c.getName(), 80 density, c.getTotalBugs(), c.size()); 81 } 82 } 83 84 } 85 86 87 } 88 | Popular Tags |