01: /*
02: * Hammurapi
03: * Automated Java code review system.
04: * Copyright (C) 2004 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation; either version 2 of the License, or
09: * (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.results.persistent.jdbc;
24:
25: import java.sql.SQLException;
26:
27: import org.hammurapi.HammurapiException;
28: import org.hammurapi.Violation;
29: import org.hammurapi.ViolationFilter;
30: import org.hammurapi.results.persistent.jdbc.sql.BaselineViolationImpl;
31: import org.hammurapi.results.persistent.jdbc.sql.ResultsEngine;
32:
33: import com.pavelvlasov.config.Component;
34: import com.pavelvlasov.config.ConfigurationException;
35: import com.pavelvlasov.review.Signed;
36:
37: /**
38: * @author Pavel Vlasov
39: * @revision $Revision$
40: */
41: public class BaselineSetupViolationFilter implements ViolationFilter,
42: Component {
43:
44: private String reportName;
45: private ResultsEngine resultsEngine;
46:
47: public boolean accept(Violation violation)
48: throws HammurapiException {
49: if (violation.getDescriptor() != null
50: && violation.getSource() instanceof Signed)
51: try {
52: BaselineViolationImpl bv = new BaselineViolationImpl(
53: true);
54: bv.setInspector(violation.getDescriptor().getName());
55: String signature = ((Signed) violation.getSource())
56: .getSignature();
57: if (signature != null) {
58: bv.setSignature(signature);
59: bv.setReportName(reportName);
60: resultsEngine.insertBaselineViolation(bv);
61: return false;
62: }
63: } catch (SQLException e) {
64: throw new HammurapiException(
65: "Cannot store baseline violation", e);
66: }
67: return true;
68: }
69:
70: public void start() throws ConfigurationException {
71: ResultsFactory resultsFactory = ((ResultsFactory) org.hammurapi.results.ResultsFactory
72: .getInstance());
73: try {
74: reportName = resultsFactory.getName();
75: resultsEngine = resultsFactory.getResultsEngine();
76: resultsEngine.deleteBaseline(reportName);
77: } catch (SQLException e) {
78: throw new ConfigurationException(
79: "Cannot delete old baseline", e);
80: }
81: }
82:
83: public void stop() throws ConfigurationException {
84: // Nothing to do.
85: }
86:
87: public void setOwner(Object owner) {
88: // Ignore
89: }
90:
91: }
|