Changeset View
Changeset View
Standalone View
Standalone View
src/lint/renderer/ArcanistCheckstyleXMLLintRenderer.php
| <?php | <?php | ||||
| final class ArcanistCheckstyleXMLLintRenderer extends ArcanistLintRenderer { | final class ArcanistCheckstyleXMLLintRenderer extends ArcanistLintRenderer { | ||||
| const RENDERERKEY = 'xml'; | const RENDERERKEY = 'xml'; | ||||
| private $writer; | private $writer; | ||||
| public function __construct() { | private function getWriter() { | ||||
| $this->writer = new XMLWriter(); | if (!$this->writer) { | ||||
| $this->writer->openMemory(); | $xml_extension = 'XMLWriter'; | ||||
| $this->writer->setIndent(true); | |||||
| $this->writer->setIndentString(' '); | if (!extension_loaded($xml_extension)) { | ||||
| throw new Exception( | |||||
| pht( | |||||
| 'Lint can not be output into "%s" format because the PHP "%s" '. | |||||
| 'extension is not installed. Install the extension or choose a '. | |||||
| 'different output format.', | |||||
| self::RENDERERKEY, | |||||
| $xml_extension)); | |||||
| } | |||||
| $writer = new XMLWriter(); | |||||
| $writer->openMemory(); | |||||
| $writer->setIndent(true); | |||||
| $writer->setIndentString(' '); | |||||
| $this->writer = $writer; | |||||
| } | |||||
| return $this->writer; | |||||
| } | } | ||||
| public function willRenderResults() { | public function willRenderResults() { | ||||
| $this->writer->startDocument('1.0', 'UTF-8'); | $writer = $this->getWriter(); | ||||
| $this->writer->startElement('checkstyle'); | |||||
| $this->writer->writeAttribute('version', '4.3'); | $writer->startDocument('1.0', 'UTF-8'); | ||||
| $this->writeOut($this->writer->flush()); | $writer->startElement('checkstyle'); | ||||
| $writer->writeAttribute('version', '4.3'); | |||||
| $this->writeOut($writer->flush()); | |||||
| } | } | ||||
| public function renderLintResult(ArcanistLintResult $result) { | public function renderLintResult(ArcanistLintResult $result) { | ||||
| $this->writer->startElement('file'); | $writer = $this->getWriter(); | ||||
| $this->writer->writeAttribute('name', $result->getPath()); | |||||
| $writer->startElement('file'); | |||||
| $writer->writeAttribute('name', $result->getPath()); | |||||
| foreach ($result->getMessages() as $message) { | foreach ($result->getMessages() as $message) { | ||||
| $this->writer->startElement('error'); | $writer->startElement('error'); | ||||
| $this->writer->writeAttribute('line', $message->getLine()); | $writer->writeAttribute('line', $message->getLine()); | ||||
| $this->writer->writeAttribute('column', $message->getChar()); | $writer->writeAttribute('column', $message->getChar()); | ||||
| $this->writer->writeAttribute('severity', | $writer->writeAttribute('severity', | ||||
| $this->getStringForSeverity($message->getSeverity())); | $this->getStringForSeverity($message->getSeverity())); | ||||
| $this->writer->writeAttribute('message', $message->getDescription()); | $writer->writeAttribute('message', $message->getDescription()); | ||||
| $this->writer->writeAttribute('source', $message->getCode()); | $writer->writeAttribute('source', $message->getCode()); | ||||
| $this->writer->endElement(); | $writer->endElement(); | ||||
| } | } | ||||
| $this->writer->endElement(); | $writer->endElement(); | ||||
| $this->writeOut($this->writer->flush()); | $this->writeOut($writer->flush()); | ||||
| } | } | ||||
| public function didRenderResults() { | public function didRenderResults() { | ||||
| $this->writer->endElement(); | $writer = $this->getWriter(); | ||||
| $this->writer->endDocument(); | |||||
| $this->writeOut($this->writer->flush()); | $writer->endElement(); | ||||
| $writer->endDocument(); | |||||
| $this->writeOut($writer->flush()); | |||||
| } | } | ||||
| private function getStringForSeverity($severity) { | private function getStringForSeverity($severity) { | ||||
| switch ($severity) { | switch ($severity) { | ||||
| case ArcanistLintSeverity::SEVERITY_ADVICE: | case ArcanistLintSeverity::SEVERITY_ADVICE: | ||||
| return 'info'; | return 'info'; | ||||
| case ArcanistLintSeverity::SEVERITY_AUTOFIX: | case ArcanistLintSeverity::SEVERITY_AUTOFIX: | ||||
| return 'info'; | return 'info'; | ||||
| Show All 10 Lines | |||||