Merge pull request #460 from REBELinBLUE/master
Adding a build status JS plugin for PHPCPD
This commit is contained in:
commit
e578523f81
|
@ -54,7 +54,7 @@ class PhpCpd implements \PHPCI\Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($options['ignore'])) {
|
if (!empty($options['ignore'])) {
|
||||||
$this->ignore = $this->phpci->ignore;
|
$this->ignore = $options['ignore'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,10 +88,50 @@ class PhpCpd implements \PHPCI\Plugin
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = $this->phpci->executeCommand($phpcpd . ' %s "%s"', $ignore, $this->path);
|
$tmpfilename = tempnam('/tmp', 'phpcpd');
|
||||||
|
|
||||||
|
$success = $this->phpci->executeCommand($phpcpd . ' --log-pmd="%s" %s "%s"', $tmpfilename, $ignore, $this->path);
|
||||||
|
|
||||||
print $this->phpci->getLastOutput();
|
print $this->phpci->getLastOutput();
|
||||||
|
|
||||||
|
list($errorCount, $data) = $this->processReport(file_get_contents($tmpfilename));
|
||||||
|
$this->build->storeMeta('phpcpd-warnings', $errorCount);
|
||||||
|
$this->build->storeMeta('phpcpd-data', $data);
|
||||||
|
|
||||||
|
unlink($tmpfilename);
|
||||||
|
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function processReport($xmlString)
|
||||||
|
{
|
||||||
|
$xml = simplexml_load_string($xmlString);
|
||||||
|
|
||||||
|
if ($xml === false) {
|
||||||
|
$this->phpci->log($xmlString);
|
||||||
|
throw new \Exception('Could not process PHPCPD report XML.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$warnings = 0;
|
||||||
|
$data = array();
|
||||||
|
|
||||||
|
foreach ($xml->duplication as $duplication) {
|
||||||
|
foreach ($duplication->file as $file) {
|
||||||
|
$fileName = (string)$file['path'];
|
||||||
|
$fileName = str_replace($this->phpci->buildPath, '', $fileName);
|
||||||
|
|
||||||
|
$data[] = array(
|
||||||
|
'file' => $fileName,
|
||||||
|
'line_start' => (int) $file['line'],
|
||||||
|
'line_end' => (int) $file['line'] + (int) $duplication['lines'],
|
||||||
|
'code' => (string) $duplication->codefragment
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$warnings++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array($warnings, $data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
81
public/assets/js/build-plugins/phpcpd.js
Normal file
81
public/assets/js/build-plugins/phpcpd.js
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
var phpcpdPlugin = PHPCI.UiPlugin.extend({
|
||||||
|
id: 'build-phpcpd',
|
||||||
|
css: 'col-lg-12 col-md-12 col-sm-12 col-xs-12',
|
||||||
|
title: 'PHP Copy/Paste Detector',
|
||||||
|
lastData: null,
|
||||||
|
box: true,
|
||||||
|
rendered: false,
|
||||||
|
|
||||||
|
register: function() {
|
||||||
|
var self = this;
|
||||||
|
var query = PHPCI.registerQuery('phpcpd-data', -1, {key: 'phpcpd-data'})
|
||||||
|
|
||||||
|
$(window).on('phpcpd-data', function(data) {
|
||||||
|
self.onUpdate(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).on('build-updated', function() {
|
||||||
|
if (!self.rendered) {
|
||||||
|
query();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
render: function() {
|
||||||
|
|
||||||
|
return $('<table class="table table-striped" id="phpcpd-data">' +
|
||||||
|
'<thead>' +
|
||||||
|
'<tr>' +
|
||||||
|
' <th>File</th>' +
|
||||||
|
' <th>Start</th>' +
|
||||||
|
' <th>End</th>' +
|
||||||
|
'</tr>' +
|
||||||
|
'</thead><tbody></tbody></table>');
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
onUpdate: function(e) {
|
||||||
|
if (!e.queryData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rendered = true;
|
||||||
|
this.lastData = e.queryData;
|
||||||
|
|
||||||
|
var errors = this.lastData[0].meta_value;
|
||||||
|
var tbody = $('#phpcpd-data tbody');
|
||||||
|
tbody.empty();
|
||||||
|
|
||||||
|
var rowClass = 'danger';
|
||||||
|
for (var i in errors) {
|
||||||
|
var file = errors[i].file;
|
||||||
|
|
||||||
|
if (PHPCI.fileLinkTemplate) {
|
||||||
|
var fileLink = PHPCI.fileLinkTemplate.replace('{FILE}', file);
|
||||||
|
fileLink = fileLink.replace('{LINE}', errors[i].line_start);
|
||||||
|
|
||||||
|
file = '<a target="_blank" href="'+fileLink+'">' + file + '</a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
var label = 'From';
|
||||||
|
|
||||||
|
if (i % 2 > 0) {
|
||||||
|
label = 'To';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rowClass = (rowClass == 'warning' ? 'danger' : 'warning');
|
||||||
|
}
|
||||||
|
|
||||||
|
var row = $('<tr>' +
|
||||||
|
'<td><strong>' + label + '</strong>: '+file+'</td>' +
|
||||||
|
'<td>'+errors[i].line_start+'</td>' +
|
||||||
|
'<td>'+errors[i].line_end+'</td></tr>');
|
||||||
|
|
||||||
|
row.addClass(rowClass);
|
||||||
|
|
||||||
|
tbody.append(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
PHPCI.registerPlugin(new phpcpdPlugin());
|
Loading…
Reference in a new issue