1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.internal.utils;
21
22 import java.util.HashSet;
23 import java.util.Properties;
24 import java.util.Set;
25
26 import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
27 import com.puppycrawl.tools.checkstyle.PropertiesExpander;
28 import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
29 import com.puppycrawl.tools.checkstyle.api.Configuration;
30
31 public final class ConfigurationUtil {
32
33 private ConfigurationUtil() {
34 }
35
36 public static Configuration loadConfiguration(String path) throws CheckstyleException {
37 final Properties props = new Properties();
38
39 props.setProperty("checkstyle.basedir", "basedir");
40 props.setProperty("checkstyle.cache.file", "file");
41 props.setProperty("checkstyle.suppressions.file", "file");
42 props.setProperty("checkstyle.suppressions-xpath.file", "file");
43 props.setProperty("checkstyle.header.file", "file");
44 props.setProperty("checkstyle.regexp.header.file", "file");
45 props.setProperty("checkstyle.importcontrol.file", "file");
46 props.setProperty("checkstyle.importcontroltest.file", "file");
47 props.setProperty("checkstyle.java.version", "value");
48
49 return loadConfiguration(path, props);
50 }
51
52 public static Configuration loadConfiguration(String path, Properties props)
53 throws CheckstyleException {
54 return ConfigurationLoader.loadConfiguration(path, new PropertiesExpander(props));
55 }
56
57 public static Set<Configuration> getModules(Configuration config) {
58 final Set<Configuration> result = new HashSet<>();
59
60 for (Configuration child : config.getChildren()) {
61 if ("TreeWalker".equals(child.getName())) {
62 result.addAll(getModules(child));
63 }
64 else {
65 result.add(child);
66 }
67 }
68
69 return result;
70 }
71
72 public static Set<Configuration> getChecks(Configuration config) {
73 final Set<Configuration> result = new HashSet<>();
74
75 for (Configuration child : config.getChildren()) {
76 if ("TreeWalker".equals(child.getName())) {
77 result.addAll(getModules(child));
78 }
79 }
80
81 return result;
82 }
83
84 }