01: package net.sourceforge.pmd;
02:
03: import java.util.HashMap;
04: import java.util.Map;
05: import java.util.StringTokenizer;
06:
07: public class SimpleRuleSetNameMapper {
08:
09: private StringBuffer rulesets = new StringBuffer();
10: private Map<String, String> nameMap = new HashMap<String, String>();
11:
12: public SimpleRuleSetNameMapper(String ruleString) {
13: populateNameMap();
14: if (ruleString.indexOf(',') == -1) {
15: check(ruleString);
16: return;
17: }
18: for (StringTokenizer st = new StringTokenizer(ruleString, ","); st
19: .hasMoreTokens();) {
20: String tok = st.nextToken();
21: check(tok);
22: }
23: }
24:
25: public String getRuleSets() {
26: return rulesets.toString();
27: }
28:
29: private void check(String name) {
30: if (name.indexOf("rulesets") == -1 && nameMap.containsKey(name)) {
31: append(nameMap.get(name));
32: } else {
33: append(name);
34: }
35: }
36:
37: private void append(String name) {
38: if (rulesets.length() > 0) {
39: rulesets.append(',');
40: }
41: rulesets.append(name);
42: }
43:
44: private void populateNameMap() {
45: nameMap.put("basic", "rulesets/basic.xml");
46: nameMap.put("jsp", "rulesets/basic-jsp.xml");
47: nameMap.put("jsf", "rulesets/basic-jsf.xml");
48: nameMap.put("braces", "rulesets/braces.xml");
49: nameMap.put("clone", "rulesets/clone.xml");
50: nameMap.put("codesize", "rulesets/codesize.xml");
51: nameMap.put("controversial", "rulesets/controversial.xml");
52: nameMap.put("coupling", "rulesets/coupling.xml");
53: nameMap.put("design", "rulesets/design.xml");
54: nameMap.put("finalizers", "rulesets/finalizers.xml");
55: nameMap.put("imports", "rulesets/imports.xml");
56: nameMap.put("j2ee", "rulesets/j2ee.xml");
57: nameMap.put("junit", "rulesets/junit.xml");
58: nameMap.put("javabeans", "rulesets/javabeans.xml");
59: nameMap.put("logging-java", "rulesets/logging-java.xml");
60: nameMap.put("logging-jakarta",
61: "rulesets/logging-jakarta-commons.xml");
62: nameMap.put("logging-jakarta-commons",
63: "rulesets/logging-jakarta-commons.xml");
64: nameMap.put("migrating", "rulesets/migrating.xml");
65: nameMap.put("naming", "rulesets/naming.xml");
66: nameMap.put("optimizations", "rulesets/optimizations.xml");
67: nameMap.put("scratchpad", "rulesets/scratchpad.xml");
68: nameMap.put("strictexception", "rulesets/strictexception.xml");
69: nameMap.put("strings", "rulesets/strings.xml");
70: nameMap.put("sunsecure", "rulesets/sunsecure.xml");
71: nameMap.put("typeresolution", "rulesets/typeresolution.xml");
72: nameMap.put("unusedcode", "rulesets/unusedcode.xml");
73: nameMap.put("33", "rulesets/releases/33.xml");
74: nameMap.put("34", "rulesets/releases/34.xml");
75: nameMap.put("35", "rulesets/releases/35.xml");
76: nameMap.put("36", "rulesets/releases/36.xml");
77: nameMap.put("37", "rulesets/releases/37.xml");
78: nameMap.put("38", "rulesets/releases/38.xml");
79: nameMap.put("39", "rulesets/releases/39.xml");
80: nameMap.put("40rc1", "rulesets/releases/40rc1.xml");
81: }
82: }
|