]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2804 coverage on new code for all tests
authorDavid Gageot <david@gageot.net>
Thu, 4 Oct 2012 07:01:41 +0000 (09:01 +0200)
committerDavid Gageot <david@gageot.net>
Thu, 4 Oct 2012 07:01:41 +0000 (09:01 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageAggregator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/it_coverage.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_header_coverage.html.erb

index 49b7f8b8ac15bb72079f40ff840eb665ecceb2f2..03a1f3f780418d7f8d0cd326b623b279caddcbae 100644 (file)
@@ -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);
   }
 }
index a0aec7935ad64b282498b9ded412e3f5b0fe23b8..beb4d01608700757de8bcf68b745c5e6f640e277 100644 (file)
@@ -46,7 +46,8 @@ public final class NewCoverageAggregator implements Decorator {
   public List<Metric> 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 (file)
index 0000000..3808a56
--- /dev/null
@@ -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;
+  }
+}
index e21eb58dbe06337c71a446485464d34dfc8d4cf7..86add802fd037f6b5fd637d48b02fca18a4524e3 100644 (file)
             <% end %>
           </div>
         </td>
+      <% end -%>
+      <% if overall_coverage -%>
+        <td nowrap valign="top">
+          <div class="dashbox">
+            <p class="title"><%= message('widget.overall-coverage.name') -%></p>
+
+            <p>
+              <span class="big"><%= format_measure(overall_coverage, :suffix => '', :url => url_for_drilldown('overall_coverage'), :default => '-') %></span>
+              <%= dashboard_configuration.selected_period? ? format_variation(overall_coverage) : trend_icon(overall_coverage) -%>
+            </p>
+            <% it_line_coverage=measure('overall_line_coverage')
+               if it_line_coverage %>
+              <p>
+                <%= 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) -%>
+              </p>
+            <% end %>
+            <% it_branch_coverage=measure('overall_branch_coverage')
+               if it_branch_coverage %>
+              <p>
+                <%= 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) -%>
+              </p>
+            <% end %>
+          </div>
+        </td>
+      <% end -%>
+    </tr>
+    <tr>
+      <% if it_coverage -%>
         <td nowrap valign="top">
           <div class="dashbox">
             <%
         </td>
       <% end -%>
       <% if overall_coverage -%>
-        <td nowrap valign="top">
-          <div class="dashbox">
-            <p class="title"><%= message('widget.overall-coverage.name') -%></p>
-
-            <p>
-              <span class="big"><%= format_measure(overall_coverage, :suffix => '', :url => url_for_drilldown('overall_coverage'), :default => '-') %></span>
-              <%= dashboard_configuration.selected_period? ? format_variation(overall_coverage) : trend_icon(overall_coverage) -%>
-            </p>
-            <% it_line_coverage=measure('overall_line_coverage')
-               if it_line_coverage %>
-              <p>
-                <%= 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) -%>
-              </p>
-            <% end %>
-            <% it_branch_coverage=measure('overall_branch_coverage')
-               if it_branch_coverage %>
-              <p>
-                <%= 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) -%>
-              </p>
-            <% end %>
-          </div>
-        </td>
         <td nowrap valign="top">
           <div class="dashbox">
             <%
index f461411355657af2c6f230cbfc0b468fb908e8f7..594a9002a885a510aa82ceb89b7caf5047c06837 100644 (file)
@@ -1,5 +1,5 @@
 <div id="coverage_header" class="tab_header">
-  <% 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')) %>
     <p><%= message('coverage_viewer.on_new_code') -%> :</p>
     <table>
       <tr>