diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -91,6 +91,7 @@ '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 @@ '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 --- /dev/null +++ b/src/lint/renderer/ArcanistLintCheckstyleXMLRenderer.php @@ -0,0 +1,53 @@ +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(); + } +} diff --git a/src/lint/renderer/ArcanistLintRenderer.php b/src/lint/renderer/ArcanistLintRenderer.php --- a/src/lint/renderer/ArcanistLintRenderer.php +++ b/src/lint/renderer/ArcanistLintRenderer.php @@ -10,4 +10,8 @@ abstract public function renderLintResult(ArcanistLintResult $result); abstract public function renderOkayResult(); + public function renderPostamble() { + return ''; + } + } diff --git a/src/workflow/ArcanistLintWorkflow.php b/src/workflow/ArcanistLintWorkflow.php --- a/src/workflow/ArcanistLintWorkflow.php +++ b/src/workflow/ArcanistLintWorkflow.php @@ -96,7 +96,8 @@ "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 @@ $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 @@ } } + $console->writeOut('%s', $renderer->renderPostamble()); + if ($wrote_to_disk && $this->shouldAmendChanges) { if ($this->shouldAmendWithoutPrompt || ($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) {