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:
024: package org.hammurapi;
025:
026: import java.text.MessageFormat;
027: import java.util.Iterator;
028:
029: import org.apache.tools.ant.Project;
030: import org.hammurapi.results.CompositeResults;
031: import org.hammurapi.results.ReviewResults;
032:
033: /**
034: *
035: * @author Pavel Vlasov
036: * @version $Revision: 1.1 $
037: */
038: public class ReviewToLogListener implements Listener {
039: private Project project;
040:
041: /** Creates a new instance of ReviewToLogListener */
042: public ReviewToLogListener(Project project) {
043: this .project = project;
044: }
045:
046: public void onReview(ReviewResults reviewResult)
047: throws HammurapiException {
048: if (reviewResult.getViolations().size() != 0) {
049: project.log("Violations in "
050: + reviewResult.getCompilationUnit()
051: .getRelativeName() + ":",
052: Project.MSG_VERBOSE);
053: Iterator vit = reviewResult.getViolations().iterator();
054: while (vit.hasNext()) {
055: Violation violation = (Violation) vit.next();
056: Object[] objs = {
057: new Integer(violation.getSource().getLine()),
058: new Integer(violation.getSource().getColumn()),
059: violation.getDescriptor().getName(),
060: violation.getDescriptor().getSeverity(),
061: violation.getMessage() };
062:
063: project.log(MessageFormat.format(
064: "{0}:{1} - {2}[{3}] {4}", objs),
065: Project.MSG_VERBOSE);
066: }
067: }
068:
069: project.log("Codebase: " + reviewResult.getCodeBase(),
070: Project.MSG_VERBOSE);
071: project.log("Reviews: " + reviewResult.getReviewsNumber(),
072: Project.MSG_VERBOSE);
073: project.log("Violations: "
074: + reviewResult.getViolations().size(),
075: Project.MSG_VERBOSE);
076: // project.log(MessageFormat.format("PAI {0, number,###.00}%", new Object[] { new Double(reviewResult.getPerfectionAffinityIndex()*100) }), Project.MSG_VERBOSE);
077: project.log("DPMO: " + reviewResult.getDPMO(),
078: Project.MSG_VERBOSE);
079: project.log("Sigma: " + reviewResult.getSigma(),
080: Project.MSG_VERBOSE);
081: project.log(" ", Project.MSG_VERBOSE);
082: }
083:
084: public void onSummary(CompositeResults summary, InspectorSet ruleSet)
085: throws HammurapiException {
086: project.log("=== Summary ===");
087: project.log("Codebase: " + summary.getCodeBase());
088: project.log("Reviews: " + summary.getReviewsNumber());
089: project.log("Violations: " + summary.getViolationsNumber());
090: // project.log(MessageFormat.format("PAI {0, number,###.00}%", new Object[] { new Double(summary.getPerfectionAffinityIndex()*100) }));
091: project.log("DPMO: " + summary.getDPMO());
092: project.log("Sigma: " + summary.getSigma());
093: }
094:
095: public void onPackage(CompositeResults packageResults) {
096: project.log("=== Package ===", Project.MSG_VERBOSE);
097: project.log("Package: " + packageResults.getName(),
098: Project.MSG_VERBOSE);
099: project.log("Codebase: " + packageResults.getCodeBase(),
100: Project.MSG_VERBOSE);
101: project.log("Reviews: " + packageResults.getReviewsNumber(),
102: Project.MSG_VERBOSE);
103: project.log("Violations: "
104: + packageResults.getViolationsNumber(),
105: Project.MSG_VERBOSE);
106: // project.log(MessageFormat.format("PAI {0, number,###.00}%", new Object[] { new Double(packageResults.getPerfectionAffinityIndex()*100) }), Project.MSG_VERBOSE);
107: project.log("DPMO: " + packageResults.getDPMO(),
108: Project.MSG_VERBOSE);
109: project.log("Sigma: " + packageResults.getSigma(),
110: Project.MSG_VERBOSE);
111: }
112:
113: public void onBegin(InspectorSet inspectorSet) {
114: project.log("Review started with " + inspectorSet.size()
115: + " inspectors");
116: }
117: }
|