Date | 2007/07/27 |
---|---|
Codebase | 5530 |
Reviews | 10293 |
DPMO | 927 |
Sigma | 4.612 |
Name | Number | Min | Avg | Max | Total |
---|---|---|---|---|---|
Class complexity | 1 | 48.00 | 48.00 | 48.00 | 48.00 |
Code length | 10 | 1.00 | 35.50 | 273.00 | 355.00 |
File length | 1 | 474.00 | 474.00 | 474.00 | 474.00 |
Operation complexity | 10 | 1.00 | 5.80 | 36.00 | 58.00 |
Work order | 1 | 3.28 | 3.28 | 3.28 | 3.28 |
# | Line | Column | Name | Severity | Description |
---|---|---|---|---|---|
1 | 23 | 1 | ER-023 | 3 | Packages should begin with [] |
2 | 101 | 84 | ER-036 | 3 | Line is too long |
3 | 112 | 94 | ER-036 | 3 | Line is too long |
4 | 122 | 131 | ER-036 | 3 | Line is too long |
5 | 123 | 88 | ER-036 | 3 | Line is too long |
6 | 124 | 83 | ER-036 | 3 | Line is too long |
7 | 126 | 91 | ER-036 | 3 | Line is too long |
8 | 127 | 80 | ER-036 | 3 | Line is too long |
9 | 128 | 90 | ER-036 | 3 | Line is too long |
10 | 134 | 88 | ER-036 | 3 | Line is too long |
11 | 143 | 91 | ER-036 | 3 | Line is too long |
12 | 145 | 91 | ER-036 | 3 | Line is too long |
13 | 146 | 83 | ER-036 | 3 | Line is too long |
14 | 148 | 80 | ER-036 | 3 | Line is too long |
15 | 149 | 117 | ER-036 | 3 | Line is too long |
16 | 150 | 127 | ER-036 | 3 | Line is too long |
17 | 155 | 92 | ER-036 | 3 | Line is too long |
18 | 162 | 86 | ER-036 | 3 | Line is too long |
19 | 165 | 86 | ER-036 | 3 | Line is too long |
20 | 171 | 91 | ER-036 | 3 | Line is too long |
21 | 178 | 91 | ER-036 | 3 | Line is too long |
22 | 183 | 84 | ER-036 | 3 | Line is too long |
23 | 184 | 150 | ER-036 | 3 | Line is too long |
24 | 191 | 90 | ER-036 | 3 | Line is too long |
25 | 195 | 99 | ER-036 | 3 | Line is too long |
26 | 203 | 116 | ER-036 | 3 | Line is too long |
27 | 210 | 114 | ER-036 | 3 | Line is too long |
28 | 221 | 116 | ER-036 | 3 | Line is too long |
29 | 222 | 81 | ER-036 | 3 | Line is too long |
30 | 223 | 80 | ER-036 | 3 | Line is too long |
31 | 227 | 97 | ER-036 | 3 | Line is too long |
32 | 229 | 105 | ER-036 | 3 | Line is too long |
33 | 230 | 98 | ER-036 | 3 | Line is too long |
34 | 231 | 92 | ER-036 | 3 | Line is too long |
35 | 232 | 142 | ER-036 | 3 | Line is too long |
36 | 238 | 102 | ER-036 | 3 | Line is too long |
37 | 243 | 82 | ER-036 | 3 | Line is too long |
38 | 244 | 104 | ER-036 | 3 | Line is too long |
39 | 246 | 157 | ER-036 | 3 | Line is too long |
40 | 248 | 83 | ER-036 | 3 | Line is too long |
41 | 250 | 106 | ER-036 | 3 | Line is too long |
42 | 253 | 82 | ER-036 | 3 | Line is too long |
43 | 258 | 132 | ER-036 | 3 | Line is too long |
44 | 259 | 82 | ER-036 | 3 | Line is too long |
45 | 266 | 80 | ER-036 | 3 | Line is too long |
46 | 272 | 106 | ER-036 | 3 | Line is too long |
47 | 275 | 91 | ER-036 | 3 | Line is too long |
48 | 277 | 134 | ER-036 | 3 | Line is too long |
49 | 289 | 109 | ER-036 | 3 | Line is too long |
50 | 290 | 86 | ER-036 | 3 | Line is too long |
51 | 291 | 99 | ER-036 | 3 | Line is too long |
52 | 292 | 138 | ER-036 | 3 | Line is too long |
53 | 293 | 127 | ER-036 | 3 | Line is too long |
54 | 296 | 91 | ER-036 | 3 | Line is too long |
55 | 298 | 96 | ER-036 | 3 | Line is too long |
56 | 300 | 128 | ER-036 | 3 | Line is too long |
57 | 301 | 105 | ER-036 | 3 | Line is too long |
58 | 302 | 113 | ER-036 | 3 | Line is too long |
59 | 303 | 143 | ER-036 | 3 | Line is too long |
60 | 309 | 84 | ER-036 | 3 | Line is too long |
61 | 311 | 94 | ER-036 | 3 | Line is too long |
62 | 313 | 128 | ER-036 | 3 | Line is too long |
63 | 315 | 121 | ER-036 | 3 | Line is too long |
64 | 316 | 147 | ER-036 | 3 | Line is too long |
65 | 318 | 99 | ER-036 | 3 | Line is too long |
66 | 319 | 123 | ER-036 | 3 | Line is too long |
67 | 325 | 83 | ER-036 | 3 | Line is too long |
68 | 327 | 87 | ER-036 | 3 | Line is too long |
69 | 329 | 128 | ER-036 | 3 | Line is too long |
70 | 331 | 118 | ER-036 | 3 | Line is too long |
71 | 332 | 146 | ER-036 | 3 | Line is too long |
72 | 334 | 99 | ER-036 | 3 | Line is too long |
73 | 335 | 122 | ER-036 | 3 | Line is too long |
74 | 341 | 101 | ER-036 | 3 | Line is too long |
75 | 342 | 136 | ER-036 | 3 | Line is too long |
76 | 357 | 123 | ER-036 | 3 | Line is too long |
77 | 385 | 177 | ER-036 | 3 | Line is too long |
78 | 405 | 178 | ER-036 | 3 | Line is too long |
79 | 407 | 122 | ER-036 | 3 | Line is too long |
80 | 409 | 146 | ER-036 | 3 | Line is too long |
81 | 421 | 81 | ER-036 | 3 | Line is too long |
82 | 461 | 123 | ER-036 | 3 | Line is too long |
83 | 464 | 90 | ER-036 | 3 | Line is too long |
84 | 465 | 87 | ER-036 | 3 | Line is too long |
85 | 467 | 90 | ER-036 | 3 | Line is too long |
86 | 470 | 99 | ER-036 | 3 | Line is too long |
87 | 98 | 1 | ER-049 | 2 | Unify logging strategy - define individual logger for class |
88 | 99 | 9 | ER-011 | 1 | Cyclomatic complexity (36) exceeds 12 |
89 | 99 | 9 | ER-041 | 2 | Method is too long |
90 | 99 | 38 | ER-047 | 2 | Operation (method or constructor) declares subclasses of RuntimeException in throws clause |
91 | 99 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
92 | 101 | 29 | ER-030 | 3 | Avoid hardwired string literals |
93 | 111 | 25 | ER-104 | 2 | Use a Collection instead of arrays Object[] |
94 | 113 | 33 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
95 | 122 | 116 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
96 | 122 | 49 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
97 | 134 | 37 | ER-030 | 3 | Avoid hardwired string literals |
98 | 138 | 29 | ER-030 | 3 | Avoid hardwired string literals |
99 | 149 | 73 | ER-030 | 3 | Avoid hardwired string literals |
100 | 150 | 73 | ER-030 | 3 | Avoid hardwired string literals |
101 | 151 | 73 | ER-030 | 3 | Avoid hardwired string literals |
102 | 155 | 29 | ER-030 | 3 | Avoid hardwired string literals |
103 | 157 | 29 | ER-030 | 3 | Avoid hardwired string literals |
104 | 165 | 29 | ER-030 | 3 | Avoid hardwired string literals |
105 | 167 | 29 | ER-030 | 3 | Avoid hardwired string literals |
106 | 175 | 41 | ER-214 | 1 | java.util.List is different from java.lang.Object |
107 | 176 | 38 | ER-214 | 1 | org.hammurapi.ReviewToLogListener is different from java.lang.Object |
108 | 181 | 29 | ER-030 | 3 | Avoid hardwired string literals |
109 | 184 | 97 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
110 | 184 | 90 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
111 | 184 | 37 | ER-030 | 3 | Avoid hardwired string literals |
112 | 184 | 91 | ER-030 | 3 | Avoid hardwired string literals |
113 | 230 | 55 | ER-102 | 2 | String Arrays are deprecated and are ONLY allowed for final variables |
114 | 230 | 55 | ER-104 | 2 | Use a Collection instead of arrays Object[] |
115 | 256 | 45 | ER-030 | 3 | Avoid hardwired string literals |
116 | 282 | 74 | ER-029 | 3 | Avoid hardwired numeric literals |
117 | 283 | 61 | ER-029 | 3 | Avoid hardwired numeric literals |
118 | 284 | 63 | ER-029 | 3 | Avoid hardwired numeric literals |
119 | 286 | 70 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
120 | 286 | 66 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
121 | 286 | 57 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
122 | 286 | 45 | ER-030 | 3 | Avoid hardwired string literals |
123 | 286 | 58 | ER-030 | 3 | Avoid hardwired string literals |
124 | 286 | 71 | ER-030 | 3 | Avoid hardwired string literals |
125 | 289 | 73 | ER-030 | 3 | Avoid hardwired string literals |
126 | 292 | 106 | ER-048 | 1 | Use BigDecimal instead of Float or Double for monetary values |
127 | 292 | 138 | ER-029 | 3 | Avoid hardwired numeric literals |
128 | 300 | 76 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
129 | 300 | 57 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
130 | 303 | 128 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
131 | 303 | 102 | ER-030 | 3 | Avoid hardwired string literals |
132 | 303 | 129 | ER-030 | 3 | Avoid hardwired string literals |
133 | 311 | 55 | ER-048 | 1 | Use BigDecimal instead of Float or Double for monetary values |
134 | 313 | 76 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
135 | 313 | 57 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
136 | 316 | 142 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
137 | 316 | 110 | ER-030 | 3 | Avoid hardwired string literals |
138 | 316 | 143 | ER-030 | 3 | Avoid hardwired string literals |
139 | 318 | 67 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
140 | 319 | 102 | ER-030 | 3 | Avoid hardwired string literals |
141 | 329 | 76 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
142 | 329 | 57 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
143 | 332 | 141 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
144 | 332 | 110 | ER-030 | 3 | Avoid hardwired string literals |
145 | 332 | 142 | ER-030 | 3 | Avoid hardwired string literals |
146 | 334 | 67 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
147 | 335 | 102 | ER-030 | 3 | Avoid hardwired string literals |
148 | 342 | 91 | ER-030 | 3 | Avoid hardwired string literals |
149 | 357 | 58 | ER-030 | 3 | Avoid hardwired string literals |
150 | 359 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
151 | 361 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
152 | 363 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
153 | 365 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
154 | 367 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
155 | 369 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
156 | 371 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
157 | 385 | 9 | ER-095 | 2 | Too many exceptions listed in throws clause |
158 | 389 | 29 | ER-104 | 2 | Use a Collection instead of arrays Object[] |
159 | 405 | 9 | ER-005 | 3 | Classes, interfaces, methods, and variables should be named according to Sun's naming conventions. |
160 | 405 | 9 | ER-095 | 2 | Too many exceptions listed in throws clause |
161 | 421 | 31 | ER-111 | 1 | LOG4J is mandatory for all logging in ERC. System.out.println will be lost in a system console of our web/app server. |
162 | 421 | 32 | ER-030 | 3 | Avoid hardwired string literals |
163 | 431 | 15 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
164 | 437 | 32 | ER-030 | 3 | Avoid hardwired string literals |
165 | 450 | 34 | ER-030 | 3 | Avoid hardwired string literals |
166 | 455 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
167 | 457 | 37 | ER-029 | 3 | Avoid hardwired numeric literals |
168 | 461 | 88 | ER-047 | 2 | Operation (method or constructor) declares subclasses of RuntimeException in throws clause |
169 | 461 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
170 | 465 | 81 | ER-030 | 3 | Avoid hardwired string literals |
171 | 467 | 50 | ER-030 | 3 | Avoid hardwired string literals |
172 | 470 | 83 | ER-030 | 3 | Avoid hardwired string literals |
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 */
23package org.hammurapi;
24
25import java.io.File;
26import java.io.FileInputStream;
27import java.io.FileNotFoundException;
28import java.io.FileReader;
29import java.io.IOException;
30import java.io.InputStream;
31import java.io.InputStreamReader;
32import java.io.Reader;
33import java.sql.SQLException;
34import java.text.MessageFormat;
35import java.util.ArrayList;
36import java.util.Collection;
37import java.util.Date;
38import java.util.Iterator;
39import java.util.LinkedList;
40import java.util.List;
41
42import org.apache.commons.cli.CommandLine;
43import org.apache.commons.cli.CommandLineParser;
44import org.apache.commons.cli.Options;
45import org.apache.commons.cli.PosixParser;
46import org.apache.tools.ant.AntClassLoader;
47import org.apache.tools.ant.BuildException;
48import org.apache.tools.ant.DirectoryScanner;
49import org.apache.tools.ant.Project;
50import org.hammurapi.results.CompositeResults;
51import org.hammurapi.results.ResultsFactory;
52import org.hammurapi.results.quick.PackageTotal;
53import org.hammurapi.results.simple.QuickResultsFactory;
54
55import com.pavelvlasov.config.Component;
56import com.pavelvlasov.config.ConfigurationException;
57import com.pavelvlasov.jsel.JselException;
58import com.pavelvlasov.jsel.impl.CompilationUnitImpl;
59import com.pavelvlasov.logging.AntLogger;
60import com.pavelvlasov.logging.Logger;
61import com.pavelvlasov.sql.DataAccessObject;
62import com.pavelvlasov.util.ClassResourceLoader;
63import com.pavelvlasov.util.VisitorStack;
64import com.pavelvlasov.util.VisitorStackSource;
65
66/**
67 * Performs automatic code reviews. Quick mode - doesn't store anything to the database,
68 * package and repository level inspectors are not invoked.
69 * <section name="Example" suppress-description="yes">
70If you copy content of Hammurapi lib directory to ant lib directory then you can
71invoke Hammurapi in the following way:
72 <pre>
73<taskdef name="quickurappi" classname="org.hammurapi.QuickHammurapiTask" /><br/>
74<br/>
75<quickurappi><br/>
76 <tab/><src dir="src"/><br/>
77 <tab/><output dir="review"/><br/>
78</quickurappi></pre>
79or, if you didn't copy jar files to Ant lib directory, use this syntax:
80<pre>
81<taskdef name="quickurappi" classname="org.hammurapi.QuickHammurapiTask"><br/>
82 <tab/><classpath><br/>
83 <tab/><tab/><fileset dir="${hammurapi.home}/lib" includes="*.jar"/><br/>
84 <tab/></classpath><br/>
85</taskdef><br/>
86<br/>
87<quickurappi><br/>
88 <tab/><src dir="src"/><br/>
89 <tab/><output dir="review"/><br/>
90</quickurappi>
91</pre>
92
93</section>
94 * @ant.element name="hammurapi" display-name="Automatic code review task"
95 * @author Pavel Vlasov
96 * @version $Revision: 1.10 $
97 */
98public class QuickHammurapiTask extends TaskBase {
99 public void execute() throws BuildException {
100 if (!suppressLogo) {
101 log("Quick Hammurapi 3 Copyright (C) 2004 Hammurapi Group");
102 }
103
104 File archiveTmpDir=processArchive();
105
106 try {
107 long start=System.currentTimeMillis();
108
109 Logger logger=new AntLogger(this);
110
111 final VisitorStack[] visitorStack={null};
112 final VisitorStackSource visitorStackSource=new VisitorStackSource() {
113 public VisitorStack getVisitorStack() {
114 return visitorStack[0];
115 }
116 };
117
118 final SessionImpl session=new SessionImpl();
119
120 InspectorSet inspectorSet=new InspectorSet(
121 new InspectorContextFactory() {
122 public InspectorContext newContext(InspectorDescriptor descriptor, Logger logger) {
123 return new InspectorContextImpl(
124 descriptor,
125 logger,
126 visitorStackSource,
127 session,
128 violationFilters);
129 }
130 },
131 logger);
132
133 if (embeddedInspectors) {
134 log("Loading embedded inspectors", Project.MSG_VERBOSE);
135 loadEmbeddedInspectors(inspectorSet);
136 }
137
138 log("Loading inspectors", Project.MSG_VERBOSE);
139 Iterator it=inspectors.iterator();
140 while (it.hasNext()) {
141 Object o=it.next();
142 if (o instanceof InspectorSource) {
143 ((InspectorSource) o).loadInspectors(inspectorSet);
144 } else {
145 InspectorEntry inspectorEntry = (InspectorEntry) o;
146 inspectorSet.addDescriptor(inspectorEntry);
147 inspectorSet.addInspectorSourceInfo(
148 new InspectorSourceInfo(
149 "Inline inspector "+inspectorEntry.getName(),
150 "Build file: "+inspectorEntry.getLocation().toString(),
151 ""));
152 }
153 }
154
155 log("Inspectors loaded: "+inspectorSet.size(), Project.MSG_VERBOSE);
156
157 log("Loading waivers", Project.MSG_VERBOSE);
158 Date now=new Date();
159 WaiverSet waiverSet=new WaiverSet();
160 it=waivers.iterator();
161 while (it.hasNext()) {
162 ((WaiverSource) it.next()).loadWaivers(waiverSet,now);
163 }
164
165 log("Waivers loaded: "+waiverSet.size(), Project.MSG_VERBOSE);
166
167 log("Loading listeners", Project.MSG_VERBOSE);
168 List listeners=new LinkedList();
169 it=listenerEntries.iterator();
170 while (it.hasNext()) {
171 listeners.add(((ListenerEntry) it.next()).getObject(null));
172 }
173
174 //Outputs
175 listeners.addAll(outputs);
176 listeners.add(new ReviewToLogListener(project));
177
178 Collection inspectors=new LinkedList(inspectorSet.getInspectors());
179 session.setInspectors(inspectorSet);
180 Iterator inspectorsIt=inspectors.iterator();
181 log("Inspectors mapping", Project.MSG_VERBOSE);
182 while (inspectorsIt.hasNext()) {
183 Inspector inspector=(Inspector) inspectorsIt.next();
184 log("\t"+inspector.getContext().getDescriptor().getName()+" -> "+inspector.getClass().getName(), Project.MSG_VERBOSE);
185 }
186
187 ClassLoader classLoader;
188 if (classPath==null) {
189 classLoader=this.getClass().getClassLoader();
190 } else {
191 classLoader=new AntClassLoader(project, classPath, false);
192 session.setClassPath(classPath.list());
193 }
194
195 new QuickResultsFactory(waiverSet, classLoader, tabSize, logger).install();
196
197 Iterator lit=listeners.iterator();
198 while (lit.hasNext()) {
199 ((Listener) lit.next()).onBegin(inspectorSet);
200 }
201
202 try {
203 QuickResultsCollector collector = new QuickResultsCollector(this, title, listeners);
204
205 // Initializing violation filters
206 Iterator vfit=violationFilters.iterator();
207 while (vfit.hasNext()) {
208 Object vf=vfit.next();
209 if (vf instanceof DataAccessObject) {
210 ((DataAccessObject) vf).setSQLProcessor(collector.getProcessor());
211 }
212
213 if (vf instanceof Component) {
214 ((Component) vf).start();
215 }
216 }
217
218 try {
219 inspectors.add(collector);
220
221 QuickReviewEngine engine=new QuickReviewEngine(inspectors, this, collector);
222 visitorStack[0]=engine.getVisitorStack();
223 session.setVisitor(engine.getVisitor());
224
225 it=srcFileSets.iterator();
226 while (it.hasNext()) {
227 HammurapiFileSet fs=(HammurapiFileSet) it.next();
228 fs.setDefaultIncludes();
229 DirectoryScanner scanner=fs.getDirectoryScanner(project);
230 String[] includedFiles=scanner.getIncludedFiles();
231 for (int i=0; i<includedFiles.length; i++) {
232 review(new File(scanner.getBasedir(), includedFiles[i]), engine, classLoader, logger);
233 }
234 }
235
236 it=srcFiles.iterator();
237 while (it.hasNext()) {
238 review((File) it.next(), engine, classLoader, logger);
239 }
240
241 collector.getEngine().deleteOld();
242
243 Collection packageResults=new ArrayList();
244 Iterator pit=collector.getEngine().getPackageTotal().iterator();
245 while (pit.hasNext()) {
246 CompositeResults packageResult = new QuickPackageResults((PackageTotal) pit.next(), collector, inspectorSet);
247 packageResult.commit();
248 Iterator llit=listeners.iterator();
249 while (llit.hasNext()) {
250 ((Listener) llit.next()).onPackage(packageResult);
251 }
252
253 packageResults.add(packageResult);
254 }
255
256 log("Building summary");
257
258 CompositeResults summary = new QuickSummary(title, collector, inspectorSet, packageResults);
259 ResultsFactory.pushThreadResults(summary);
260
261 // Stopping violation filters
262 vfit=violationFilters.iterator();
263 while (vfit.hasNext()) {
264 Object vf=vfit.next();
265 if (vf instanceof Component) {
266 ((Component) vf).stop();
267 }
268 }
269
270 Iterator slit=listeners.iterator();
271 while (slit.hasNext()) {
272 ((Listener) slit.next()).onSummary(summary, inspectorSet);
273 }
274
275 Iterator rit=getReviewAcceptorEntries().iterator();
276 while (rit.hasNext()) {
277 ((ReviewAcceptor) ((ReviewAcceptorEntry) rit.next()).getObject(null)).accept(summary);
278 }
279
280 long finish=System.currentTimeMillis();
281
282 long elapsedSec = (finish-start)/1000;
283 long min=elapsedSec/60;
284 long sec=elapsedSec % 60;
285
286 log("Time: "+min+" min. "+sec+" sec.");
287 log(
288 MessageFormat.format(
289 "Performance {0, number,###.000000}",
290 new Object[] {
291 new Double(
292 (double) summary.getCodeBase() * 1000
293 / (finish - start))}));
294
295
296 Integer severityThreshold = getSeverityThreshold();
297 if (severityThreshold!=null) {
298 final int sth=getSeverityThreshold().intValue();
299 new ReviewAcceptor() {
300 public void accept(CompositeResults summary) throws HammurapiException {
301 Number severity=summary.getMaxSeverity();
302 if (severity!=null && severity.intValue()<=sth) {
303 throw new HammurapiException("Severity threshold ("+sth+") infringed");
304 }
305 }
306 }.accept(summary);
307 }
308
309 Double sigmaThreshold = getSigmaThreshold();
310 if (sigmaThreshold!=null) {
311 final double cth=sigmaThreshold.doubleValue();
312 new ReviewAcceptor() {
313 public void accept(CompositeResults summary) throws HammurapiException {
314 try {
315 if (Double.parseDouble(summary.getSigma())<cth) {
316 throw new HammurapiException("Sigma is below threshold ("+cth+")");
317 }
318 } catch (NumberFormatException e) {
319 throw new HammurapiException("Sigma is not valid");
320 }
321 }
322 }.accept(summary);
323 }
324
325 Integer dpmoThreshold = getDpmoThreshold();
326 if (dpmoThreshold!=null) {
327 final int cth=dpmoThreshold.intValue();
328 new ReviewAcceptor() {
329 public void accept(CompositeResults summary) throws HammurapiException {
330 try {
331 if (Integer.parseInt(summary.getDPMO())>cth) {
332 throw new HammurapiException("DPMO is above threshold ("+cth+")");
333 }
334 } catch (NumberFormatException e) {
335 throw new HammurapiException("DPMO is not valid");
336 }
337 }
338 }.accept(summary);
339 }
340
341 if (isFailOnWarnings() && !summary.getWarnings().isEmpty()) {
342 throw new HammurapiNonConsumableException("There have been warnings during execution.");
343 }
344
345 summary.commit();
346 } finally {
347 session.shutdown();
348 collector.shutdown();
349 }
350 } finally {
351 if (archiveTmpDir!=null) {
352 deleteFile(archiveTmpDir);
353 }
354 }
355
356 if (hadExceptions) {
357 throw new BuildException("There have been exceptions during execution. Check log output.");
358 }
359 } catch (ClassNotFoundException e) {
360 throw new BuildException(e);
361 } catch (SQLException e) {
362 throw new BuildException(e);
363 } catch (JselException e) {
364 throw new BuildException(e);
365 } catch (HammurapiException e) {
366 throw new BuildException(e);
367 } catch (ConfigurationException e) {
368 throw new BuildException(e);
369 } catch (FileNotFoundException e) {
370 throw new BuildException(e);
371 } catch (IOException e) {
372 throw new BuildException(e);
373 }
374 }
375
376 /**
377 * @param file
378 * @param engine
379 * @param classLoader
380 * @param logger
381 * @throws JselException
382 * @throws FileNotFoundException
383 * @throws SQLException
384 */
385 private void review(File file, QuickReviewEngine engine, ClassLoader classLoader, Logger logger) throws JselException, FileNotFoundException, SQLException, IOException {
386 if (file.isFile()) {
387 _review(file, engine, classLoader, logger);
388 } else if (file.isDirectory()) {
389 File[] files=file.listFiles();
390 for (int i=0; i<files.length; i++) {
391 review(files[i], engine, classLoader, logger);
392 }
393 }
394 }
395
396 /**
397 * @param file
398 * @param engine
399 * @param classLoader
400 * @param logger
401 * @throws JselException
402 * @throws FileNotFoundException
403 * @throws SQLException
404 */
405 private void _review(File file, QuickReviewEngine engine, ClassLoader classLoader, Logger logger) throws JselException, FileNotFoundException, SQLException, IOException {
406 InputStream is=new FileInputStream(file);
407 Reader reader= getEncoding()==null ? new InputStreamReader(is) : new InputStreamReader(is, getEncoding());
408 try {
409 engine.review(new CompilationUnitImpl(reader, getEncoding(), null, file.getAbsolutePath(), tabSize, classLoader, logger));
410 } finally {
411 reader.close();
412 is.close();
413 }
414 }
415
416 /**
417 * Use it for inspector debugging
418 * @param args
419 */
420 public static void main(String[] args) {
421 System.out.println("Hammurapi 3 Copyright (C) 2004 Hammurapi Group");
422
423 Options options=new Options();
424
425 populateOptions(options);
426
427 CommandLineParser parser=new PosixParser();
428 CommandLine line=null;
429 try {
430 line=parser.parse(options, args);
431 } catch (org.apache.commons.cli.ParseException e) {
432 System.err.println(e.getMessage());
433 System.err.flush();
434 printHelpAndExit(options);
435 }
436
437 if (line.hasOption("h")) {
438 printHelpAndExit(options);
439 }
440
441 QuickHammurapiTask task=new QuickHammurapiTask();
442 Project project = new Project();
443 task.setProject(project);
444 project.setCoreLoader(task.getClass().getClassLoader());
445
446 task.configure(options, line);
447
448 task.suppressLogo=true;
449
450 task.setTaskName("quickurapi");
451
452 try {
453 task.execute();
454 System.exit(0);
455 } catch (Exception e) {
456 e.printStackTrace();
457 System.exit(2);
458 }
459 }
460
461 protected static void loadEmbeddedInspectors(InspectorSet inspectorSet) throws BuildException, HammurapiException {
462 TaskBase.loadEmbeddedInspectors(inspectorSet);
463
464 ClassResourceLoader crl=new ClassResourceLoader(QuickHammurapiTask.class);
465 InputStream inspectorStream=crl.getResourceAsStream(null, null, "xml");
466 if (inspectorStream==null) {
467 throw new BuildException("Cannot load quick embedded inspectors");
468 }
469
470 DomInspectorSource source=new DomInspectorSource(inspectorStream, "Hammurapi.jar");
471 source.loadInspectors(inspectorSet);
472 }
473}
474
475