diff --git a/PHPCI/Languages/lang.en.php b/PHPCI/Languages/lang.en.php index 63df75d2..fcd4a5bc 100644 --- a/PHPCI/Languages/lang.en.php +++ b/PHPCI/Languages/lang.en.php @@ -167,6 +167,7 @@ PHPCI', 'chart_display' => 'This chart will display once the build has completed.', + 'structure' => 'Structure', 'build' => 'Build', 'lines' => 'Lines', 'comment_lines' => 'Comment Lines', diff --git a/PHPCI/Languages/lang.ru.php b/PHPCI/Languages/lang.ru.php index 0a7acff2..33268971 100644 --- a/PHPCI/Languages/lang.ru.php +++ b/PHPCI/Languages/lang.ru.php @@ -158,6 +158,7 @@ PHPCI', 'chart_display' => 'Этот график будет показан после окончания сборки.', + 'structure' => 'Структура', 'build' => 'Сборка', 'lines' => 'Строк', 'comment_lines' => 'Строк комментариев', diff --git a/PHPCI/Plugin/PhpLoc.php b/PHPCI/Plugin/PhpLoc.php index c8dedb91..e7d03057 100644 --- a/PHPCI/Plugin/PhpLoc.php +++ b/PHPCI/Plugin/PhpLoc.php @@ -15,6 +15,7 @@ use PHPCI\Model\Build; /** * PHP Loc - Allows PHP Copy / Lines of Code testing. + * * @author Johan van der Heide * @package PHPCI * @subpackage Plugins @@ -30,11 +31,18 @@ class PhpLoc implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin */ protected $phpci; + /** + * @var Build + */ + protected $build; + /** * Check if this plugin can be executed. - * @param $stage + * + * @param $stage * @param Builder $builder - * @param Build $build + * @param Build $build + * * @return bool */ 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. + * * @param Builder $phpci - * @param Build $build - * @param array $options + * @param Build $build + * @param array $options */ public function __construct(Builder $phpci, Build $build, array $options = array()) { - $this->phpci = $phpci; - $this->build = $build; + $this->phpci = $phpci; + $this->build = $build; $this->directory = $phpci->buildPath; if (isset($options['directory'])) { @@ -82,17 +91,30 @@ class PhpLoc implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin $phploc = $this->phpci->findBinary('phploc'); $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(); - foreach ($matches[1] as $k => $v) { - $data[$v] = (int)$matches[2][$k]; + foreach ($matches2[1] as $k => $v) { + $data[$v] = (int) $matches2[2][$k]; } $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; } } diff --git a/public/assets/js/build-plugins/loc.js b/public/assets/js/build-plugins/loc.js index 89e703b8..406853c0 100644 --- a/public/assets/js/build-plugins/loc.js +++ b/public/assets/js/build-plugins/loc.js @@ -1,6 +1,6 @@ var locPlugin = ActiveBuild.UiPlugin.extend({ id: 'build-lines-chart', - css: 'col-xs-12', + css: 'col-xs-6', title: Lang.get('lines_of_code'), lastData: null, displayOnUpdate: false, diff --git a/public/assets/js/build-plugins/loc2.js b/public/assets/js/build-plugins/loc2.js new file mode 100644 index 00000000..12c07c01 --- /dev/null +++ b/public/assets/js/build-plugins/loc2.js @@ -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 = $('
'); + container.append(''); + + $(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()); diff --git a/public/assets/js/build-plugins/summary.js b/public/assets/js/build-plugins/summary.js index 7ccea67b..9e9736cf 100644 --- a/public/assets/js/build-plugins/summary.js +++ b/public/assets/js/build-plugins/summary.js @@ -1,6 +1,6 @@ var SummaryPlugin = ActiveBuild.UiPlugin.extend({ id: 'build-summary', - css: 'col-xs-12', + css: 'col-xs-6', title: Lang.get('build-summary'), box: true, statusIcons: [ 'fa-clock-o', 'fa-cogs', 'fa-check', 'fa-remove' ],