KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > ReviewToLogListener


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
24 package org.hammurapi;
25
26 import java.text.MessageFormat JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 import org.apache.tools.ant.Project;
30 import org.hammurapi.results.CompositeResults;
31 import org.hammurapi.results.ReviewResults;
32
33 /**
34  *
35  * @author Pavel Vlasov
36  * @version $Revision: 1.1 $
37  */

38 public class ReviewToLogListener implements Listener {
39     private Project project;
40     
41     /** Creates a new instance of ReviewToLogListener */
42     public ReviewToLogListener(Project project) {
43         this.project=project;
44     }
45     
46     public void onReview(ReviewResults reviewResult) throws HammurapiException {
47         if (reviewResult.getViolations().size()!=0) {
48             project.log("Violations in "+reviewResult.getCompilationUnit().getRelativeName()+":", Project.MSG_VERBOSE);
49             Iterator JavaDoc vit=reviewResult.getViolations().iterator();
50             while (vit.hasNext()) {
51                 Violation violation=(Violation) vit.next();
52                 Object JavaDoc[] objs = {
53                     new Integer JavaDoc(violation.getSource().getLine()),
54                     new Integer JavaDoc(violation.getSource().getColumn()),
55                     violation.getDescriptor().getName(),
56                     violation.getDescriptor().getSeverity(),
57                     violation.getMessage()
58                 };
59                 
60                 project.log(MessageFormat.format("{0}:{1} - {2}[{3}] {4}", objs), Project.MSG_VERBOSE);
61             }
62         }
63
64         project.log("Codebase: "+reviewResult.getCodeBase(), Project.MSG_VERBOSE);
65         project.log("Reviews: "+reviewResult.getReviewsNumber(), Project.MSG_VERBOSE);
66         project.log("Violations: "+reviewResult.getViolations().size(), Project.MSG_VERBOSE);
67 // project.log(MessageFormat.format("PAI {0, number,###.00}%", new Object[] { new Double(reviewResult.getPerfectionAffinityIndex()*100) }), Project.MSG_VERBOSE);
68
project.log("DPMO: "+reviewResult.getDPMO(), Project.MSG_VERBOSE);
69         project.log("Sigma: "+reviewResult.getSigma(), Project.MSG_VERBOSE);
70         project.log(" ", Project.MSG_VERBOSE);
71     }
72     
73     public void onSummary(CompositeResults summary, InspectorSet ruleSet) throws HammurapiException {
74         project.log("=== Summary ===");
75         project.log("Codebase: "+summary.getCodeBase());
76         project.log("Reviews: "+summary.getReviewsNumber());
77         project.log("Violations: "+summary.getViolationsNumber());
78 // project.log(MessageFormat.format("PAI {0, number,###.00}%", new Object[] { new Double(summary.getPerfectionAffinityIndex()*100) }));
79
project.log("DPMO: "+summary.getDPMO());
80         project.log("Sigma: "+summary.getSigma());
81     }
82     
83     public void onPackage(CompositeResults packageResults) {
84         project.log("=== Package ===", Project.MSG_VERBOSE);
85         project.log("Package: "+packageResults.getName(), Project.MSG_VERBOSE);
86         project.log("Codebase: "+packageResults.getCodeBase(), Project.MSG_VERBOSE);
87         project.log("Reviews: "+packageResults.getReviewsNumber(), Project.MSG_VERBOSE);
88         project.log("Violations: "+packageResults.getViolationsNumber(), Project.MSG_VERBOSE);
89 // project.log(MessageFormat.format("PAI {0, number,###.00}%", new Object[] { new Double(packageResults.getPerfectionAffinityIndex()*100) }), Project.MSG_VERBOSE);
90
project.log("DPMO: "+packageResults.getDPMO(), Project.MSG_VERBOSE);
91         project.log("Sigma: "+packageResults.getSigma(), Project.MSG_VERBOSE);
92 }
93
94     public void onBegin(InspectorSet inspectorSet) {
95         project.log("Review started with "+inspectorSet.size()+" inspectors");
96     }
97 }
98
Popular Tags