KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > workflow > ListBugDatabaseInfo


1 /*
2  * FindBugs - Find bugs in Java programs
3  * Copyright (C) 2003-2005 William Pugh
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package edu.umd.cs.findbugs.workflow;
19
20 import java.io.IOException JavaDoc;
21 import java.io.PrintWriter JavaDoc;
22 import java.util.Date JavaDoc;
23
24 import org.dom4j.DocumentException;
25
26 import edu.umd.cs.findbugs.AppVersion;
27 import edu.umd.cs.findbugs.BugCollection;
28 import edu.umd.cs.findbugs.Detector;
29 import edu.umd.cs.findbugs.DetectorFactoryCollection;
30 import edu.umd.cs.findbugs.Project;
31 import edu.umd.cs.findbugs.ProjectStats;
32 import edu.umd.cs.findbugs.SortedBugCollection;
33 import edu.umd.cs.findbugs.annotations.CheckForNull;
34 import edu.umd.cs.findbugs.config.CommandLine;
35
36 /**
37  * Java main application to compute update a historical bug collection with
38  * results from another build/analysis.
39  *
40  * @author William Pugh
41  */

42
43 public class ListBugDatabaseInfo {
44
45     private static final String JavaDoc USAGE = "Usage: " + ListBugDatabaseInfo.class.getName()
46             + " [options] data1File data2File data3File ... ";
47
48     static class ListBugDatabaseInfoCommandLine extends CommandLine {
49
50          boolean formatDates = false;
51
52         ListBugDatabaseInfoCommandLine() {
53             addSwitch("-formatDates", "render dates in textual form");
54         }
55
56         @Override JavaDoc
57         public void handleOption(String JavaDoc option, String JavaDoc optionalExtraPart) {
58             if (option.equals("-formatDates"))
59                 formatDates = true;
60             else
61                 throw new IllegalArgumentException JavaDoc("unknown option: " + option);
62         }
63
64         @Override JavaDoc
65         public void handleOptionWithArgument(String JavaDoc option, String JavaDoc argument) {
66
67             throw new IllegalArgumentException JavaDoc("unknown option: " + option);
68         }
69     }
70
71     public static void main(String JavaDoc[] args) throws IOException JavaDoc, DocumentException {
72
73         DetectorFactoryCollection.instance();
74         ListBugDatabaseInfoCommandLine commandLine = new ListBugDatabaseInfoCommandLine();
75         int argCount = commandLine.parse(args, 0, Integer.MAX_VALUE, USAGE);
76
77
78         PrintWriter JavaDoc out = new PrintWriter JavaDoc(System.out);
79         if (argCount == args.length)
80             listVersion(out,null, commandLine.formatDates);
81         else {
82             out.println("version time classes NCSS total high medium low file");
83             while (argCount < args.length) {
84                 String JavaDoc fileName = args[argCount++];
85                 listVersion(out, fileName, commandLine.formatDates);
86                 }
87         }
88         out.close();
89     }
90
91     private static void listVersion(PrintWriter JavaDoc out, @CheckForNull String JavaDoc fileName, boolean formatDates) throws IOException JavaDoc, DocumentException {
92         Project project = new Project();
93         BugCollection origCollection;
94         origCollection = new SortedBugCollection();
95
96         if (fileName == null)
97             origCollection.readXML(System.in, project);
98         else origCollection.readXML(fileName, project);
99         AppVersion appVersion = origCollection.getCurrentAppVersion();
100         ProjectStats stats = origCollection.getProjectStats();
101         out.print(appVersion.getReleaseName());
102         out.print('\t');
103         if (formatDates)
104             out.print("\""+ new Date JavaDoc(appVersion.getTimestamp()) + "\"");
105         else
106             out.print(appVersion.getTimestamp());
107         out.print('\t');
108
109         out.print(appVersion.getNumClasses());
110         out.print('\t');
111         out.print(appVersion.getCodeSize());
112         out.print('\t');
113         out.print(stats.getTotalBugs());
114         out.print('\t');
115         out.print(stats.getBugsOfPriority(Detector.HIGH_PRIORITY));
116         out.print('\t');
117         out.print(stats.getBugsOfPriority(Detector.NORMAL_PRIORITY));
118         out.print('\t');
119         out.print(stats.getBugsOfPriority(Detector.LOW_PRIORITY));
120         if (fileName != null) {
121             out.print('\t');
122             out.print(fileName);
123         }
124
125
126         out.println();
127     }
128
129 }
130
Popular Tags