1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.sun.checkstyle.test.base;
21
22 import java.io.IOException;
23 import java.util.Set;
24
25 import org.checkstyle.base.AbstractItModuleTestSupport;
26
27 import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
28 import com.puppycrawl.tools.checkstyle.PropertiesExpander;
29 import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
30 import com.puppycrawl.tools.checkstyle.api.Configuration;
31 import com.puppycrawl.tools.checkstyle.internal.utils.CheckUtil;
32 import com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil;
33
34 public abstract class AbstractSunModuleTestSupport extends AbstractItModuleTestSupport {
35
36 private static final String XML_NAME = "/sun_checks.xml";
37
38 private static final Configuration CONFIGURATION;
39
40 private static final Set<Class<?>> CHECKSTYLE_MODULES;
41
42 static {
43 try {
44 CONFIGURATION = ConfigurationLoader.loadConfiguration(XML_NAME,
45 new PropertiesExpander(System.getProperties()));
46 }
47 catch (CheckstyleException ex) {
48 throw new IllegalStateException(ex);
49 }
50 try {
51 CHECKSTYLE_MODULES = CheckUtil.getCheckstyleModules();
52 }
53 catch (IOException ex) {
54 throw new IllegalStateException(ex);
55 }
56 }
57
58 @Override
59 protected ModuleCreationOption findModuleCreationOption(String moduleName) {
60 ModuleCreationOption moduleCreationOption = ModuleCreationOption.IN_CHECKER;
61
62 for (Class<?> moduleClass : CHECKSTYLE_MODULES) {
63 if (moduleClass.getSimpleName().equals(moduleName)
64 || moduleClass.getSimpleName().equals(moduleName + "Check")) {
65 if (ModuleReflectionUtil.isCheckstyleTreeWalkerCheck(moduleClass)
66 || ModuleReflectionUtil.isTreeWalkerFilterModule(moduleClass)) {
67 moduleCreationOption = ModuleCreationOption.IN_TREEWALKER;
68 }
69 break;
70 }
71 }
72
73 return moduleCreationOption;
74 }
75
76
77
78
79
80
81
82
83 protected static Configuration getModuleConfig(String moduleName) {
84 return getModuleConfig(moduleName, null);
85 }
86
87
88
89
90
91
92
93
94
95
96 protected static Configuration getModuleConfig(String moduleName, String moduleId) {
97 return getModuleConfig(CONFIGURATION, moduleName, moduleId);
98 }
99
100 }