Skip to content

Commit 652fdae

Browse files
committed
CheckstyleBear: Load google and sun rules from jar
The google and sun rules are provided in the jar, and those rules are known to be compatible with the jar version. Fixes coala#1017 Fixes coala#1034
1 parent f41b6cf commit 652fdae

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
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_provided_styles = {
6+
# google: since version 6.9
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,10 +82,14 @@ 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 _online_styles:
7986
checkstyle_configs = self.download_cached_file(
80-
known_checkstyles[checkstyle_configs],
87+
_online_styles[checkstyle_configs],
8188
checkstyle_configs + ".xml")
89+
elif checkstyle_configs in _checkstyle_provided_styles:
90+
# Locate the file as an absolute resource in the jar
91+
url = _checkstyle_provided_styles[checkstyle_configs]
92+
checkstyle_configs = url[url.rfind('/'):]
8293

8394
return ('-jar', self.checkstyle_jar_file, '-c',
8495
checkstyle_configs, filename)

0 commit comments

Comments
 (0)