Skip to content

Commit 9b86d14

Browse files
committed
CheckstyleBear: Load google and sun rules from jar
The google and sun ruleset have been provided in the checkstyle jar since version 6.2. Load the rulesets from the linter jar so the rules are known to be compatible with the linter version. Fixes #1017 Fixes #1034
1 parent f41b6cf commit 9b86d14

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

bears/java/CheckstyleBear.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
from coalib.settings.Setting import path
33

44

5-
known_checkstyles = {
6-
"google": "https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/google_checks.xml",
7-
"sun": 'https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/sun_checks.xml',
5+
_online_styles = {
86
"android-check-easy": "https://raw.githubusercontent.com/noveogroup/android-check/master/android-check-plugin/src/main/resources/checkstyle/checkstyle-easy.xml",
97
"android-check-hard": "https://raw.githubusercontent.com/noveogroup/android-check/master/android-check-plugin/src/main/resources/checkstyle/checkstyle-hard.xml",
108
"geosoft": "http://geosoft.no/development/geosoft_checks.xml"}
119

10+
# To be deprecated
11+
known_checkstyles = dict(_online_styles, **{'google': None, 'sun': None})
12+
1213

1314
def check_invalid_configuration(checkstyle_configs, use_spaces, indent_size):
1415
if (checkstyle_configs is 'google' and
@@ -75,9 +76,13 @@ def create_arguments(
7576
check_invalid_configuration(
7677
checkstyle_configs, use_spaces, indent_size)
7778

78-
if checkstyle_configs in known_checkstyles:
79+
if checkstyle_configs in ('google', 'sun'):
80+
# Checkstyle included these two rulesets since version 6.2
81+
# Locate the file as an absolute resource into the checkstyle jar
82+
checkstyle_configs = '/%s_checks.xml' % checkstyle_configs
83+
elif checkstyle_configs in _online_styles:
7984
checkstyle_configs = self.download_cached_file(
80-
known_checkstyles[checkstyle_configs],
85+
_online_styles[checkstyle_configs],
8186
checkstyle_configs + ".xml")
8287

8388
return ('-jar', self.checkstyle_jar_file, '-c',

tests/java/CheckstyleBearTest.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,25 @@ def test_run(self):
2626
self.check_validity(self.uut, [], self.good_file)
2727
self.check_validity(self.uut, [], self.bad_file, valid=False)
2828

29-
def test_known_configs(self):
29+
def test_style_google(self):
3030
self.section["checkstyle_configs"] = "google"
3131
self.check_validity(self.uut, [], self.good_file)
3232

33+
def test_style_sun(self):
34+
self.section["checkstyle_configs"] = "sun"
35+
self.check_validity(self.uut, [], self.good_file)
36+
37+
def test_style_android(self):
38+
self.section["checkstyle_configs"] = "android-check-easy"
39+
self.check_validity(self.uut, [], self.good_file)
40+
41+
self.section["checkstyle_configs"] = "android-check-hard"
42+
self.check_validity(self.uut, [], self.good_file)
43+
44+
def test_style_geosoft(self):
45+
self.section["checkstyle_configs"] = "geosoft"
46+
self.check_validity(self.uut, [], self.good_file)
47+
3348
def test_config_failure_use_spaces(self):
3449
self.section["checkstyle_configs"] = "google"
3550
self.section.append(Setting('use_spaces', False))

0 commit comments

Comments
 (0)