This commit is contained in:
Stephen Ball 2015-10-15 18:43:18 +00:00
commit 5183162bde
2 changed files with 96 additions and 2 deletions

View file

@ -26,6 +26,7 @@ class Lint implements PHPCI\Plugin
protected $ignore;
protected $phpci;
protected $build;
protected $failedPaths = array();
/**
* Standard Constructor
@ -69,6 +70,8 @@ class Lint implements PHPCI\Plugin
$php = $this->phpci->findBinary('php');
$this->phpci->logExecOutput(false);
foreach ($this->directories as $dir) {
if (!$this->lintDirectory($php, $dir)) {
$success = false;
@ -77,6 +80,11 @@ class Lint implements PHPCI\Plugin
$this->phpci->quiet = false;
$this->phpci->logExecOutput(true);
$this->build->storeMeta('phplint-warnings', count($this->failedPaths));
$this->build->storeMeta('phplint-data', $this->failedPaths);
return $success;
}
@ -140,8 +148,16 @@ class Lint implements PHPCI\Plugin
{
$success = true;
if (!$this->phpci->executeCommand($php . ' -l "%s"', $this->phpci->buildPath . $path)) {
$this->phpci->logFailure($path);
if (!$this->phpci->executeCommand($php . ' -l "%s" 2>&1', $this->phpci->buildPath . $path)) {
$output = $this->phpci->getLastOutput();
preg_match('/Parse error:\s*syntax error,(.+?)\s+in\s+.+?\s*line\s+(\d+)/', $output, $matches);
$this->failedPaths[] = array(
'file' => $path,
'line' => trim($matches[2]),
'message' => trim($matches[1])
);
$success = false;
}

View file

@ -0,0 +1,78 @@
var lintPlugin = ActiveBuild.UiPlugin.extend({
id: 'build-lint-warnings',
css: 'col-lg-12 col-md-12 col-sm-12 col-xs-12',
title: 'PHP Lint',
lastData: null,
displayOnUpdate: false,
box: true,
rendered: false,
register: function() {
var self = this;
var query = ActiveBuild.registerQuery('phplint-data', -1, {key: 'phplint-data'})
$(window).on('phplint-data', function(data) {
self.onUpdate(data);
});
$(window).on('build-updated', function() {
if (!self.rendered) {
self.displayOnUpdate = true;
query();
}
});
},
render: function() {
return $('<table class="table table-striped" id="phplint-data">' +
'<thead>' +
'<tr>' +
' <th>File</th>' +
' <th>Line</th>' +
' <th>Message</th>' +
'</tr>' +
'</thead><tbody></tbody></table>');
},
onUpdate: function(e) {
if (!e.queryData) {
$('#build-lint-warnings').hide();
return;
}
this.rendered = true;
this.lastData = e.queryData;
var errors = this.lastData[0].meta_value;
var tbody = $('#phplint-data tbody');
tbody.empty();
if (errors.length == 0) {
$('#build-lint-warnings').hide();
return;
}
for (var i in errors) {
var file = errors[i].file;
if (ActiveBuild.fileLinkTemplate) {
var fileLink = ActiveBuild.fileLinkTemplate.replace('{FILE}', file);
fileLink = fileLink.replace('{LINE}', errors[i].line);
file = '<a target="_blank" href="'+fileLink+'">' + file + '</a>';
}
var row = $('<tr>' +
'<td>'+file+'</td>' +
'<td>'+errors[i].line+'</td>' +
'<td>'+errors[i].message+'</td></tr>');
tbody.append(row);
}
$('#build-lint-warnings').show();
}
});
ActiveBuild.registerPlugin(new lintPlugin());