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 652fdae
Showing 1 changed file with 14 additions and 3 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)

0 comments on commit 652fdae

Please sign in to comment.