1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.openjdk.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 AbstractOpenJdkModuleTestSupport extends AbstractItModuleTestSupport {
35
36 private static final String XML_NAME = "/openjdk_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 exc) {
48 throw new IllegalStateException(exc);
49 }
50 try {
51 CHECKSTYLE_MODULES = CheckUtil.getCheckstyleModules();
52 }
53 catch (IOException exc) {
54 throw new IllegalStateException(exc);
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 protected void verifyWithWholeConfig(String filePath) throws Exception {
83 verifyWithItConfig(CONFIGURATION, filePath);
84 }
85
86 }