From 302a0da21d6cd13dca9691673baa4a515dde7c47 Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Tue, 22 Nov 2016 00:32:52 +0700 Subject: [PATCH] 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 https://github.com/coala/coala-bears/issues/1017 Fixes https://github.com/coala/coala-bears/issues/1034 --- bears/java/CheckstyleBear.py | 17 ++++++++++++++--- tests/java/CheckstyleBearTest.py | 10 +++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bears/java/CheckstyleBear.py b/bears/java/CheckstyleBear.py index 0c42a7170d..cbe525bfec 100644 --- a/bears/java/CheckstyleBear.py +++ b/bears/java/CheckstyleBear.py @@ -2,13 +2,20 @@ from coalib.settings.Setting import path -known_checkstyles = { +# Checkstyle included these two rulesets since version 6.2 +_checkstyle_provided_styles = { "google": "https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/google_checks.xml", "sun": 'https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/sun_checks.xml', +} + +_online_styles = { "android-check-easy": "https://raw.githubusercontent.com/noveogroup/android-check/master/android-check-plugin/src/main/resources/checkstyle/checkstyle-easy.xml", "android-check-hard": "https://raw.githubusercontent.com/noveogroup/android-check/master/android-check-plugin/src/main/resources/checkstyle/checkstyle-hard.xml", "geosoft": "http://geosoft.no/development/geosoft_checks.xml"} +# To be deprecated +known_checkstyles = dict(_checkstyle_provided_styles, **_online_styles) + def check_invalid_configuration(checkstyle_configs, use_spaces, indent_size): if (checkstyle_configs is 'google' and @@ -75,9 +82,13 @@ def create_arguments( check_invalid_configuration( checkstyle_configs, use_spaces, indent_size) - if checkstyle_configs in known_checkstyles: + if checkstyle_configs in _checkstyle_provided_styles: + # Locate the file as an absolute resource in the jar + url = _checkstyle_provided_styles[checkstyle_configs] + checkstyle_configs = url[url.rfind('/'):] + elif checkstyle_configs in _online_styles: checkstyle_configs = self.download_cached_file( - known_checkstyles[checkstyle_configs], + _online_styles[checkstyle_configs], checkstyle_configs + ".xml") return ('-jar', self.checkstyle_jar_file, '-c', diff --git a/tests/java/CheckstyleBearTest.py b/tests/java/CheckstyleBearTest.py index feb10258a0..cc7cde7e08 100644 --- a/tests/java/CheckstyleBearTest.py +++ b/tests/java/CheckstyleBearTest.py @@ -26,10 +26,18 @@ def test_run(self): self.check_validity(self.uut, [], self.good_file) self.check_validity(self.uut, [], self.bad_file, valid=False) - def test_known_configs(self): + def test_style_google(self): self.section["checkstyle_configs"] = "google" self.check_validity(self.uut, [], self.good_file) + def test_style_sun(self): + self.section["checkstyle_configs"] = "google" + self.check_validity(self.uut, [], self.good_file) + + def test_style_geosoft(self): + self.section["checkstyle_configs"] = "geosoft" + self.check_validity(self.uut, [], self.good_file) + def test_config_failure_use_spaces(self): self.section["checkstyle_configs"] = "google" self.section.append(Setting('use_spaces', False))