KickJava   Java API By Example, From Geeks To Geeks.

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


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

19
20 package edu.umd.cs.findbugs.workflow;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import edu.umd.cs.findbugs.BugCollection;
26 import edu.umd.cs.findbugs.BugInstance;
27 import edu.umd.cs.findbugs.DetectorFactoryCollection;
28 import edu.umd.cs.findbugs.Project;
29 import edu.umd.cs.findbugs.ProjectStats;
30 import edu.umd.cs.findbugs.SortedBugCollection;
31
32 /**
33  * Compute the union of two sets of bug results,
34  * preserving annotations.
35  */

36 public class UnionResults {
37
38     static {
39         DetectorFactoryCollection.instance(); // as a side effect, loads detector plugins
40
}
41     static public SortedBugCollection union (SortedBugCollection origCollection, SortedBugCollection newCollection) {
42
43         SortedBugCollection result = origCollection.duplicate();
44         
45         for (Iterator JavaDoc<BugInstance> i = newCollection.iterator(); i.hasNext();) {
46             BugInstance bugInstance = i.next();
47             result.add(bugInstance);
48             }
49         ProjectStats stats = result.getProjectStats();
50         ProjectStats stats2 = newCollection.getProjectStats();
51         stats.addStats(stats2);
52
53         return result;
54     }
55
56     public static void main(String JavaDoc[] argv) throws Exception JavaDoc {
57
58
59         if (argv.length == 0 || "-help".equals(argv[0])) {
60             System.err.println("Usage: " + UnionResults.class.getName() + " <results1> <results2> ... <resultsn>");
61             System.exit(1);
62         }
63
64         SortedBugCollection results = new SortedBugCollection();
65         results.readXML(argv[0], new Project());
66         for(int i = 1; i < argv.length; i++) {
67             SortedBugCollection more = new SortedBugCollection();
68             more.readXML(argv[i], new Project());
69             results = union(results, more);
70         }
71     
72         results.writeXML(System.out, new Project());
73     }
74
75
76 }
77
78 // vim:ts=3
79
Popular Tags