This commit is contained in:
OxGroup 2016-08-30 16:41:30 +00:00 committed by GitHub
commit aa4e394aef
6 changed files with 142 additions and 12 deletions

View file

@ -167,6 +167,7 @@ PHPCI',
'chart_display' => 'This chart will display once the build has completed.', 'chart_display' => 'This chart will display once the build has completed.',
'structure' => 'Structure',
'build' => 'Build', 'build' => 'Build',
'lines' => 'Lines', 'lines' => 'Lines',
'comment_lines' => 'Comment Lines', 'comment_lines' => 'Comment Lines',

View file

@ -158,6 +158,7 @@ PHPCI',
'chart_display' => 'Этот график будет показан после окончания сборки.', 'chart_display' => 'Этот график будет показан после окончания сборки.',
'structure' => 'Структура',
'build' => 'Сборка', 'build' => 'Сборка',
'lines' => 'Строк', 'lines' => 'Строк',
'comment_lines' => 'Строк комментариев', 'comment_lines' => 'Строк комментариев',

View file

@ -15,6 +15,7 @@ use PHPCI\Model\Build;
/** /**
* PHP Loc - Allows PHP Copy / Lines of Code testing. * PHP Loc - Allows PHP Copy / Lines of Code testing.
*
* @author Johan van der Heide <info@japaveh.nl> * @author Johan van der Heide <info@japaveh.nl>
* @package PHPCI * @package PHPCI
* @subpackage Plugins * @subpackage Plugins
@ -30,11 +31,18 @@ class PhpLoc implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
*/ */
protected $phpci; protected $phpci;
/**
* @var Build
*/
protected $build;
/** /**
* Check if this plugin can be executed. * Check if this plugin can be executed.
* @param $stage *
* @param $stage
* @param Builder $builder * @param Builder $builder
* @param Build $build * @param Build $build
*
* @return bool * @return bool
*/ */
public static function canExecute($stage, Builder $builder, Build $build) public static function canExecute($stage, Builder $builder, Build $build)
@ -48,14 +56,15 @@ class PhpLoc implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
/** /**
* Set up the plugin, configure options, etc. * Set up the plugin, configure options, etc.
*
* @param Builder $phpci * @param Builder $phpci
* @param Build $build * @param Build $build
* @param array $options * @param array $options
*/ */
public function __construct(Builder $phpci, Build $build, array $options = array()) public function __construct(Builder $phpci, Build $build, array $options = array())
{ {
$this->phpci = $phpci; $this->phpci = $phpci;
$this->build = $build; $this->build = $build;
$this->directory = $phpci->buildPath; $this->directory = $phpci->buildPath;
if (isset($options['directory'])) { if (isset($options['directory'])) {
@ -82,17 +91,30 @@ class PhpLoc implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
$phploc = $this->phpci->findBinary('phploc'); $phploc = $this->phpci->findBinary('phploc');
$success = $this->phpci->executeCommand($phploc . ' %s "%s"', $ignore, $this->directory); $success = $this->phpci->executeCommand($phploc . ' %s "%s"', $ignore, $this->directory);
$output = $this->phpci->getLastOutput(); $output = $this->phpci->getLastOutput();
if (preg_match_all('/\((LOC|CLOC|NCLOC|LLOC)\)\s+([0-9]+)/', $output, $matches)) { if (preg_match_all('/\((LOC|CLOC|NCLOC|LLOC)\)\s+([0-9]+)/', $output, $matches2)) {
$data = array(); $data = array();
foreach ($matches[1] as $k => $v) { foreach ($matches2[1] as $k => $v) {
$data[$v] = (int)$matches[2][$k]; $data[$v] = (int) $matches2[2][$k];
} }
$this->build->storeMeta('phploc', $data); $this->build->storeMeta('phploc', $data);
} }
if (preg_match_all('/(Namespaces|Interfaces|Classes|Methods)\s+([0-9]+)/', $output, $matches)) {
$key = $matches[1];
$val = $matches[2];
$data = array(
$key[1] => (int) $val[1],
$key[2] => (int) $val[2],
$key[3] => (int) $val[3],
$key[6] => (int) $val[6],
);
$this->build->storeMeta('phploc-structure', $data);
}
return $success; return $success;
} }
} }

