]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Modernize `ArcanistScalaSBTLinter`.
authorJoshua Spence <josh@joshuaspence.com>
Sun, 18 May 2014 17:49:22 +0000 (10:49 -0700)
committerepriestley <git@epriestley.com>
Sun, 18 May 2014 17:49:22 +0000 (10:49 -0700)
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

src/__phutil_library_map__.php
src/lint/linter/ArcanistScalaSBTLinter.php

index 6956fd0b359559dc15264c274f67d1ce3a73a210..f60b447d6b0a19dc3e0885b993289705c739384e 100644 (file)
@@ -311,7 +311,7 @@ phutil_register_library_map(array(
     'ArcanistRevertWorkflow' => 'ArcanistBaseWorkflow',
     'ArcanistRubyLinter' => 'ArcanistExternalLinter',
     'ArcanistRubyLinterTestCase' => 'ArcanistArcanistLinterTestCase',
-    'ArcanistScalaSBTLinter' => 'ArcanistLinter',
+    'ArcanistScalaSBTLinter' => 'ArcanistExternalLinter',
     'ArcanistScriptAndRegexLinter' => 'ArcanistLinter',
     'ArcanistSetConfigWorkflow' => 'ArcanistBaseWorkflow',
     'ArcanistShellCompleteWorkflow' => 'ArcanistBaseWorkflow',
index 5e24f358df5a543f3b00746b0bf1a69b2f489b72..804833101653171ffaf0a3417b4ea33485c8f93c 100644 (file)
@@ -3,60 +3,78 @@
 /**
  * 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() {
     return 'ScalaSBT';
   }
 
-  public function canRun() {
-    // Check if this looks like a SBT project. If it doesn't, throw, because
-    // 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.
-    if (!Filesystem::pathExists('project/Build.scala') &&
-      !Filesystem::pathExists('build.sbt')) {
-      return false;
-    }
-    return true;
+  public function getLinterConfigurationName() {
+    return 'scala-sbt';
   }
 
-  private function getSBTPath() {
-    $sbt_bin = "sbt";
-
+  public function getDefaultBinary() {
     $prefix = $this->getDeprecatedConfiguration('lint.scala_sbt.prefix');
-    if ($prefix !== null) {
-      $sbt_bin = $prefix . $sbt_bin;
-    }
+    $bin = 'sbt';
 
-    return $sbt_bin;
+    if ($prefix) {
+      return $prefix.'/'.$bin;
+    } else {
+      return $bin;
+    }
   }
 
-  private function getMessageCodeSeverity($type_of_error) {
-    switch ($type_of_error) {
-      case 'warn':
-        return ArcanistLintSeverity::SEVERITY_WARNING;
-      case 'error':
-        return ArcanistLintSeverity::SEVERITY_ERROR;
+  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;
     }
   }
 
-  public function lintPath($path) {
-    $sbt = $this->getSBTPath();
+  public function getInstallInstructions() {
+    return pht(
+      'Check <http://www.scala-sbt.org> for installation instructions.');
+  }
+
+  public function shouldExpectCommandErrors() {
+    return true;
+  }
 
-    // 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();
+  protected function getMandatoryFlags() {
+    return array(
+      '-Dsbt.log.noformat=true',
+      'compile',
+    );
+  }
 
-    $lines = explode("\n", $stdout);
+  protected function parseLinterOutput($path, $err, $stdout, $stderr) {
+    $lines = phutil_split_lines($stdout, false);
     $messages = array();
+
     foreach ($lines as $line) {
       $matches = null;
-      if (!preg_match(
-        "/\[(warn|error)\] (.*?):(\d+): (.*?)$/",
-        $line,
-        $matches)) {
+      $regex = '/\[(warn|error)\] (.*?):(\d+): (.*?)$/';
+      if (!preg_match($regex, $line, $matches)) {
         continue;
       }
       foreach ($matches as $key => $match) {
@@ -68,9 +86,23 @@ final class ArcanistScalaSBTLinter extends ArcanistLinter {
       $message->setLine($matches[3]);
       $message->setCode($this->getLinterName());
       $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;
   }
 
 }