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