]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Provide a getProjectRoot method for ArcanistLinter
authorJoshua Spence <josh@joshuaspence.com>
Tue, 19 May 2015 23:16:36 +0000 (09:16 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Tue, 19 May 2015 23:16:36 +0000 (09:16 +1000)
Summary: Adds a `getProjectRoot()` method to the `ArcanistLinter` class, simplifying a bunch of code.

Test Plan: `arc unit`

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

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

src/lint/linter/ArcanistExternalLinter.php
src/lint/linter/ArcanistLinter.php
src/lint/linter/ArcanistScriptAndRegexLinter.php
src/lint/linter/ArcanistSpellingLinter.php

index 418a434a7213a594c44ddbc6e8c0431c2ff37c4d..835860817eadba65affce908b410e5192f00f4e8 100644 (file)
@@ -339,7 +339,7 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
       $path_argument = $this->getPathArgumentForLinterFuture($disk_path);
       $future = new ExecFuture('%C %C', $bin, $path_argument);
 
-      $future->setCWD($this->getEngine()->getWorkingCopy()->getProjectRoot());
+      $future->setCWD($this->getProjectRoot());
       $futures[$path] = $future;
     }
 
@@ -407,8 +407,7 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
   public function setLinterConfigurationValue($key, $value) {
     switch ($key) {
       case 'interpreter':
-        $working_copy = $this->getEngine()->getWorkingCopy();
-        $root = $working_copy->getProjectRoot();
+        $root = $this->getProjectRoot();
 
         foreach ((array)$value as $path) {
           if (Filesystem::binaryExists($path)) {
@@ -429,8 +428,7 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
       case 'bin':
         $is_script = $this->shouldUseInterpreter();
 
-        $working_copy = $this->getEngine()->getWorkingCopy();
-        $root = $working_copy->getProjectRoot();
+        $root = $this->getProjectRoot();
 
         foreach ((array)$value as $path) {
           if (!$is_script && Filesystem::binaryExists($path)) {
index aae1fbbd801624b1d3bafb452f56f1d485ec3f64..b7def1634aea0087e07ca873395f435129e097c7 100644 (file)
@@ -248,6 +248,24 @@ abstract class ArcanistLinter {
     return $this;
   }
 
+  final public function getProjectRoot() {
+    $engine = $this->getEngine();
+    if (!$engine) {
+      throw new Exception(
+        pht(
+          'You must call %s before you can call %s.',
+          'setEngine()',
+          __FUNCTION__.'()'));
+    }
+
+    $working_copy = $engine->getWorkingCopy();
+    if (!$working_copy) {
+      return null;
+    }
+
+    return $working_copy->getProjectRoot();
+  }
+
   final public function getOtherLocation($offset, $path = null) {
     if ($path === null) {
       $path = $this->getActivePath();
@@ -386,7 +404,7 @@ abstract class ArcanistLinter {
   }
 
   final protected function addLintMessage(ArcanistLintMessage $message) {
-    $root = $this->getEngine()->getWorkingCopy()->getProjectRoot();
+    $root = $this->getProjectRoot();
     $path = Filesystem::resolvePath($message->getPath(), $root);
     $message->setPath(Filesystem::readablePath($path, $root));
 
index 8e8a1f5c5622c923908111af7755270403e3463c..af2ebb95339235774ef83a5a5607ec6936527f07 100644 (file)
@@ -180,7 +180,7 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
    */
   public function willLintPaths(array $paths) {
     $script = $this->getConfiguredScript();
-    $root   = $this->getEngine()->getWorkingCopy()->getProjectRoot();
+    $root   = $this->getProjectRoot();
 
     $futures = array();
     foreach ($paths as $path) {
index d22e67fb4309d759ff8168446bc753b05e849703..f27bc9064577408cff7aaa1c6b1678f280b10503 100644 (file)
@@ -54,7 +54,7 @@ final class ArcanistSpellingLinter extends ArcanistLinter {
   }
 
   public function loadDictionary($path) {
-    $root = $this->getEngine()->getWorkingCopy()->getProjectRoot();
+    $root = $this->getProjectRoot();
     $path = Filesystem::resolvePath($path, $root);
 
     $dict = phutil_json_decode(Filesystem::readFile($path));