]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add a `getVersion` function to `ArcanistExternalLinter`.
authorJoshua Spence <josh@joshuaspence.com>
Mon, 5 May 2014 22:10:20 +0000 (15:10 -0700)
committerepriestley <git@epriestley.com>
Mon, 5 May 2014 22:10:20 +0000 (15:10 -0700)
Summary:
This method will, theoretically, allow `arc lint` to be configured to require some minimum version of an external linter (although this would probably require significantly more work).

Additionally, the existence of this method simplifies the `getCacheVersion` function which, previously, was implemented by the external linters individually. Instead, a general approach to determining the version for cacheing purposes can be used.

Fixes T4954.

Test Plan: I'm not sure how to test this.

Reviewers: chad, epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Maniphest Tasks: T4954

Differential Revision: https://secure.phabricator.com/D8971

src/lint/linter/ArcanistCSSLintLinter.php
src/lint/linter/ArcanistExternalLinter.php
src/lint/linter/ArcanistFlake8Linter.php
src/lint/linter/ArcanistJSHintLinter.php
src/lint/linter/ArcanistPEP8Linter.php
src/lint/linter/ArcanistPhpcsLinter.php
src/lint/linter/ArcanistRubyLinter.php

index a69929cfde22e2e4cb04dd8db09542e5b6aacdd4..25b1afe0a34ba466da995f393be5472480170575 100644 (file)
@@ -34,6 +34,17 @@ final class ArcanistCSSLintLinter extends ArcanistExternalLinter {
     return $config->getConfigFromAnySource('lint.csslint.bin', 'csslint');
   }
 
+  public function getVersion() {
+    list($stdout) = execx('%C --version', $this->getExecutableCommand());
+
+    $matches = array();
+    if (preg_match('/^v(?P<version>\d+\.\d+\.\d+)$/', $stdout, $matches)) {
+      return $matches['version'];
+    } else {
+      return false;
+    }
+  }
+
   public function getInstallInstructions() {
     return pht('Install CSSLint using `npm install -g csslint`.');
   }
index 4a9523593ae49b2325f49fe8a4e0f8d4871cdc77..a858a54e05a436b68148a63f9322ef15482c1a5b 100644 (file)
@@ -369,6 +369,21 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return array_merge($mandatory_flags, $flags);
   }
 
+  public function getCacheVersion() {
+    $version = $this->getVersion();
+
+    if ($version) {
+      return $version.'-'.json_encode($this->getCommandFlags());
+    } else {
+      // Either we failed to parse the version number or the `getVersion`
+      // function hasn't been implemented.
+      return json_encode($this->getCommandFlags());
+    }
+  }
+
+  public function getVersion() {
+    return null;
+  }
 
   protected function buildFutures(array $paths) {
     $executable = $this->getExecutableCommand();
index 36ecbd70c46de6729b6da378e65a3aafae72f8c7..3fc905c3146c1144850ed60d7e636e6789f4705d 100644 (file)
@@ -34,6 +34,17 @@ final class ArcanistFlake8Linter extends ArcanistExternalLinter {
     return 'flake8';
   }
 
+  public function getVersion() {
+    list($stdout) = execx('%C --version', $this->getExecutableCommand());
+
+    $matches = array();
+    if (preg_match('/^(?P<version>\d+\.\d+\.\d+)\b/', $stdout, $matches)) {
+      return $matches['version'];
+    } else {
+      return false;
+    }
+  }
+
   public function getInstallInstructions() {
     return pht('Install flake8 using `easy_install flake8`.');
   }
index ffd444f4f47d16785b9b58a01199ff61dbf60467..52cb01465f971bbb839ae9f9b2ca34cb44aa9114 100644 (file)
@@ -35,18 +35,16 @@ final class ArcanistJSHintLinter extends ArcanistExternalLinter {
     }
   }
 
-  public function getCacheVersion() {
+  public function getVersion() {
     list($stdout) = execx('%C --version', $this->getExecutableCommand());
 
-    // Extract version number from standard output.
     $matches = array();
-    if (preg_match('/^jshint v(\d+\.\d+\.\d+)$/', $stdout, $matches)) {
-      $version = $matches[1];
+    $regex = '/^jshint v(?P<version>\d+\.\d+\.\d+)$/';
+    if (preg_match($regex, $stdout, $matches)) {
+      return $matches['version'];
     } else {
-      $version = md5($stdout);
+      return false;
     }
-
-    return $version . '-' . md5(json_encode($this->getCommandFlags()));
   }
 
   public function getInstallInstructions() {
index 1058c8f17eb5ee9001ec1df12d31f77dbe2808e5..688966d49c537e2757cbec071fc665f520616ddf 100644 (file)
@@ -15,11 +15,6 @@ final class ArcanistPEP8Linter extends ArcanistExternalLinter {
     return 'pep8';
   }
 
-  public function getCacheVersion() {
-    list($stdout) = execx('%C --version', $this->getExecutableCommand());
-    return $stdout.implode(' ', $this->getCommandFlags());
-  }
-
   public function getDefaultFlags() {
     // TODO: Warn that all of this is deprecated.
     $config = $this->getEngine()->getConfigurationManager();
@@ -55,6 +50,17 @@ final class ArcanistPEP8Linter extends ArcanistExternalLinter {
     return $arc_root.'/externals/pep8/pep8.py';
   }
 
+  public function getVersion() {
+    list($stdout) = execx('%C --version', $this->getExecutableCommand());
+
+    $matches = array();
+    if (preg_match('/^(?P<version>\d+\.\d+\.\d+)$/', $stdout, $matches)) {
+      return $matches['version'];
+    } else {
+      return false;
+    }
+  }
+
   public function getInstallInstructions() {
     return pht('Install PEP8 using `easy_install pep8`.');
   }
index a5c292b2f1dd55a3690f92174595985b8aae0bf0..e1fa3d9d6f73695d70d370f20d893d359a1ba769 100644 (file)
@@ -58,6 +58,18 @@ final class ArcanistPhpcsLinter extends ArcanistExternalLinter {
     return $config->getConfigFromAnySource('lint.phpcs.bin', 'phpcs');
   }
 
+  public function getVersion() {
+    list($stdout) = execx('%C --version', $this->getExecutableCommand());
+
+    $matches = array();
+    $regex = '/^PHP_CodeSniffer version (?P<version>\d+\.\d+\.\d+)\b/';
+    if (preg_match($regex, $stdout, $matches)) {
+      return $matches['version'];
+    } else {
+      return false;
+    }
+  }
+
   public function shouldExpectCommandErrors() {
     return true;
   }
index 2921f5f437cb31ab9a050b317fa2e9ec26cf210d..15ba1b72ba1e38c411fe48a09c04b183de32330c 100644 (file)
@@ -26,6 +26,18 @@ final class ArcanistRubyLinter extends ArcanistExternalLinter {
     return 'ruby';
   }
 
+  public function getVersion() {
+    list($stdout) = execx('%C --version', $this->getExecutableCommand());
+
+    $matches = array();
+    $regex = '/^ruby (?P<version>\d+\.\d+\.\d+)p\d+/';
+    if (preg_match($regex, $stdout, $matches)) {
+      return $matches['version'];
+    } else {
+      return false;
+    }
+  }
+
   public function getInstallInstructions() {
     return pht('Install `ruby` from <http://www.ruby-lang.org/>.');
   }