forked from coala/coala-bears
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JavaPMDBear: Detect appropriate linter executable
Describe current executable requirements of pmd or run.sh. Also remove explicit invocation using `bash`, which was ineffective as which('run.sh') would only be successful if the script was executable. Also add `-f text` arguments, which are mandatory on recent versions of pmd, but were optional on older supported versions. Fixes coala#2908
- Loading branch information
Showing
3 changed files
with
20 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
from shutil import which | ||
from dependency_management.requirements.AnyOneOfRequirements import ( | ||
AnyOneOfRequirements) | ||
from dependency_management.requirements.ExecutableRequirement import ( | ||
ExecutableRequirement) | ||
|
||
from coalib.bearlib.abstractions.Linter import linter | ||
from coalib.bearlib import deprecate_settings | ||
from coala_utils.param_conversion import negate | ||
|
||
_executable = which('run.sh') or which('pmd') | ||
|
||
@linter('bash', output_format='regex', | ||
|
||
@linter(_executable or 'pmd', output_format='regex', | ||
output_regex=r'.+:(?P<line>.+):(?P<message>.*)') | ||
class JavaPMDBear: | ||
""" | ||
|
@@ -17,22 +23,19 @@ class JavaPMDBear: | |
""" | ||
|
||
LANGUAGES = {'Java'} | ||
REQUIREMENTS = { | ||
AnyOneOfRequirements( | ||
[ExecutableRequirement('pmd'), | ||
ExecutableRequirement('run.sh'), | ||
] | ||
), | ||
} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Code Simplification', 'Unreachable Code', 'Smell', | ||
'Duplication'} | ||
|
||
@classmethod | ||
def check_prerequisites(cls): | ||
if which('bash') is None: | ||
return 'bash is not installed.' | ||
elif which('pmd') is None and which('run.sh') is None: | ||
return ('PMD is missing. Make sure to install it from ' | ||
'<https://pmd.github.io/>') | ||
else: | ||
return True | ||
|
||
@staticmethod | ||
@deprecate_settings(allow_unnecessary_code=('check_unnecessary', negate), | ||
allow_unused_code=('check_unused', negate)) | ||
|
@@ -94,5 +97,6 @@ def create_arguments(filename, file, config_file, | |
'java-unusedcode': not allow_unused_code} | ||
rules = ','.join(key for key in options if options[key]) | ||
|
||
executable = which('pmd') or which('run.sh') # Mac vs. Unix | ||
return executable, 'pmd', '-R', rules, '-d', filename | ||
executable = tuple(['pmd'] if _executable.endswith('run.sh') else []) | ||
arguments = '-R', rules, '-d', filename, '-f', 'text' | ||
return executable + arguments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters