Date | 2007/07/27 |
---|---|
Codebase | 3525 |
Reviews | 6431 |
DPMO | 677 |
Sigma | 4.704 |
Name | Number | Min | Avg | Max | Total |
---|---|---|---|---|---|
Class complexity | 2 | 0.00 | 25.00 | 50.00 | 50.00 |
Code length | 9 | 1.00 | 18.66 | 63.00 | 168.00 |
File length | 1 | 290.00 | 290.00 | 290.00 | 290.00 |
Operation complexity | 9 | 1.00 | 5.55 | 16.00 | 50.00 |
Work order | 1 | 9.85 | 9.85 | 9.85 | 9.85 |
# | Line | Column | Name | Severity | Description |
---|---|---|---|---|---|
1 | 24 | 1 | ER-023 | 3 | Packages should begin with [] |
2 | 77 | 82 | ER-036 | 3 | Line is too long |
3 | 89 | 84 | ER-036 | 3 | Line is too long |
4 | 101 | 85 | ER-036 | 3 | Line is too long |
5 | 103 | 85 | ER-036 | 3 | Line is too long |
6 | 108 | 86 | ER-036 | 3 | Line is too long |
7 | 113 | 120 | ER-036 | 3 | Line is too long |
8 | 117 | 86 | ER-036 | 3 | Line is too long |
9 | 122 | 93 | ER-036 | 3 | Line is too long |
10 | 127 | 90 | ER-036 | 3 | Line is too long |
11 | 128 | 81 | ER-036 | 3 | Line is too long |
12 | 132 | 100 | ER-036 | 3 | Line is too long |
13 | 134 | 80 | ER-036 | 3 | Line is too long |
14 | 137 | 90 | ER-036 | 3 | Line is too long |
15 | 138 | 81 | ER-036 | 3 | Line is too long |
16 | 142 | 100 | ER-036 | 3 | Line is too long |
17 | 144 | 80 | ER-036 | 3 | Line is too long |
18 | 152 | 97 | ER-036 | 3 | Line is too long |
19 | 154 | 87 | ER-036 | 3 | Line is too long |
20 | 183 | 80 | ER-036 | 3 | Line is too long |
21 | 186 | 107 | ER-036 | 3 | Line is too long |
22 | 189 | 85 | ER-036 | 3 | Line is too long |
23 | 202 | 147 | ER-036 | 3 | Line is too long |
24 | 208 | 122 | ER-036 | 3 | Line is too long |
25 | 211 | 99 | ER-036 | 3 | Line is too long |
26 | 231 | 88 | ER-036 | 3 | Line is too long |
27 | 233 | 99 | ER-036 | 3 | Line is too long |
28 | 234 | 174 | ER-036 | 3 | Line is too long |
29 | 242 | 141 | ER-036 | 3 | Line is too long |
30 | 253 | 130 | ER-036 | 3 | Line is too long |
31 | 257 | 96 | ER-036 | 3 | Line is too long |
32 | 269 | 248 | ER-036 | 3 | Line is too long |
33 | 59 | 1 | ER-049 | 2 | Unify logging strategy - define individual logger for class |
34 | 66 | 9 | ER-049 | 2 | Unify logging strategy - define individual logger for class |
35 | 79 | 40 | ER-028 | 3 | Avoid hardwired character literals |
36 | 83 | 55 | ER-028 | 3 | Avoid hardwired character literals |
37 | 85 | 44 | ER-030 | 3 | Avoid hardwired string literals |
38 | 97 | 9 | ER-011 | 1 | Cyclomatic complexity (13) exceeds 12 |
39 | 101 | 62 | ER-030 | 3 | Avoid hardwired string literals |
40 | 103 | 73 | ER-030 | 3 | Avoid hardwired string literals |
41 | 113 | 60 | ER-030 | 3 | Avoid hardwired string literals |
42 | 117 | 37 | ER-030 | 3 | Avoid hardwired string literals |
43 | 122 | 44 | ER-030 | 3 | Avoid hardwired string literals |
44 | 127 | 44 | ER-030 | 3 | Avoid hardwired string literals |
45 | 133 | 43 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
46 | 137 | 44 | ER-030 | 3 | Avoid hardwired string literals |
47 | 143 | 43 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
48 | 150 | 55 | ER-030 | 3 | Avoid hardwired string literals |
49 | 152 | 73 | ER-030 | 3 | Avoid hardwired string literals |
50 | 157 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
51 | 159 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
52 | 166 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
53 | 172 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
54 | 178 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
55 | 182 | 9 | ER-011 | 1 | Cyclomatic complexity (13) exceeds 12 |
56 | 182 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
57 | 225 | 9 | ER-005 | 3 | Classes, interfaces, methods, and variables should be named according to Sun's naming conventions. |
58 | 225 | 9 | ER-011 | 1 | Cyclomatic complexity (16) exceeds 12 |
59 | 232 | 50 | ER-030 | 3 | Avoid hardwired string literals |
60 | 234 | 68 | ER-025 | 3 | Parenthesis are redundant |
61 | 234 | 89 | ER-030 | 3 | Avoid hardwired string literals |
62 | 234 | 167 | ER-029 | 3 | Avoid hardwired numeric literals |
63 | 256 | 35 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
64 | 269 | 100 | ER-030 | 3 | Avoid hardwired string literals |
65 | 272 | 35 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
66 | 281 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
67 | 285 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
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
24package org.hammurapi;
25
26import java.text.ParseException;
27import java.text.SimpleDateFormat;
28import java.util.Collection;
29import java.util.Date;
30import java.util.HashSet;
31import java.util.Iterator;
32import java.util.LinkedList;
33import java.util.Set;
34
35import javax.xml.transform.TransformerException;
36
37import org.apache.oro.text.GlobCompiler;
38import org.apache.oro.text.regex.MalformedPatternException;
39import org.apache.oro.text.regex.Pattern;
40import org.apache.oro.text.regex.Perl5Matcher;
41import org.apache.xpath.CachedXPathAPI;
42import org.w3c.dom.Element;
43import org.w3c.dom.Node;
44import org.w3c.dom.traversal.NodeIterator;
45
46import com.pavelvlasov.jsel.CompilationUnit;
47import com.pavelvlasov.jsel.JselException;
48import com.pavelvlasov.jsel.LanguageElement;
49import com.pavelvlasov.jsel.Operation;
50import com.pavelvlasov.jsel.Package;
51import com.pavelvlasov.jsel.TypeBody;
52import com.pavelvlasov.review.Signed;
53import com.pavelvlasov.xml.dom.AbstractDomObject;
54
55/**
56 * @author Pavel Vlasov
57 * @version $Revision: 1.10 $
58 */
59public class DomWaiver extends AbstractDomObject implements Waiver {
60 private Set signatures=new HashSet();
61 boolean active=true;
62 boolean hadSignatures=false;
63
64 private LinkedList elements=new LinkedList();
65
66 private static class ElementEntry {
67 boolean exclude;
68 String name;
69 String operationSignature;
70 Pattern fileNamePattern;
71 }
72
73 /**
74 * @param parameter
75 * @param entry
76 */
77 private static void parseParameter(Object parameter, ElementEntry entry) {
78 String value = (String) parameter;
79 int pi = value.indexOf('(');
80 if (pi==-1) {
81 entry.name=value;
82 } else {
83 int lastDot=value.lastIndexOf('.', pi);
84 if (lastDot==-1) {
85 entry.name="*";
86 entry.operationSignature=value;
87 } else {
88 entry.name=value.substring(0, lastDot);
89 entry.operationSignature=value.substring(lastDot+1);
90 }
91 }
92 }
93
94 /**
95 * @param holder
96 */
97 public DomWaiver(Element holder) throws HammurapiException {
98 super();
99 try {
100 CachedXPathAPI cxpa=new CachedXPathAPI();
101 inspectorName=getElementText(holder, "inspector-name", cxpa);
102
103 NodeIterator it=cxpa.selectNodeIterator(holder, "signature");
104 Node signatureNode;
105 while ((signatureNode=it.nextNode())!=null) {
106 if (signatureNode instanceof Element) {
107 hadSignatures=true;
108 signatures.add(getElementText(signatureNode));
109
110 }
111 }
112
113 it=cxpa.selectNodeIterator(holder, "include-element|exclude-element|include-file|exclude-file");
114 Element element;
115 while ((element=(Element) it.nextNode())!=null) {
116 String elementText = getElementText(element);
117 if ("include-element".equals(element.getNodeName())) {
118 ElementEntry entry=new ElementEntry();
119 entry.exclude=false;
120 parseParameter(elementText, entry);
121 elements.addFirst(entry);
122 } else if ("exclude-element".equals(element.getNodeName())) {
123 ElementEntry entry=new ElementEntry();
124 entry.exclude=true;
125 parseParameter(elementText , entry);
126 elements.addFirst(entry);
127 } else if ("include-file".equals(element.getNodeName())) {
128 GlobCompiler compiler=new GlobCompiler();
129 ElementEntry entry=new ElementEntry();
130 entry.exclude=false;
131 try {
132 entry.fileNamePattern=compiler.compile(elementText);
133 } catch (MalformedPatternException e) {
134 throw new HammurapiException(e);
135 }
136 elements.addFirst(entry);
137 } else if ("exclude-file".equals(element.getNodeName())) {
138 GlobCompiler compiler=new GlobCompiler();
139 ElementEntry entry=new ElementEntry();
140 entry.exclude=true;
141 try {
142 entry.fileNamePattern=compiler.compile(elementText);
143 } catch (MalformedPatternException e) {
144 throw new HammurapiException(e);
145 }
146 elements.addFirst(entry);
147 }
148 }
149
150 reason=getElementText(holder, "reason", cxpa);
151
152 String expirationDateVal=getElementText(holder, "expiration-date", cxpa);
153 if (expirationDateVal!=null) {
154 SimpleDateFormat sdf=new SimpleDateFormat(DATE_FORMAT);
155 expirationDate=sdf.parse(expirationDateVal);
156 }
157 } catch (TransformerException e) {
158 throw new HammurapiException(e);
159 } catch (ParseException e) {
160 throw new HammurapiException(e);
161 }
162 }
163
164 private String inspectorName;
165
166 public String getInspectorName() {
167 return inspectorName;
168 }
169
170 private Date expirationDate;
171
172 public Date getExpirationDate() {
173 return expirationDate;
174 }
175
176 private String reason;
177
178 public String getReason() {
179 return reason;
180 }
181
182 public boolean waive(Violation violation, boolean peek) {
183 if (inspectorName.equals(violation.getDescriptor().getName())) {
184 if (hadSignatures) {
185 if (violation.getSource() instanceof Signed) {
186 String signature = ((Signed) violation.getSource()).getSignature();
187 if (signatures.contains(signature)) {
188 if (!peek) {
189 signatures.remove(signature);
190 }
191 active=!signatures.isEmpty();
192 return true;
193 }
194 }
195 }
196
197 if (elements.isEmpty()) {
198 return true;
199 }
200
201 if (violation.getSource() instanceof LanguageElement) {
202 for (LanguageElement element=(LanguageElement) violation.getSource(); element!=null; element=element.getParent()) {
203 if (_waive(element)) {
204 return true;
205 }
206 }
207
208 if (_waive(((LanguageElement) violation.getSource()).getCompilationUnit().getPackage())) {
209 return true;
210 }
211 } else if (violation.getSource() instanceof com.pavelvlasov.jsel.Package) {
212 if (_waive(violation.getSource())) {
213 return true;
214 }
215 }
216 }
217 return false;
218 }
219
220 private Perl5Matcher matcher=new Perl5Matcher();
221
222 /**
223 * @param source
224 */
225 private boolean _waive(Object o) {
226 if (o instanceof Package) {
227 Iterator it=elements.iterator();
228 while (it.hasNext()) {
229 ElementEntry entry=(ElementEntry) it.next();
230 Package pkg = (Package) o;
231 if (entry.name!=null && entry.operationSignature==null &&
232 ("*".equals(entry.name)
233 || pkg.getName().equals(entry.name)
234 || (entry.name.endsWith(".*") && pkg.getName().startsWith(entry.name.substring(0, entry.name.length()-2))))) {
235 return !entry.exclude;
236 }
237 }
238 } else if (o instanceof CompilationUnit) {
239 Iterator it=elements.iterator();
240 while (it.hasNext()) {
241 ElementEntry entry=(ElementEntry) it.next();
242 if (entry.fileNamePattern!=null && matcher.matches(((CompilationUnit) o).getName(), entry.fileNamePattern)) {
243 return !entry.exclude;
244 }
245 }
246 } else if (o instanceof TypeBody) {
247 // only if package included ???
248 Iterator it=elements.iterator();
249 while (it.hasNext()) {
250 ElementEntry entry=(ElementEntry) it.next();
251 try {
252 TypeBody typeBody = (TypeBody) o;
253 if (entry.name!=null && entry.operationSignature==null && typeBody.isKindOf(entry.name)) {
254 return !entry.exclude;
255 }
256 } catch (JselException e) {
257 if (!(e.getCause() instanceof ClassNotFoundException)) {
258 return false;
259 }
260 }
261 }
262 } else if (o instanceof Operation) {
263 // only if type included ???
264 Iterator it=elements.iterator();
265 while (it.hasNext()) {
266 ElementEntry entry=(ElementEntry) it.next();
267 try {
268 Operation operation = (Operation) o;
269 if (entry.name!=null && entry.operationSignature!=null && ("*".equals(entry.name) || operation.getEnclosingType().isKindOf(entry.name)) && operation.getInfo().isArgumentCompatible(entry.operationSignature)) {
270 return !entry.exclude;
271 }
272 } catch (JselException e) {
273 throw new HammurapiRuntimeException(e);
274 }
275 }
276 }
277
278 return false;
279 }
280
281 public boolean isActive() {
282 return active;
283 }
284
285 public Collection getSignatures() {
286 return signatures;
287 }
288
289}
290
291