KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nbbuild > misc > bugcompare > Compare


1 package nbbuild.misc.bugcompare;
2
3 /*
4  * The contents of this file are subject to the terms of the Common Development
5  * and Distribution License (the License). You may not use this file except in
6  * compliance with the License.
7  *
8  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
9  * or http://www.netbeans.org/cddl.txt.
10  *
11  * When distributing Covered Code, include this CDDL Header Notice in each file
12  * and include the License file at http://www.netbeans.org/cddl.txt.
13  * If applicable, add the following below the CDDL Header, with the fields
14  * enclosed by brackets [] replaced by your own identifying information:
15  * "Portions Copyrighted [year] [name of copyright owner]"
16  *
17  * The Original Software is NetBeans. The Initial Developer of the Original
18  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
19  * Microsystems, Inc. All Rights Reserved.
20  */

21 import java.util.*;
22 import java.net.*;
23 import java.io.*;
24 import org.xml.sax.*;
25
26 /**
27  *
28  * @author ph97928
29  * @version
30  */

31 public class Compare_1 {
32     Map release32;
33     Map dev;
34
35     public Map fillTable(String JavaDoc name) {
36         Map map = new TreeMap();
37         try {
38             ChangelogRecognizer.parse(new InputSource(name), new ChangelogHandlerImpl(map), new ChangelogParslet());
39         }
40         catch (Exception JavaDoc exc) {
41             exc.printStackTrace();
42         }
43         return map;
44     }
45
46     public List compare(Map source, Map dest) {
47         List result = new ArrayList();
48         Iterator it = source.keySet().iterator();
49         while (it.hasNext()) {
50             Integer JavaDoc key = (Integer JavaDoc) it.next();
51             if (!dest.containsKey(key)) {
52                 result.add(key);
53             }
54         }
55         return result;
56     }
57
58     public void start() {
59         System.out.println("Filling release32");
60         release32 = fillTable("d:\\petr\\bugs\\release32.xml");
61         System.out.println("Filling dev");
62         dev = fillTable("d:\\petr\\bugs\\dev.xml");
63         System.out.println("Comparing");
64         List notInDev = compare(release32, dev);
65         output("d:\\petr\\bugs\\bugs.html", notInDev);
66     }
67     
68     public void output(String JavaDoc name, List list) {
69         try {
70             PrintWriter writer = new PrintWriter(new FileWriter(name));
71             writer.println("<html>");
72             writer.println("<body>");
73             writer.println("Found "+list.size()+" differences");
74
75             writer.println("<table border=\"1\" width=\"100%\">");
76
77             Iterator it = list.iterator();
78             while (it.hasNext()) {
79                 Integer JavaDoc number = (Integer JavaDoc) it.next();
80                 System.out.println("bug:"+number);
81                 writer.println("<tr>");
82                 writer.println("<td width=\"10%\"><a HREF=\"http://www.netbeans.org/issues/show_bug.cgi?id="+number+"\">"+number+"</a></td>");
83                 writer.println("<td width=\"10%\">"+moduleName(number.intValue())+"</td>");
84                 writer.println("<td width=\"80%\">"+release32.get(number)+"</td>");
85                 writer.println("</tr>");
86             }
87             writer.println("</table>");
88             writer.println("</body>");
89             writer.println("</html>");
90             writer.close();
91         }
92         catch (Exception JavaDoc exc) {
93            exc.printStackTrace();
94         }
95     }
96
97     String JavaDoc moduleName(int bugnumber) throws Exception JavaDoc {
98         URLConnection con = new URL("http://www.netbeans.org/issues/show_bug.cgi?id="+bugnumber).openConnection();
99         BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
100         int i = 0;
101         for (;;) {
102             String JavaDoc line = reader.readLine();
103             if (line == null)
104                 break;
105             if (i == 0) {
106                 if (line.indexOf("<TD ALIGN=RIGHT><B>Product:</B></TD>") > 0) {
107                     i = 1;
108                 }
109             }
110             else if (i == 1) {
111                 int index = line.indexOf("<OPTION SELECTED VALUE=\"");
112                 if (index > 0) {
113                     String JavaDoc module = line.substring(index + 24);
114                     module = module.substring(0, module.indexOf('\"'));
115                     reader.close();
116                     return module;
117                 }
118             }
119         }
120         reader.close();
121         return "";
122     }
123     
124     /**
125     * @param args the command line arguments
126     */

127     public static void main (String JavaDoc args[]) throws Exception JavaDoc {
128         new Compare().start();
129     }
130 }
131
Popular Tags