001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.org
021: * e-Mail: support@hammurapi.biz
022: */
023: package org.hammurapi;
024:
025: import java.sql.Connection;
026: import java.sql.SQLException;
027: import java.sql.Timestamp;
028:
029: import org.hammurapi.results.CompositeResults;
030: import org.hammurapi.results.ReviewResults;
031:
032: import com.pavelvlasov.ant.ConnectionEntry;
033: import com.pavelvlasov.convert.CompositeConverter;
034: import com.pavelvlasov.sql.SQLProcessor;
035:
036: /**
037: * @author Pavel Vlasov
038: *
039: * @version $Revision: 1.3 $
040: */
041: public class HistoryOutput extends ConnectionEntry implements Listener {
042: private String table;
043: private String reportUrl;
044: private String host;
045: private String description;
046:
047: public void onReview(ReviewResults reviewResult) {
048: // Nothing
049: }
050:
051: public void onPackage(CompositeResults packageResults) {
052: // Nothing
053: }
054:
055: public void onSummary(final CompositeResults summary,
056: InspectorSet inspectorSet) throws HammurapiException {
057: try {
058: Connection con = getConnection();
059: try {
060: HistoryImpl history = new HistoryImpl(false);
061:
062: //history.setChangeRatio();
063: history.setCodebase(summary.getCodeBase());
064: history.setCompilationUnits(summary.size()
065: - summary.getChildren().size());
066: history.setDescription(description);
067: // history.setExecutionTime( );
068: history.setHasWarnings(summary.hasWarnings() ? 1 : 0);
069: history.setHost(host);
070: history.setMaxSeverity((Integer) CompositeConverter
071: .getDefaultConverter().convert(
072: summary.getMaxSeverity(),
073: Integer.class, false));
074: history.setName(summary.getName());
075: history.setReportDate(new Timestamp(summary.getDate()
076: .getTime()));
077: history.setReportUrl(reportUrl);
078: history.setReviews(summary.getReviewsNumber());
079: history.setViolationLevel(summary.getViolationLevel());
080: history.setViolations(summary.getViolationsNumber());
081: history.setWaivedViolations(summary
082: .getWaivedViolationsNumber());
083: history.setSigma(summary.getSigma());
084: history.setDpmo(summary.getDPMO());
085:
086: history.insert(new SQLProcessor(con, null), table);
087: } finally {
088: con.close();
089: }
090: } catch (SQLException e) {
091: throw new HammurapiException(e);
092: } catch (ClassNotFoundException e) {
093: throw new HammurapiException(e);
094: }
095: }
096:
097: public void onBegin(InspectorSet inspectorSet) {
098: // Nothing
099: }
100:
101: /**
102: * Table name
103: * @ant.required
104: * @param table
105: */
106: public void setTable(String table) {
107: this .table = table;
108: }
109:
110: /**
111: * Report url
112: * @ant.non-required
113: * @param reportUrl
114: */
115: public void setReportUrl(String reportUrl) {
116: this .reportUrl = reportUrl;
117: }
118:
119: /**
120: * Name of the host to differentiate reports from different hosts.
121: * @ant.non-required
122: * @param host
123: */
124: public void setHost(String host) {
125: this .host = host;
126: }
127:
128: /**
129: * Review description
130: * @ant.non-required
131: * @param description
132: */
133: public void setDescription(String description) {
134: this.description = description;
135: }
136: }
|