Skip to content

Commit 302a0da

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

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

bears/java/CheckstyleBear.py

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

44

5-
known_checkstyles = {
5+
# Checkstyle included these two rulesets since version 6.2
6+
_checkstyle_provided_styles = {
67
"google": "https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/google_checks.xml",
78
"sun": 'https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/sun_checks.xml',
9+
}
10+
11+
_online_styles = {
812
"android-check-easy": "https://raw.githubusercontent.com/noveogroup/android-check/master/android-check-plugin/src/main/resources/checkstyle/checkstyle-easy.xml",
913
"android-check-hard": "https://raw.githubusercontent.com/noveogroup/android-check/master/android-check-plugin/src/main/resources/checkstyle/checkstyle-hard.xml",
1014
"geosoft": "http://geosoft.no/development/geosoft_checks.xml"}
1115

16+
# To be deprecated
17+
known_checkstyles = dict(_checkstyle_provided_styles, **_online_styles)
18+
1219

1320
def check_invalid_configuration(checkstyle_configs, use_spaces, indent_size):
1421
if (checkstyle_configs is 'google' and
@@ -75,9 +82,13 @@ def create_arguments(
7582
check_invalid_configuration(
7683
checkstyle_configs, use_spaces, indent_size)
7784

78-
if checkstyle_configs in known_checkstyles:
85+
if checkstyle_configs in _checkstyle_provided_styles:
86+
# Locate the file as an absolute resource in the jar
87+
url = _checkstyle_provided_styles[checkstyle_configs]
88+
checkstyle_configs = url[url.rfind('/'):]
89+
elif checkstyle_configs in _online_styles:
7990
checkstyle_configs = self.download_cached_file(
80-
known_checkstyles[checkstyle_configs],
91+
_online_styles[checkstyle_configs],
8192
checkstyle_configs + ".xml")
8293

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

tests/java/CheckstyleBearTest.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ 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"] = "google"
35+
self.check_validity(self.uut, [], self.good_file)
36+
37+
def test_style_geosoft(self):
38+
self.section["checkstyle_configs"] = "geosoft"
39+
self.check_validity(self.uut, [], self.good_file)
40+
3341
def test_config_failure_use_spaces(self):
3442
self.section["checkstyle_configs"] = "google"
3543
self.section.append(Setting('use_spaces', False))

0 commit comments

Comments
 (0)