View file

@ -1,6 +1,6 @@
var locPlugin = ActiveBuild.UiPlugin.extend({ var locPlugin = ActiveBuild.UiPlugin.extend({
id: 'build-lines-chart', id: 'build-lines-chart',
css: 'col-xs-12', css: 'col-xs-6',
title: Lang.get('lines_of_code'), title: Lang.get('lines_of_code'),
lastData: null, lastData: null,
displayOnUpdate: false, displayOnUpdate: false,

View file

@ -0,0 +1,106 @@
var locPlugin2 = ActiveBuild.UiPlugin.extend({
id: 'build-lines-chart-structure',
css: 'col-xs-6',
title: Lang.get('structure'),
lastData: null,
displayOnUpdate: false,
rendered: false,
chartData: null,
register: function() {
var self = this;
var query = ActiveBuild.registerQuery('phploc-structure', -1, {num_builds: 10, key: 'phploc-structure'})
$(window).on('phploc-structure', function(data) {
self.onUpdate(data);
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1 && !self.rendered) {
query();
}
});
},
render: function() {
var self = this;
var container = $('<div id="phploc-structure" style="width: 100%; height: 300px"></div>');
container.append('<canvas id="phploc-structure-chart" style="width: 100%; height: 300px"></canvas>');
$(document).on('shown.bs.tab', function () {
$('#build-lines-chart-structure').hide();
self.drawChart();
});
return container;
},
onUpdate: function(e) {
this.lastData = e.queryData;
this.displayChart();
},
displayChart: function() {
var self = this;
var builds = this.lastData;
self.rendered = true;
self.chartData = {
labels: [],
datasets: [
{
label: "Namespaces",
strokeColor: "rgba(60,141,188,1)",
pointColor: "rgba(60,141,188,1)",
data: []
},
{
label: "Interfaces",
strokeColor: "rgba(245,105,84,1)",
pointColor: "rgba(245,105,84,1)",
data: []
},
{
label: "Classes",
strokeColor: "rgba(0,166,90,1)",
pointColor: "rgba(0,166,90,1)",
data: []
},
{
label: "Methods",
strokeColor: "rgba(0,192,239,1)",
pointColor: "rgba(0,192,239,1)",
data: []
}
]
};
for (var i in builds) {
self.chartData.labels.push('Build ' + builds[i].build_id);
self.chartData.datasets[0].data.push(builds[i].meta_value.Namespaces);
self.chartData.datasets[1].data.push(builds[i].meta_value.Interfaces);
self.chartData.datasets[2].data.push(builds[i].meta_value.Classes);
self.chartData.datasets[3].data.push(builds[i].meta_value.Methods);
}
self.drawChart();
},
drawChart: function () {
var self = this;
if ($('#information').hasClass('active') && self.chartData && self.lastData) {
$('#build-lines-chart-structure').show();
var ctx = $("#phploc-structure-chart").get(0).getContext("2d");
var phpLocChart = new Chart(ctx);
phpLocChart.Line(self.chartData, {
datasetFill: false,
multiTooltipTemplate: "<%=datasetLabel%>: <%= value %>"
});
}
}
});
ActiveBuild.registerPlugin(new locPlugin2());

View file

@ -1,6 +1,6 @@
var SummaryPlugin = ActiveBuild.UiPlugin.extend({ var SummaryPlugin = ActiveBuild.UiPlugin.extend({
id: 'build-summary', id: 'build-summary',
css: 'col-xs-12', css: 'col-xs-6',
title: Lang.get('build-summary'), title: Lang.get('build-summary'),
box: true, box: true,
statusIcons: [ 'fa-clock-o', 'fa-cogs', 'fa-check', 'fa-remove' ], statusIcons: [ 'fa-clock-o', 'fa-cogs', 'fa-check', 'fa-remove' ],