1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-08 07:52:39 +01:00

Don't depend on "XMLWriter" to load the lint renderer class tree

Summary: Fixes T13489. See that task for discussion.

Test Plan: Ran `arc lint` and `arc lint --output xml`. Faked a missing extension, ran `arc lint` (no problems) and `arc lint --output xml` (sensible error message).

Maniphest Tasks: T13489

Differential Revision: https://secure.phabricator.com/D20989
This commit is contained in:
epriestley 2020-02-13 13:36:51 -08:00
parent 8c4f6ce161
commit 0d62a10eda

View file

@ -6,45 +6,69 @@ final class ArcanistCheckstyleXMLLintRenderer extends ArcanistLintRenderer {
private $writer;
public function __construct() {
$this->writer = new XMLWriter();
$this->writer->openMemory();
$this->writer->setIndent(true);
$this->writer->setIndentString(' ');
private function getWriter() {
if (!$this->writer) {
$xml_extension = 'XMLWriter';
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() {
$this->writer->startDocument('1.0', 'UTF-8');
$this->writer->startElement('checkstyle');
$this->writer->writeAttribute('version', '4.3');
$this->writeOut($this->writer->flush());
$writer = $this->getWriter();
$writer->startDocument('1.0', 'UTF-8');
$writer->startElement('checkstyle');
$writer->writeAttribute('version', '4.3');
$this->writeOut($writer->flush());
}
public function renderLintResult(ArcanistLintResult $result) {
$this->writer->startElement('file');
$this->writer->writeAttribute('name', $result->getPath());
$writer = $this->getWriter();
$writer->startElement('file');
$writer->writeAttribute('name', $result->getPath());
foreach ($result->getMessages() as $message) {
$this->writer->startElement('error');
$writer->startElement('error');
$this->writer->writeAttribute('line', $message->getLine());
$this->writer->writeAttribute('column', $message->getChar());
$this->writer->writeAttribute('severity',
$writer->writeAttribute('line', $message->getLine());
$writer->writeAttribute('column', $message->getChar());
$writer->writeAttribute('severity',
$this->getStringForSeverity($message->getSeverity()));
$this->writer->writeAttribute('message', $message->getDescription());
$this->writer->writeAttribute('source', $message->getCode());
$writer->writeAttribute('message', $message->getDescription());
$writer->writeAttribute('source', $message->getCode());
$this->writer->endElement();
$writer->endElement();
}
$this->writer->endElement();
$this->writeOut($this->writer->flush());
$writer->endElement();
$this->writeOut($writer->flush());
}
public function didRenderResults() {
$this->writer->endElement();
$this->writer->endDocument();
$this->writeOut($this->writer->flush());
$writer = $this->getWriter();
$writer->endElement();
$writer->endDocument();
$this->writeOut($writer->flush());
}
private function getStringForSeverity($severity) {