Date | 2007/07/27 |
---|---|
Codebase | 4901 |
Reviews | 8507 |
DPMO | 881 |
Sigma | 4.627 |
Name | Number | Min | Avg | Max | Total |
---|---|---|---|---|---|
Class complexity | 2 | 24.00 | 40.50 | 57.00 | 81.00 |
Code length | 35 | 0.00 | 8.62 | 79.00 | 302.00 |
File length | 1 | 432.00 | 432.00 | 432.00 | 432.00 |
Operation complexity | 35 | 1.00 | 2.28 | 16.00 | 80.00 |
Work order | 1 | 3.36 | 3.36 | 3.36 | 3.36 |
# | Line | Column | Name | Severity | Description |
---|---|---|---|---|---|
1 | 23 | 1 | ER-023 | 3 | Packages should begin with [] |
2 | 74 | 135 | ER-036 | 3 | Line is too long |
3 | 83 | 82 | ER-036 | 3 | Line is too long |
4 | 84 | 101 | ER-036 | 3 | Line is too long |
5 | 92 | 87 | ER-036 | 3 | Line is too long |
6 | 102 | 101 | ER-036 | 3 | Line is too long |
7 | 107 | 142 | ER-036 | 3 | Line is too long |
8 | 116 | 107 | ER-036 | 3 | Line is too long |
9 | 122 | 137 | ER-036 | 3 | Line is too long |
10 | 132 | 91 | ER-036 | 3 | Line is too long |
11 | 134 | 175 | ER-036 | 3 | Line is too long |
12 | 136 | 99 | ER-036 | 3 | Line is too long |
13 | 143 | 151 | ER-036 | 3 | Line is too long |
14 | 153 | 97 | ER-036 | 3 | Line is too long |
15 | 154 | 104 | ER-036 | 3 | Line is too long |
16 | 157 | 178 | ER-036 | 3 | Line is too long |
17 | 159 | 85 | ER-036 | 3 | Line is too long |
18 | 172 | 95 | ER-036 | 3 | Line is too long |
19 | 196 | 98 | ER-036 | 3 | Line is too long |
20 | 205 | 127 | ER-036 | 3 | Line is too long |
21 | 206 | 126 | ER-036 | 3 | Line is too long |
22 | 212 | 110 | ER-036 | 3 | Line is too long |
23 | 214 | 96 | ER-036 | 3 | Line is too long |
24 | 217 | 107 | ER-036 | 3 | Line is too long |
25 | 225 | 100 | ER-036 | 3 | Line is too long |
26 | 240 | 124 | ER-036 | 3 | Line is too long |
27 | 250 | 160 | ER-036 | 3 | Line is too long |
28 | 252 | 102 | ER-036 | 3 | Line is too long |
29 | 257 | 188 | ER-036 | 3 | Line is too long |
30 | 278 | 98 | ER-036 | 3 | Line is too long |
31 | 287 | 127 | ER-036 | 3 | Line is too long |
32 | 288 | 126 | ER-036 | 3 | Line is too long |
33 | 294 | 88 | ER-036 | 3 | Line is too long |
34 | 295 | 93 | ER-036 | 3 | Line is too long |
35 | 297 | 96 | ER-036 | 3 | Line is too long |
36 | 300 | 107 | ER-036 | 3 | Line is too long |
37 | 313 | 124 | ER-036 | 3 | Line is too long |
38 | 323 | 160 | ER-036 | 3 | Line is too long |
39 | 325 | 102 | ER-036 | 3 | Line is too long |
40 | 330 | 188 | ER-036 | 3 | Line is too long |
41 | 349 | 84 | ER-036 | 3 | Line is too long |
42 | 352 | 178 | ER-036 | 3 | Line is too long |
43 | 383 | 83 | ER-036 | 3 | Line is too long |
44 | 388 | 101 | ER-036 | 3 | Line is too long |
45 | 390 | 142 | ER-036 | 3 | Line is too long |
46 | 393 | 89 | ER-036 | 3 | Line is too long |
47 | 405 | 130 | ER-036 | 3 | Line is too long |
48 | 409 | 85 | ER-036 | 3 | Line is too long |
49 | 62 | 1 | ER-049 | 2 | Unify logging strategy - define individual logger for class |
50 | 70 | 29 | ER-029 | 3 | Avoid hardwired numeric literals |
51 | 72 | 9 | ER-049 | 2 | Unify logging strategy - define individual logger for class |
52 | 74 | 17 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
53 | 88 | 17 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
54 | 92 | 17 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
55 | 92 | 73 | ER-048 | 1 | Use BigDecimal instead of Float or Double for monetary values |
56 | 105 | 48 | ER-030 | 3 | Avoid hardwired string literals |
57 | 107 | 133 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
58 | 107 | 127 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
59 | 107 | 108 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
60 | 107 | 104 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
61 | 107 | 87 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
62 | 107 | 83 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
63 | 107 | 48 | ER-030 | 3 | Avoid hardwired string literals |
64 | 107 | 84 | ER-030 | 3 | Avoid hardwired string literals |
65 | 107 | 105 | ER-030 | 3 | Avoid hardwired string literals |
66 | 107 | 128 | ER-030 | 3 | Avoid hardwired string literals |
67 | 120 | 48 | ER-030 | 3 | Avoid hardwired string literals |
68 | 122 | 133 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
69 | 122 | 127 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
70 | 122 | 108 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
71 | 122 | 104 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
72 | 122 | 87 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
73 | 122 | 83 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
74 | 122 | 48 | ER-030 | 3 | Avoid hardwired string literals |
75 | 122 | 84 | ER-030 | 3 | Avoid hardwired string literals |
76 | 122 | 105 | ER-030 | 3 | Avoid hardwired string literals |
77 | 122 | 128 | ER-030 | 3 | Avoid hardwired string literals |
78 | 131 | 17 | ER-011 | 1 | Cyclomatic complexity (16) exceeds 12 |
79 | 134 | 159 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
80 | 134 | 146 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
81 | 134 | 122 | ER-030 | 3 | Avoid hardwired string literals |
82 | 134 | 160 | ER-030 | 3 | Avoid hardwired string literals |
83 | 143 | 140 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
84 | 143 | 133 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
85 | 143 | 127 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
86 | 143 | 112 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
87 | 143 | 74 | ER-030 | 3 | Avoid hardwired string literals |
88 | 143 | 113 | ER-030 | 3 | Avoid hardwired string literals |
89 | 143 | 134 | ER-030 | 3 | Avoid hardwired string literals |
90 | 149 | 41 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
91 | 153 | 41 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
92 | 167 | 41 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
93 | 171 | 41 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
94 | 175 | 41 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
95 | 179 | 41 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
96 | 188 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
97 | 188 | 9 | ER-109 | 3 | It is good practice to call in any case super() in a constructor. (see also: UnnecessaryConstructorRule ) |
98 | 194 | 17 | ER-104 | 2 | Use a Collection instead of arrays Object[] |
99 | 198 | 25 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
100 | 205 | 106 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
101 | 205 | 33 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
102 | 212 | 93 | ER-030 | 3 | Avoid hardwired string literals |
103 | 214 | 62 | ER-030 | 3 | Avoid hardwired string literals |
104 | 217 | 91 | ER-030 | 3 | Avoid hardwired string literals |
105 | 226 | 35 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
106 | 240 | 36 | ER-030 | 3 | Avoid hardwired string literals |
107 | 240 | 104 | ER-030 | 3 | Avoid hardwired string literals |
108 | 241 | 36 | ER-030 | 3 | Avoid hardwired string literals |
109 | 250 | 100 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
110 | 250 | 49 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
111 | 252 | 86 | ER-030 | 3 | Avoid hardwired string literals |
112 | 257 | 165 | ER-030 | 3 | Avoid hardwired string literals |
113 | 263 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
114 | 270 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
115 | 270 | 9 | ER-109 | 3 | It is good practice to call in any case super() in a constructor. (see also: UnnecessaryConstructorRule ) |
116 | 276 | 17 | ER-104 | 2 | Use a Collection instead of arrays Object[] |
117 | 280 | 25 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
118 | 287 | 106 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
119 | 287 | 33 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
120 | 295 | 87 | ER-030 | 3 | Avoid hardwired string literals |
121 | 297 | 62 | ER-030 | 3 | Avoid hardwired string literals |
122 | 300 | 91 | ER-030 | 3 | Avoid hardwired string literals |
123 | 313 | 36 | ER-030 | 3 | Avoid hardwired string literals |
124 | 313 | 104 | ER-030 | 3 | Avoid hardwired string literals |
125 | 314 | 36 | ER-030 | 3 | Avoid hardwired string literals |
126 | 323 | 100 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
127 | 323 | 49 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
128 | 325 | 86 | ER-030 | 3 | Avoid hardwired string literals |
129 | 330 | 165 | ER-030 | 3 | Avoid hardwired string literals |
130 | 336 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
131 | 349 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
132 | 354 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
133 | 379 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
134 | 382 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
135 | 383 | 54 | ER-030 | 3 | Avoid hardwired string literals |
136 | 387 | 54 | ER-046 | 2 | Method declares too general exception types (Exception, Throwable) in throws clause |
137 | 387 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
138 | 388 | 44 | ER-030 | 3 | Avoid hardwired string literals |
139 | 389 | 35 | 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. |
140 | 390 | 17 | ER-113 | 2 | Unused private/local variables |
141 | 390 | 81 | ER-030 | 3 | Avoid hardwired string literals |
142 | 396 | 25 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
143 | 400 | 25 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
144 | 401 | 40 | ER-030 | 3 | Avoid hardwired string literals |
145 | 404 | 25 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
146 | 405 | 51 | 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. |
147 | 405 | 106 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
148 | 405 | 101 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
149 | 405 | 52 | ER-030 | 3 | Avoid hardwired string literals |
150 | 405 | 102 | ER-030 | 3 | Avoid hardwired string literals |
151 | 408 | 25 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
152 | 409 | 51 | 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. |
153 | 409 | 52 | ER-030 | 3 | Avoid hardwired string literals |
154 | 412 | 25 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
155 | 413 | 49 | ER-030 | 3 | Avoid hardwired string literals |
156 | 428 | 32 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
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.FileReader;
27import java.io.InputStream;
28import java.io.Reader;
29import java.lang.reflect.Method;
30import java.net.URL;
31import java.net.URLClassLoader;
32import java.sql.SQLException;
33import java.util.Collection;
34import java.util.Date;
35import java.util.HashSet;
36import java.util.Iterator;
37import java.util.Set;
38
39import org.hammurapi.results.Annotation;
40
41import com.pavelvlasov.config.ConfigurationException;
42import com.pavelvlasov.jsel.CompilationUnit;
43import com.pavelvlasov.jsel.JselException;
44import com.pavelvlasov.jsel.impl.CompilationUnitImpl;
45import com.pavelvlasov.logging.Logger;
46import com.pavelvlasov.persistence.CompositeStorage;
47import com.pavelvlasov.persistence.FileStorage;
48import com.pavelvlasov.persistence.MemoryStorage;
49import com.pavelvlasov.review.Signed;
50import com.pavelvlasov.review.SourceMarker;
51import com.pavelvlasov.util.ClassResourceLoader;
52import com.pavelvlasov.util.DispatchingVisitor;
53import com.pavelvlasov.util.VisitorExceptionSink;
54import com.pavelvlasov.util.VisitorStack;
55import com.pavelvlasov.util.VisitorStackSource;
56
57/**
58 * This class is to be used by IDE plugins
59 * @author Pavel Vlasov
60 * @version $Revision: 1.8 $
61 */
62public class Reviewer {
63
64 private Logger logger;
65 private InspectorSet inspectorSet;
66 private WaiverSet waiverSet=new WaiverSet();
67 private CompositeStorage storage=new CompositeStorage();
68 private DispatchingVisitor visitor;
69 private SessionImpl session=new SessionImpl();
70 private int tabSize=8;
71
72 private class ReviewerInspectorContext extends InspectorContextBase {
73
74 public ReviewerInspectorContext(InspectorDescriptor descriptor, Logger logger, VisitorStackSource visitorStackSource) {
75 super(descriptor, logger, visitorStackSource, session);
76 }
77
78 /**
79 *
80 * @param source
81 * @param message
82 */
83 public void reportViolation(SourceMarker source, String message) {
84 Violation violation=new SimpleViolation(detach(source), message, descriptor);
85 addViolation(violation);
86 }
87
88 public void annotate(Annotation annotation) {
89 addAnnotation(annotation);
90 }
91
92 public void addMetric(SourceMarker source, String name, double value) {
93 // Ignore
94 }
95
96 /**
97 * Report warning
98 * @param source
99 * @param message
100 */
101 public void warn(SourceMarker source, String message) {
102 Violation violation=new SimpleViolation(detach(source), message, descriptor);
103 addWarning(violation);
104 if (source==null) {
105 System.err.println("WARNING: "+message);
106 } else {
107 System.err.println("WARNING at "+source.getSourceURL()+" "+source.getLine()+":"+source.getColumn()+" : "+message);
108 }
109 }
110
111 /**
112 * Report warning
113 * @param source
114 */
115 public void warn(SourceMarker source, Throwable th) {
116 Violation violation=new SimpleViolation(detach(source), th.toString(), descriptor);
117 addWarning(violation);
118 // TODO better warning handling here
119 if (source==null) {
120 System.err.println("WARNING: "+th);
121 } else {
122 System.err.println("WARNING at "+source.getSourceURL()+" "+source.getLine()+":"+source.getColumn()+" : "+th);
123 }
124 th.printStackTrace();
125 }
126
127 /**
128 * Creates a waiver for inspector with a given key
129 * @param inspectorKey
130 */
131 public void waive(Signed signed, final String inspectorKey) {
132 final String iName=descriptor.getWaivedInspectorName(inspectorKey);
133 if (iName==null) {
134 warn(signed instanceof SourceMarker ? (SourceMarker) signed : null, descriptor.getName()+": Inspector with key '"+inspectorKey+"' not found.");
135 } else {
136 final String signature=signed==null ? null : signed.getSignature();
137 final Set signatures=new HashSet();
138 if (signature!=null) {
139 signatures.add(signature);
140 }
141
142 if (Reviewer.this.logger!=null) {
143 Reviewer.this.logger.debug(this, "Inspector "+getDescriptor().getName()+" autowaives "+iName+" at "+signature);
144 }
145
146 Waiver waiver=new Waiver() {
147 boolean active=true;
148
149 public String getInspectorName() {
150 return iName;
151 }
152
153 public boolean waive(Violation violation, boolean peek) {
154 if (iName.equals(violation.getDescriptor().getName())) {
155 if (signature==null) {
156 return true;
157 } else if (violation.getSource() instanceof Signed && signature.equals(((Signed) violation.getSource()).getSignature())) {
158 if (!peek) {
159 active=false;
160 }
161 return true;
162 }
163 }
164 return false;
165 }
166
167 public Date getExpirationDate() {
168 return null;
169 }
170
171 public String getReason() {
172 return descriptor.getWaiveReason(inspectorKey);
173 }
174
175 public boolean isActive() {
176 return active;
177 }
178
179 public Collection getSignatures() {
180 return signatures;
181 }
182 };
183 waiverSet.addWaiver(waiver, date);
184 }
185 }
186 }
187
188 public Reviewer(
189 final Logger logger,
190 boolean embeddedInspectors,
191 Collection inspectors,
192 Collection waivers) throws HammurapiException {
193 this.logger=logger;
194 final VisitorStack[] visitorStack={null};
195
196 final VisitorStackSource delegatingVisitorStackSource = new VisitorStackSource() {
197
198 public VisitorStack getVisitorStack() {
199 return visitorStack[0];
200 }
201 };
202
203 inspectorSet=new InspectorSet(
204 new InspectorContextFactory() {
205 public InspectorContext newContext(final InspectorDescriptor descriptor, final Logger logger) {
206 return new ReviewerInspectorContext(descriptor, logger, delegatingVisitorStackSource);
207 }
208 },
209 logger);
210
211 if (embeddedInspectors) {
212 InputStream inspectorStream=HammurapiTask.class.getResourceAsStream("inspectors.xml");
213 if (inspectorStream==null) {
214 throw new HammurapiException("Cannot load embedded inspectors");
215 }
216
217 DomInspectorSource source=new DomInspectorSource(inspectorStream, "Hammurapi.jar");
218 source.loadInspectors(inspectorSet);
219 }
220
221 if (inspectors!=null) {
222 Iterator it=inspectors.iterator();
223 while (it.hasNext()) {
224 try {
225 inspectorSet.addDescriptor((InspectorDescriptor) it.next());
226 } catch (ConfigurationException e) {
227 throw new HammurapiException(e);
228 }
229 }
230 }
231
232 if (waivers!=null) {
233 Date now=new Date();
234 Iterator it=waivers.iterator();
235 while (it.hasNext()) {
236 waiverSet.addWaiver((Waiver) it.next(), now);
237 }
238 }
239
240 storage.addStorage("file", new FileStorage(new File(System.getProperties().getProperty("java.io.tmpdir"))));
241 storage.addStorage("memory", new MemoryStorage());
242 session.setStorage(storage);
243
244 try {
245 Collection ic = inspectorSet.getInspectors();
246
247 visitor = new DispatchingVisitor(
248 ic,
249 new VisitorExceptionSink() {
250 public void consume(DispatchingVisitor dispatcher, Object visitor, Method method, Object visitee, Exception e) {
251 if (logger!=null) {
252 logger.warn(visitee, "Exception: "+e);
253 }
254
255 e.printStackTrace();
256
257 getRequest().onWarning(new SimpleViolation(visitee instanceof SourceMarker ? (SourceMarker) visitee : null, "Exception: "+e, null));
258 }
259 },
260 null);
261 session.setInspectors(inspectorSet);
262 visitorStack[0]=visitor.getVisitorStack();
263 } catch (ConfigurationException e) {
264 throw new HammurapiException(e);
265 }
266
267 session.setVisitor(visitor);
268 }
269
270 public Reviewer(
271 final Logger logger,
272 boolean embeddedInspectors,
273 InspectorSource inspectorSource,
274 WaiverSource waiverSource) throws HammurapiException {
275 this.logger=logger;
276 final VisitorStack[] visitorStack={null};
277
278 final VisitorStackSource delegatingVisitorStackSource = new VisitorStackSource() {
279
280 public VisitorStack getVisitorStack() {
281 return visitorStack[0];
282 }
283 };
284
285 inspectorSet=new InspectorSet(
286 new InspectorContextFactory() {
287 public InspectorContext newContext(final InspectorDescriptor descriptor, final Logger logger) {
288 return new ReviewerInspectorContext(descriptor, logger, delegatingVisitorStackSource);
289 }
290 },
291 logger);
292
293 if (embeddedInspectors) {
294 ClassResourceLoader crl=new ClassResourceLoader(TaskBase.class);
295 InputStream inspectorStream=crl.getResourceAsStream(null,null,"xml");
296 if (inspectorStream==null) {
297 throw new HammurapiException("Cannot load embedded inspectors");
298 }
299
300 DomInspectorSource source=new DomInspectorSource(inspectorStream, "Hammurapi.jar");
301 source.loadInspectors(inspectorSet);
302 }
303
304 if (inspectorSource!=null) {
305 inspectorSource.loadInspectors(inspectorSet);
306 }
307
308 if (waiverSource!=null) {
309 Date now=new Date();
310 waiverSource.loadWaivers(waiverSet, now);
311 }
312
313 storage.addStorage("file", new FileStorage(new File(System.getProperties().getProperty("java.io.tmpdir"))));
314 storage.addStorage("memory", new MemoryStorage());
315 session.setStorage(storage);
316
317 try {
318 Collection ic = inspectorSet.getInspectors();
319
320 visitor = new DispatchingVisitor(
321 ic,
322 new VisitorExceptionSink() {
323 public void consume(DispatchingVisitor dispatcher, Object visitor, Method method, Object visitee, Exception e) {
324 if (logger!=null) {
325 logger.warn(visitee, "Exception: "+e);
326 }
327
328 e.printStackTrace();
329
330 getRequest().onWarning(new SimpleViolation(visitee instanceof SourceMarker ? (SourceMarker) visitee : null, "Exception: "+e, null));
331 }
332 },
333 null);
334 session.setInspectors(inspectorSet);
335 visitorStack[0]=visitor.getVisitorStack();
336 } catch (ConfigurationException e) {
337 throw new HammurapiException(e);
338 }
339
340 session.setVisitor(visitor);
341 }
342
343 private ThreadLocal requestTL=new ThreadLocal();
344
345 private ReviewRequest getRequest() {
346 return (ReviewRequest) requestTL.get();
347 }
348
349 public void process(final ReviewRequest request) throws HammurapiException {
350 requestTL.set(request);
351 try {
352 CompilationUnit cu=new CompilationUnitImpl(request.getSource(), null, request.getRootDir(), request.getName(), tabSize, request.getClassLoader(), logger);
353 cu.accept(visitor);
354 } catch (JselException e) {
355 throw new HammurapiException(e);
356 } finally {
357 requestTL.set(null);
358 }
359 }
360
361 private void addViolation(Violation violation) {
362 getRequest().onViolation(violation);
363 }
364
365 /**
366 * @param annotation
367 */
368 private void addAnnotation(Annotation annotation) {
369 // Annotations are ignored
370 }
371
372 /**
373 * @param violation
374 */
375 private void addWarning(Violation violation) {
376 getRequest().onWarning(violation);
377 }
378
379 public void shutdown() throws HammurapiException {
380 try {
381 session.shutdown();
382 } catch (SQLException e) {
383 throw new HammurapiException("Cannot shutdown session", e);
384 }
385 }
386
387 public static void main(String[] arg) throws Exception {
388 final File source=new File("..\\UmlApi\\src\\com\\pavelvlasov\\uml\\Operation.java");
389 System.out.println(source.getAbsolutePath());
390 ClassLoader classLoader=new URLClassLoader(new URL[] { new File("..\\UmlApi\\bin").toURL()}, Reviewer.class.getClassLoader());
391
392 final Reader sr=new FileReader(source);
393 Reviewer reviewer=new Reviewer(null, true, (InspectorSource) null, null);
394 reviewer.process(new ReviewRequestBase(classLoader) {
395
396 public Reader getSource() {
397 return sr;
398 }
399
400 public String getName() {
401 return "com/pavelvlasov/uml/Operation.java";
402 }
403
404 public void onViolation(Violation violation) {
405 System.out.println("VIOLATION: "+violation.getDescriptor().getName()+": "+violation.getMessage());
406 }
407
408 public void onWarning(Violation warning) {
409 System.out.println("WARNING: "+warning.getMessage());
410 }
411
412 public File getRootDir() {
413 return new File("..\\UmlApi\\src");
414 }
415 });
416 }
417
418 /**
419 * @return Returns the tabSize.
420 */
421 public int getTabSize() {
422 return tabSize;
423 }
424
425 /**
426 * @param tabSize The tabSize to set.
427 */
428 public void setTabSize(int tabSize) {
429 this.tabSize = tabSize;
430 }
431}
432
433