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.
CPDBear: Detect appropriate linter executable
Describe current executable requirements of cpd or run.sh, replacing check_prerequisites with Requirement classes. Also remove explicit invocation using `bash`, which was ineffective as which('run.sh') would only be successful if the script was executable, and the run.sh script is not written to be compatible with invocation on Windows. This de-supports any usage where `pmd` existed and was a script which could invoke `cpd`. It fixes usage where `pmd` is not a script, like it is an executable shim when installed with choco. Also remove duplication of `CPDBear` in generate_bear_metadata.py which was intended to make 'cpd' deselectable, but was broken. It is now mostly unnecessary as the ExecutableRequirement classes provide the `cpd` tag, however the `java` tag is still manual. Reduce the required coverage percentage to 98%. Fixes coala#2937 Related to coala#2908
- Loading branch information
Showing
5 changed files
with
27 additions
and
31 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
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,6 +1,11 @@ | ||
from shutil import which | ||
from xml.etree import ElementTree | ||
|
||
from dependency_management.requirements.AnyOneOfRequirements import ( | ||
AnyOneOfRequirements) | ||
from dependency_management.requirements.ExecutableRequirement import ( | ||
ExecutableRequirement) | ||
|
||
from coalib.bears.GlobalBear import GlobalBear | ||
from coalib.misc.Shell import run_shell_command | ||
from coalib.results.Result import Result | ||
|
@@ -30,21 +35,18 @@ class CPDBear(GlobalBear): | |
'Swift': 'swift'} | ||
|
||
LANGUAGES = set(language_dict.keys()) | ||
REQUIREMENTS = { | ||
AnyOneOfRequirements( | ||
[ExecutableRequirement('cpd'), | ||
ExecutableRequirement('run.sh'), | ||
] | ||
), | ||
} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Duplication'} | ||
|
||
@classmethod | ||
def check_prerequisites(cls): | ||
if which('bash') is None: | ||
return 'bash is not installed.' | ||
if 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 | ||
|
||
def run(self, language: language, | ||
minimum_tokens: int = 20, | ||
ignore_annotations: bool = False, | ||
|
@@ -93,8 +95,11 @@ def run(self, language: language, | |
'--skip-duplicate-files': skip_duplicate_files} | ||
|
||
files = ','.join(self.file_dict.keys()) | ||
executable = which('pmd') or which('run.sh') | ||
arguments = ('bash', executable, 'cpd', '--skip-lexical-errors', | ||
executable = which('cpd') or which('run.sh') | ||
executable = tuple([executable] if not executable.endswith('run.sh') | ||
else [executable, 'cpd']) | ||
|
||
arguments = ('--skip-lexical-errors', | ||
'--minimum-tokens', str(minimum_tokens), | ||
'--language', cpd_language, | ||
'--files', files, | ||
|
@@ -104,6 +109,7 @@ def run(self, language: language, | |
for option, enable in options.items() | ||
if enable is True) | ||
|
||
arguments = executable + arguments | ||
stdout_output, _ = run_shell_command(arguments) | ||
|
||
if stdout_output: | ||
|
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