Commit 9fda895f authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #3171307 by webflo: upgrade_status:checkstyle does not produce valid XML...

Issue #3171307 by webflo: upgrade_status:checkstyle does not produce valid XML output when multiple projects are scanned at once
parent 4018da83
......@@ -43,13 +43,6 @@ class UpgradeStatusCommands extends DrushCommands {
*/
protected $dateFormatter;
/**
* Output mode (format).
*
* @var string
*/
protected $mode = 'ascii';
/**
* Constructs a new UpgradeStatusCommands object.
*
......@@ -93,8 +86,40 @@ class UpgradeStatusCommands extends DrushCommands {
* Thrown when one of the passed arguments is invalid or no arguments were provided.
*/
public function checkstyle(array $projects, array $options = ['all' => FALSE, 'skip-existing' => FALSE, 'ignore-uninstalled' => FALSE, 'ignore-contrib' => FALSE, 'ignore-custom' => FALSE]) {
$this->mode = 'checkstyle';
$this->analyze($projects, $options);
$extensions = $this->doAnalyze($projects, $options);
$xml = new \SimpleXMLElement("<?xml version='1.0'?><checkstyle/>");
foreach ($extensions as $type => $list) {
foreach ($list as $name => $extension) {
$result = $this->resultFormatter->getRawResult($extension);
if (is_null($result)) {
$this->logger()->error('Project scan @name failed.', ['@name' => $name]);
continue;
}
foreach ($result['data']['files'] as $filepath => $errors) {
$short_path = str_replace(DRUPAL_ROOT . '/', '', $filepath);
$file_xml = $xml->addChild('file');
$file_xml->addAttribute('name', $short_path);
foreach ($errors['messages'] as $error) {
$severity = 'error';
if ($error['upgrade_status_category'] == 'ignore') {
$severity = 'info';
}
elseif ($error['upgrade_status_category'] == 'later') {
$severity = 'warning';
}
$error_xml = $file_xml->addChild('error');
$error_xml->addAttribute('line', $error['line']);
$error_xml->addAttribute('message', $error['message']);
$error_xml->addAttribute('severity', $severity);
}
}
}
}
$this->output()->writeln($xml->asXML());
}
/**
......@@ -117,6 +142,46 @@ class UpgradeStatusCommands extends DrushCommands {
* Thrown when one of the passed arguments is invalid or no arguments were provided.
*/
public function analyze(array $projects, array $options = ['all' => FALSE, 'skip-existing' => FALSE, 'ignore-uninstalled' => FALSE, 'ignore-contrib' => FALSE, 'ignore-custom' => FALSE]) {
$extensions = $this->doAnalyze($projects, $options);
foreach ($extensions as $type => $list) {
$this->output()->writeln('');
$this->output()->writeln(str_pad('', 80, '='));
foreach ($list as $name => $extension) {
$result = $this->resultFormatter->getRawResult($extension);
if (is_null($result)) {
$this->logger()->error('Project scan @name failed.', ['@name' => $name]);
continue;
}
$output = $this->formatDrushStdoutResult($extension);
foreach ($output as $line) {
$this->output()->writeln($line);
}
}
}
}
/**
* Analyze projects and return all processed extensions.
*
* @param array $projects
* List of projects to analyze.
* @param array $options
* Additional options for the command.
*
* @option all Analyze all projects.
* @option skip-existing Return results from a previous scan of a project if available, otherwise start a new one.
* @option ignore-uninstalled Ignore uninstalled projects.
* @option ignore-contrib Ignore contributed projects.
* @option ignore-custom Ignore custom projects.
*
* @throws \InvalidArgumentException
* Thrown when one of the passed arguments is invalid or no arguments were provided.
*/
public function doAnalyze(array $projects, array $options = ['all' => FALSE, 'skip-existing' => FALSE, 'ignore-uninstalled' => FALSE, 'ignore-contrib' => FALSE, 'ignore-custom' => FALSE]) {
// Group by type here so we can tell loader what is type of each one of
// these.
$extensions = [];
......@@ -197,59 +262,7 @@ class UpgradeStatusCommands extends DrushCommands {
}
}
if ($this->mode !== 'ascii') {
$xml = new \SimpleXMLElement("<?xml version='1.0'?><checkstyle/>");
}
foreach ($extensions as $type => $list) {
if ($this->mode === 'ascii') {
$this->output()->writeln('');
$this->output()->writeln(str_pad('', 80, '='));
}
$track = 0;
foreach ($list as $name => $extension) {
$result = $this->resultFormatter->getRawResult($extension);
if (is_null($result)) {
$this->logger()
->error('Project scan @name failed.', ['@name' => $name]);
continue;
}
if ($this->mode === 'ascii') {
$output = $this->formatDrushStdoutResult($extension);
foreach ($output as $line) {
$this->output()->writeln($line);
}
if (++$track < count($list)) {
$this->output()->writeln(str_pad('', 80, '='));
}
}
else {
foreach ($result['data']['files'] as $filepath => $errors) {
$short_path = str_replace(DRUPAL_ROOT . '/', '', $filepath);
$file_xml = $xml->addChild('file');
$file_xml->addAttribute('name', $short_path);
foreach ($errors['messages'] as $error) {
$severity = 'error';
if ($error['upgrade_status_category'] == 'ignore') {
$severity = 'info';
}
elseif ($error['upgrade_status_category'] == 'later') {
$severity = 'warning';
}
$error_xml = $file_xml->addChild('error');
$error_xml->addAttribute('line', $error['line']);
$error_xml->addAttribute('message', $error['message']);
$error_xml->addAttribute('severity', $severity);
}
}
$this->output()->writeln($xml->asXML());
}
}
}
return $extensions;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment