mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-10 00:42:40 +01:00
Modernize ArcanistScalaSBTLinter
.
Summary: Ref T2039. Convert the `ArcanistScalaSBTLinter` into an `ArcanistExternalLinter` and make it compatible with `.arclint`. Test Plan: I can't really test this because I don't have any Scala projects and we don't have any test cases. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: codeblock, epriestley, Korvin Maniphest Tasks: T2039 Differential Revision: https://secure.phabricator.com/D9097
This commit is contained in:
parent
178b32c6c2
commit
6c1bae437e
2 changed files with 74 additions and 42 deletions
|
@ -311,7 +311,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistRevertWorkflow' => 'ArcanistBaseWorkflow',
|
'ArcanistRevertWorkflow' => 'ArcanistBaseWorkflow',
|
||||||
'ArcanistRubyLinter' => 'ArcanistExternalLinter',
|
'ArcanistRubyLinter' => 'ArcanistExternalLinter',
|
||||||
'ArcanistRubyLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
'ArcanistRubyLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
||||||
'ArcanistScalaSBTLinter' => 'ArcanistLinter',
|
'ArcanistScalaSBTLinter' => 'ArcanistExternalLinter',
|
||||||
'ArcanistScriptAndRegexLinter' => 'ArcanistLinter',
|
'ArcanistScriptAndRegexLinter' => 'ArcanistLinter',
|
||||||
'ArcanistSetConfigWorkflow' => 'ArcanistBaseWorkflow',
|
'ArcanistSetConfigWorkflow' => 'ArcanistBaseWorkflow',
|
||||||
'ArcanistShellCompleteWorkflow' => 'ArcanistBaseWorkflow',
|
'ArcanistShellCompleteWorkflow' => 'ArcanistBaseWorkflow',
|
||||||
|
|
|
@ -3,60 +3,78 @@
|
||||||
/**
|
/**
|
||||||
* Uses `sbt compile` to detect various warnings/errors in Scala code.
|
* Uses `sbt compile` to detect various warnings/errors in Scala code.
|
||||||
*/
|
*/
|
||||||
final class ArcanistScalaSBTLinter extends ArcanistLinter {
|
final class ArcanistScalaSBTLinter extends ArcanistExternalLinter {
|
||||||
|
|
||||||
|
public function getInfoName() {
|
||||||
|
return 'sbt';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInfoURI() {
|
||||||
|
return 'http://www.scala-sbt.org';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInfoDescription() {
|
||||||
|
return pht('sbt is a build tool for Scala, Java, and more.');
|
||||||
|
}
|
||||||
|
|
||||||
public function getLinterName() {
|
public function getLinterName() {
|
||||||
return 'ScalaSBT';
|
return 'ScalaSBT';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canRun() {
|
public function getLinterConfigurationName() {
|
||||||
// Check if this looks like a SBT project. If it doesn't, throw, because
|
return 'scala-sbt';
|
||||||
// we rely fairly heavily on `sbt compile` working, below. We don't want
|
}
|
||||||
// to call out to scalac ourselves, because then we'll end up in Class Path
|
|
||||||
// Hell. We let the build system handle this for us.
|
public function getDefaultBinary() {
|
||||||
if (!Filesystem::pathExists('project/Build.scala') &&
|
$prefix = $this->getDeprecatedConfiguration('lint.scala_sbt.prefix');
|
||||||
!Filesystem::pathExists('build.sbt')) {
|
$bin = 'sbt';
|
||||||
|
|
||||||
|
if ($prefix) {
|
||||||
|
return $prefix.'/'.$bin;
|
||||||
|
} else {
|
||||||
|
return $bin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getVersion() {
|
||||||
|
// NOTE: `sbt --version` returns a non-zero exit status.
|
||||||
|
list($err, $stdout) = exec_manual(
|
||||||
|
'%C --version',
|
||||||
|
$this->getExecutableCommand());
|
||||||
|
|
||||||
|
$matches = array();
|
||||||
|
$regex = '/^sbt launcher version (?P<version>\d+\.\d+\.\d+)$/';
|
||||||
|
if (preg_match($regex, $stdout, $matches)) {
|
||||||
|
return $matches['version'];
|
||||||
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInstallInstructions() {
|
||||||
|
return pht(
|
||||||
|
'Check <http://www.scala-sbt.org> for installation instructions.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shouldExpectCommandErrors() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSBTPath() {
|
protected function getMandatoryFlags() {
|
||||||
$sbt_bin = "sbt";
|
return array(
|
||||||
|
'-Dsbt.log.noformat=true',
|
||||||
$prefix = $this->getDeprecatedConfiguration('lint.scala_sbt.prefix');
|
'compile',
|
||||||
if ($prefix !== null) {
|
);
|
||||||
$sbt_bin = $prefix . $sbt_bin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sbt_bin;
|
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
|
||||||
}
|
$lines = phutil_split_lines($stdout, false);
|
||||||
|
|
||||||
private function getMessageCodeSeverity($type_of_error) {
|
|
||||||
switch ($type_of_error) {
|
|
||||||
case 'warn':
|
|
||||||
return ArcanistLintSeverity::SEVERITY_WARNING;
|
|
||||||
case 'error':
|
|
||||||
return ArcanistLintSeverity::SEVERITY_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function lintPath($path) {
|
|
||||||
$sbt = $this->getSBTPath();
|
|
||||||
|
|
||||||
// Tell SBT to not use color codes so our regex life is easy.
|
|
||||||
// TODO: Should this be "clean compile" instead of "compile"?
|
|
||||||
$f = new ExecFuture("%s -Dsbt.log.noformat=true compile", $sbt);
|
|
||||||
list($err, $stdout, $stderr) = $f->resolve();
|
|
||||||
|
|
||||||
$lines = explode("\n", $stdout);
|
|
||||||
$messages = array();
|
$messages = array();
|
||||||
|
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
$matches = null;
|
$matches = null;
|
||||||
if (!preg_match(
|
$regex = '/\[(warn|error)\] (.*?):(\d+): (.*?)$/';
|
||||||
"/\[(warn|error)\] (.*?):(\d+): (.*?)$/",
|
if (!preg_match($regex, $line, $matches)) {
|
||||||
$line,
|
|
||||||
$matches)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach ($matches as $key => $match) {
|
foreach ($matches as $key => $match) {
|
||||||
|
@ -68,9 +86,23 @@ final class ArcanistScalaSBTLinter extends ArcanistLinter {
|
||||||
$message->setLine($matches[3]);
|
$message->setLine($matches[3]);
|
||||||
$message->setCode($this->getLinterName());
|
$message->setCode($this->getLinterName());
|
||||||
$message->setDescription($matches[4]);
|
$message->setDescription($matches[4]);
|
||||||
$message->setSeverity($this->getMessageCodeSeverity($matches[1]));
|
|
||||||
$this->addLintMessage($message);
|
switch ($matches[1]) {
|
||||||
|
case 'error':
|
||||||
|
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
|
||||||
|
break;
|
||||||
|
case 'warn':
|
||||||
|
$message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$messages[] = $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue