]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Support Checkstyle as an output format for lint results.
authorJoshua Spence <josh@joshuaspence.com>
Tue, 13 May 2014 20:20:29 +0000 (13:20 -0700)
committerepriestley <git@epriestley.com>
Tue, 13 May 2014 20:20:29 +0000 (13:20 -0700)
Summary: Fixes T4948. Add a lint renderer which supports outputting the lint results in the Checkstyle XML format.

Test Plan: Ran `arc lint --xml` and inspected the output.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T4948

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

src/__phutil_library_map__.php
src/lint/renderer/ArcanistLintCheckstyleXMLRenderer.php [new file with mode: 0644]
src/lint/renderer/ArcanistLintRenderer.php
src/workflow/ArcanistLintWorkflow.php

index b561365199c8e48f7e0a92cd8ff6d4c242a829d1..6131a1aa3704816a3f2a96707473ea26fda1763d 100644 (file)
@@ -91,6 +91,7 @@ phutil_register_library_map(array(
     'ArcanistLesscLinter' => 'lint/linter/ArcanistLesscLinter.php',
     'ArcanistLesscLinterTestCase' => 'lint/linter/__tests__/ArcanistLesscLinterTestCase.php',
     'ArcanistLiberateWorkflow' => 'workflow/ArcanistLiberateWorkflow.php',
+    'ArcanistLintCheckstyleXMLRenderer' => 'lint/renderer/ArcanistLintCheckstyleXMLRenderer.php',
     'ArcanistLintConsoleRenderer' => 'lint/renderer/ArcanistLintConsoleRenderer.php',
     'ArcanistLintEngine' => 'lint/engine/ArcanistLintEngine.php',
     'ArcanistLintJSONRenderer' => 'lint/renderer/ArcanistLintJSONRenderer.php',
@@ -262,6 +263,7 @@ phutil_register_library_map(array(
     'ArcanistLesscLinter' => 'ArcanistExternalLinter',
     'ArcanistLesscLinterTestCase' => 'ArcanistArcanistLinterTestCase',
     'ArcanistLiberateWorkflow' => 'ArcanistBaseWorkflow',
+    'ArcanistLintCheckstyleXMLRenderer' => 'ArcanistLintRenderer',
     'ArcanistLintConsoleRenderer' => 'ArcanistLintRenderer',
     'ArcanistLintJSONRenderer' => 'ArcanistLintRenderer',
     'ArcanistLintLikeCompilerRenderer' => 'ArcanistLintRenderer',
diff --git a/src/lint/renderer/ArcanistLintCheckstyleXMLRenderer.php b/src/lint/renderer/ArcanistLintCheckstyleXMLRenderer.php
new file mode 100644 (file)
index 0000000..081ead9
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+/**
+ * Shows lint messages to the user.
+ *
+ * @group lint
+ */
+final class ArcanistLintCheckstyleXMLRenderer extends ArcanistLintRenderer {
+
+  private $writer;
+
+  public function __construct() {
+    $this->writer = new XMLWriter();
+    $this->writer->openMemory();
+    $this->writer->setIndent(true);
+    $this->writer->setIndentString('  ');
+
+    $this->writer->startDocument('1.0', 'UTF-8');
+    $this->writer->startElement('checkstyle');
+    $this->writer->writeAttribute('version', '4.3');
+  }
+
+  public function renderLintResult(ArcanistLintResult $result) {
+    $this->writer->startElement('file');
+    $this->writer->writeAttribute('name', $result->getPath());
+
+    foreach ($result->getMessages() as $message) {
+      $this->writer->startElement('error');
+
+      $this->writer->writeAttribute('line', $message->getLine());
+      $this->writer->writeAttribute('column', $message->getChar());
+      $this->writer->writeAttribute('severity',
+        ArcanistLintSeverity::getStringForSeverity($message->getSeverity()));
+      $this->writer->writeAttribute('message', $message->getDescription());
+      $this->writer->writeAttribute('source', $message->getCode());
+
+      $this->writer->endElement();
+    }
+
+    $this->writer->endElement();
+    return $this->writer->flush();
+  }
+
+  public function renderOkayResult() {
+    return '';
+  }
+
+  public function renderPostamble() {
+    $this->writer->endElement();
+    $this->writer->endDocument();
+    return $this->writer->flush();
+  }
+}
index 1b1c19fda0c27dde004c47187ea2367903d90959..bc82a32fc7663bc779c8c3d4ee54bb0943d61812 100644 (file)
@@ -10,4 +10,8 @@ abstract class ArcanistLintRenderer {
   abstract public function renderLintResult(ArcanistLintResult $result);
   abstract public function renderOkayResult();
 
+  public function renderPostamble() {
+    return '';
+  }
+
 }
index df5155858d9507bfb08c6bf3278d5988a3bd7052..3845118da854c28bc8c535317470d846ad6acdb3 100644 (file)
@@ -96,7 +96,8 @@ EOTEXT
           "With 'summary', show lint warnings in a more compact format. ".
           "With 'json', show lint warnings in machine-readable JSON format. ".
           "With 'none', show no lint warnings. ".
-          "With 'compiler', show lint warnings in suitable for your editor."
+          "With 'compiler', show lint warnings in suitable for your editor. ".
+          "With 'xml', show lint warnings in the Checkstyle XML format."
       ),
       'only-new' => array(
         'param' => 'bool',
@@ -456,6 +457,9 @@ EOTEXT
         $prompt_patches = false;
         $apply_patches = $this->getArgument('apply-patches');
         break;
+      case 'xml':
+        $renderer = new ArcanistLintCheckstyleXMLRenderer();
+        break;
       default:
         $renderer = new ArcanistLintConsoleRenderer();
         $renderer->setShowAutofixPatches($prompt_autofix_patches);
@@ -514,6 +518,8 @@ EOTEXT
       }
     }
 
+    $console->writeOut('%s', $renderer->renderPostamble());
+
     if ($wrote_to_disk && $this->shouldAmendChanges) {
       if ($this->shouldAmendWithoutPrompt ||
           ($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) {