From 0785ae3f4b6b58739261218be052537858931e79 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Thu, 4 Oct 2012 09:01:41 +0200 Subject: [PATCH] SONAR-2804 coverage on new code for all tests --- .../org/sonar/plugins/core/CorePlugin.java | 8 ++- .../timemachine/NewCoverageAggregator.java | 7 +- .../NewOverallCoverageFileAnalyzer.java | 66 +++++++++++++++++++ .../plugins/core/widgets/it_coverage.html.erb | 54 ++++++++------- .../views/resource/_header_coverage.html.erb | 2 +- 5 files changed, 108 insertions(+), 29 deletions(-) create mode 100644 plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index 49b7f8b8ac1..03a1f3f7804 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -48,9 +48,6 @@ import org.sonar.plugins.core.filters.ProjectFilter; import org.sonar.plugins.core.filters.TreeMapFilter; import org.sonar.plugins.core.security.ApplyProjectRolesDecorator; import org.sonar.plugins.core.security.DefaultResourcePermissions; -import org.sonar.plugins.core.sensors.OverallBranchCoverageDecorator; -import org.sonar.plugins.core.sensors.OverallCoverageDecorator; -import org.sonar.plugins.core.sensors.OverallLineCoverageDecorator; import org.sonar.plugins.core.sensors.BranchCoverageDecorator; import org.sonar.plugins.core.sensors.CheckAlertThresholds; import org.sonar.plugins.core.sensors.CommentDensityDecorator; @@ -64,6 +61,9 @@ import org.sonar.plugins.core.sensors.ItLineCoverageDecorator; import org.sonar.plugins.core.sensors.LineCoverageDecorator; import org.sonar.plugins.core.sensors.ManualMeasureDecorator; import org.sonar.plugins.core.sensors.ManualViolationInjector; +import org.sonar.plugins.core.sensors.OverallBranchCoverageDecorator; +import org.sonar.plugins.core.sensors.OverallCoverageDecorator; +import org.sonar.plugins.core.sensors.OverallLineCoverageDecorator; import org.sonar.plugins.core.sensors.ProfileEventsSensor; import org.sonar.plugins.core.sensors.ProfileSensor; import org.sonar.plugins.core.sensors.ProjectLinksSensor; @@ -80,6 +80,7 @@ import org.sonar.plugins.core.testdetailsviewer.TestsViewerDefinition; import org.sonar.plugins.core.timemachine.NewCoverageAggregator; import org.sonar.plugins.core.timemachine.NewCoverageFileAnalyzer; import org.sonar.plugins.core.timemachine.NewItCoverageFileAnalyzer; +import org.sonar.plugins.core.timemachine.NewOverallCoverageFileAnalyzer; import org.sonar.plugins.core.timemachine.NewViolationsDecorator; import org.sonar.plugins.core.timemachine.ReferenceAnalysis; import org.sonar.plugins.core.timemachine.TendencyDecorator; @@ -429,6 +430,7 @@ public final class CorePlugin extends SonarPlugin { TimeMachineConfigurationPersister.class, NewCoverageFileAnalyzer.class, NewItCoverageFileAnalyzer.class, + NewOverallCoverageFileAnalyzer.class, NewCoverageAggregator.class); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageAggregator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageAggregator.java index a0aec7935ad..beb4d016087 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageAggregator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageAggregator.java @@ -46,7 +46,8 @@ public final class NewCoverageAggregator implements Decorator { public List generatesNewCoverageMetrics() { return Arrays.asList( CoreMetrics.NEW_LINES_TO_COVER, CoreMetrics.NEW_UNCOVERED_LINES, CoreMetrics.NEW_CONDITIONS_TO_COVER, CoreMetrics.NEW_UNCOVERED_CONDITIONS, - CoreMetrics.NEW_IT_LINES_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_LINES, CoreMetrics.NEW_IT_CONDITIONS_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS); + CoreMetrics.NEW_IT_LINES_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_LINES, CoreMetrics.NEW_IT_CONDITIONS_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS, + CoreMetrics.NEW_OVERALL_LINES_TO_COVER, CoreMetrics.NEW_OVERALL_UNCOVERED_LINES, CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER, CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS); } public void decorate(Resource resource, DecoratorContext context) { @@ -60,6 +61,10 @@ public final class NewCoverageAggregator implements Decorator { aggregate(context, CoreMetrics.NEW_IT_UNCOVERED_LINES, maxPeriods); aggregate(context, CoreMetrics.NEW_IT_CONDITIONS_TO_COVER, maxPeriods); aggregate(context, CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS, maxPeriods); + aggregate(context, CoreMetrics.NEW_OVERALL_LINES_TO_COVER, maxPeriods); + aggregate(context, CoreMetrics.NEW_OVERALL_UNCOVERED_LINES, maxPeriods); + aggregate(context, CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER, maxPeriods); + aggregate(context, CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS, maxPeriods); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java new file mode 100644 index 00000000000..3808a56f1d9 --- /dev/null +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java @@ -0,0 +1,66 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.timemachine; + +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Metric; +import org.sonar.batch.components.TimeMachineConfiguration; + +public class NewOverallCoverageFileAnalyzer extends AbstractNewCoverageFileAnalyzer { + + public NewOverallCoverageFileAnalyzer(TimeMachineConfiguration timeMachineConfiguration) { + super(timeMachineConfiguration); + } + + @Override + public Metric getCoverageLineHitsDataMetric() { + return CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA; + } + + @Override + public Metric getConditionsByLineMetric() { + return CoreMetrics.OVERALL_CONDITIONS_BY_LINE; + } + + @Override + public Metric getCoveredConditionsByLineMetric() { + return CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE; + } + + @Override + public Metric getNewLinesToCoverMetric() { + return CoreMetrics.NEW_OVERALL_LINES_TO_COVER; + } + + @Override + public Metric getNewUncoveredLinesMetric() { + return CoreMetrics.NEW_OVERALL_UNCOVERED_LINES; + } + + @Override + public Metric getNewConditionsToCoverMetric() { + return CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER; + } + + @Override + public Metric getNewUncoveredConditionsMetric() { + return CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS; + } +} diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/it_coverage.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/it_coverage.html.erb index e21eb58dbe0..86add802fd0 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/it_coverage.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/it_coverage.html.erb @@ -31,6 +31,36 @@ <% end %> + <% end -%> + <% if overall_coverage -%> + +
+

<%= message('widget.overall-coverage.name') -%>

+ +

+ <%= format_measure(overall_coverage, :suffix => '', :url => url_for_drilldown('overall_coverage'), :default => '-') %> + <%= dashboard_configuration.selected_period? ? format_variation(overall_coverage) : trend_icon(overall_coverage) -%> +

+ <% it_line_coverage=measure('overall_line_coverage') + if it_line_coverage %> +

+ <%= format_measure(it_line_coverage, :suffix => message('widget.overall-coverage.line_coverage.suffix'), :url => url_for_drilldown('overall_uncovered_lines', :highlight => 'overall_line_coverage')) %> + <%= dashboard_configuration.selected_period? ? format_variation(it_line_coverage) : trend_icon(it_line_coverage) -%> +

+ <% end %> + <% it_branch_coverage=measure('overall_branch_coverage') + if it_branch_coverage %> +

+ <%= format_measure(it_branch_coverage, :suffix => message('widget.overall-coverage.branch_coverage.suffix'), :url => url_for_drilldown('overall_uncovered_conditions', :highlight => 'overall_branch_coverage')) %> + <%= dashboard_configuration.selected_period? ? format_variation(it_branch_coverage) : trend_icon(it_branch_coverage) -%> +

+ <% end %> +
+ + <% end -%> + + + <% if it_coverage -%>
<% @@ -75,30 +105,6 @@ <% end -%> <% if overall_coverage -%> - -
-

<%= message('widget.overall-coverage.name') -%>

- -

- <%= format_measure(overall_coverage, :suffix => '', :url => url_for_drilldown('overall_coverage'), :default => '-') %> - <%= dashboard_configuration.selected_period? ? format_variation(overall_coverage) : trend_icon(overall_coverage) -%> -

- <% it_line_coverage=measure('overall_line_coverage') - if it_line_coverage %> -

- <%= format_measure(it_line_coverage, :suffix => message('widget.overall-coverage.line_coverage.suffix'), :url => url_for_drilldown('overall_uncovered_lines', :highlight => 'overall_line_coverage')) %> - <%= dashboard_configuration.selected_period? ? format_variation(it_line_coverage) : trend_icon(it_line_coverage) -%> -

- <% end %> - <% it_branch_coverage=measure('overall_branch_coverage') - if it_branch_coverage %> -

- <%= format_measure(it_branch_coverage, :suffix => message('widget.overall-coverage.branch_coverage.suffix'), :url => url_for_drilldown('overall_uncovered_conditions', :highlight => 'overall_branch_coverage')) %> - <%= dashboard_configuration.selected_period? ? format_variation(it_branch_coverage) : trend_icon(it_branch_coverage) -%> -

- <% end %> -
-
<% diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_header_coverage.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_header_coverage.html.erb index f4614113556..594a9002a88 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_header_coverage.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_header_coverage.html.erb @@ -1,5 +1,5 @@
- <% if @period && (measure('new_coverage') || measure('new_it_coverage')|| measure('new_overall_coverage')) %> + <% if @period && (measure('new_coverage') || measure('new_it_coverage') || measure('new_overall_coverage')) %>

<%= message('coverage_viewer.on_new_code') -%> :

-- 2.39.5