KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > HistoryOutput


1 /*
2   * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.hammurapi.org
21  * e-Mail: support@hammurapi.biz
22   */

23 package org.hammurapi;
24
25 import java.sql.Connection JavaDoc;
26 import java.sql.SQLException JavaDoc;
27 import java.sql.Timestamp JavaDoc;
28
29 import org.hammurapi.results.CompositeResults;
30 import org.hammurapi.results.ReviewResults;
31
32 import com.pavelvlasov.ant.ConnectionEntry;
33 import com.pavelvlasov.convert.CompositeConverter;
34 import com.pavelvlasov.sql.SQLProcessor;
35
36 /**
37  * @author Pavel Vlasov
38  *
39  * @version $Revision: 1.3 $
40  */

41 public class HistoryOutput extends ConnectionEntry implements Listener {
42     private String JavaDoc table;
43     private String JavaDoc reportUrl;
44     private String JavaDoc host;
45     private String JavaDoc description;
46
47     public void onReview(ReviewResults reviewResult) {
48         // Nothing
49
}
50
51     public void onPackage(CompositeResults packageResults) {
52         // Nothing
53
}
54
55     public void onSummary(final CompositeResults summary, InspectorSet inspectorSet) throws HammurapiException {
56         try {
57             Connection JavaDoc con = getConnection();
58             try {
59                 HistoryImpl history=new HistoryImpl(false);
60                 
61                 //history.setChangeRatio();
62
history.setCodebase(summary.getCodeBase());
63                 history.setCompilationUnits(summary.size()-summary.getChildren().size());
64                 history.setDescription(description);
65                 // history.setExecutionTime( );
66
history.setHasWarnings(summary.hasWarnings() ? 1 : 0);
67                 history.setHost(host);
68                 history.setMaxSeverity((Integer JavaDoc) CompositeConverter.getDefaultConverter().convert(summary.getMaxSeverity(), Integer JavaDoc.class, false));
69                 history.setName(summary.getName());
70                 history.setReportDate(new Timestamp JavaDoc(summary.getDate().getTime()));
71                 history.setReportUrl(reportUrl);
72                 history.setReviews(summary.getReviewsNumber());
73                 history.setViolationLevel(summary.getViolationLevel());
74                 history.setViolations(summary.getViolationsNumber());
75                 history.setWaivedViolations(summary.getWaivedViolationsNumber());
76                 history.setSigma(summary.getSigma());
77                 history.setDpmo(summary.getDPMO());
78                 
79                 history.insert(new SQLProcessor(con, null), table);
80             } finally {
81                 con.close();
82             }
83         } catch (SQLException JavaDoc e) {
84             throw new HammurapiException(e);
85         } catch (ClassNotFoundException JavaDoc e) {
86             throw new HammurapiException(e);
87         }
88     }
89
90     public void onBegin(InspectorSet inspectorSet) {
91         // Nothing
92
}
93     
94     /**
95      * Table name
96      * @ant.required
97      * @param table
98      */

99     public void setTable(String JavaDoc table) {
100         this.table = table;
101     }
102     
103     /**
104      * Report url
105      * @ant.non-required
106      * @param reportUrl
107      */

108     public void setReportUrl(String JavaDoc reportUrl) {
109         this.reportUrl = reportUrl;
110     }
111     
112     /**
113      * Name of the host to differentiate reports from different hosts.
114      * @ant.non-required
115      * @param host
116      */

117     public void setHost(String JavaDoc host) {
118         this.host = host;
119     }
120     
121     /**
122      * Review description
123      * @ant.non-required
124      * @param description
125      */

126     public void setDescription(String JavaDoc description) {
127         this.description=description;
128     }
129 }
130
Popular Tags