Skip to content

Commit

Permalink
CheckstyleBear: Load google and sun rules from jar
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jayvdb committed Nov 21, 2016
1 parent f41b6cf commit f11309a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
17 changes: 14 additions & 3 deletions bears/java/CheckstyleBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
from coalib.settings.Setting import path


known_checkstyles = {
_checkstyle_provided_styles = {
# google: since version 6.9
"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
Expand Down Expand Up @@ -75,10 +82,14 @@ def create_arguments(
check_invalid_configuration(
checkstyle_configs, use_spaces, indent_size)

if checkstyle_configs in known_checkstyles:
if checkstyle_configs in _online_styles:
checkstyle_configs = self.download_cached_file(
known_checkstyles[checkstyle_configs],
_online_styles[checkstyle_configs],
checkstyle_configs + ".xml")
elif 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('/'):]

return ('-jar', self.checkstyle_jar_file, '-c',
checkstyle_configs, filename)
10 changes: 9 additions & 1 deletion tests/java/CheckstyleBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit f11309a

Please sign in to comment.