1
2
3
4
5 package com.qulice.checkstyle;
6
7 import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
8 import com.puppycrawl.tools.checkstyle.PropertiesExpander;
9 import com.puppycrawl.tools.checkstyle.api.Configuration;
10 import java.util.Collection;
11 import java.util.HashSet;
12 import java.util.Properties;
13 import org.cactoos.scalar.Sticky;
14 import org.cactoos.scalar.Unchecked;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 final class ConfiguredChecks {
30
31
32
33
34 private final Unchecked<Collection<String>> names = new Unchecked<>(
35 new Sticky<>(ConfiguredChecks::load)
36 );
37
38
39
40
41
42
43
44
45
46
47
48 boolean covers(final String name) {
49 return this.names.value().stream().anyMatch(known -> known.contains(name));
50 }
51
52 private static Collection<String> load() throws Exception {
53 final Properties props = new Properties();
54 props.setProperty("cache.file", "");
55 return ConfiguredChecks.modules(
56 ConfigurationLoader.loadConfiguration(
57 ConfiguredChecks.class.getResource("checks.xml").toString(),
58 new PropertiesExpander(props),
59 ConfigurationLoader.IgnoredModulesOptions.OMIT
60 )
61 );
62 }
63
64 private static Collection<String> modules(final Configuration config) {
65 final Collection<String> found = new HashSet<>(0);
66 final String name = config.getName();
67 final String simple = name.substring(name.lastIndexOf('.') + 1);
68 found.add(simple);
69 if (!simple.endsWith("Check")) {
70 found.add(String.format("%sCheck", simple));
71 }
72 for (final Configuration child : config.getChildren()) {
73 found.addAll(ConfiguredChecks.modules(child));
74 }
75 return found;
76 }
77 }