mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-08 16:02: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:
parent
8c4f6ce161
commit
0d62a10eda
1 changed files with 47 additions and 23 deletions
|
@ -6,45 +6,69 @@ final class ArcanistCheckstyleXMLLintRenderer extends ArcanistLintRenderer {
|
||||||
|
|
||||||
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) {
|
||||||
|
|
Loading…
Reference in a new issue