From: David Gageot Date: Wed, 3 Oct 2012 14:32:10 +0000 (+0200) Subject: SONAR-2804 changes based on feedback X-Git-Tag: 3.3~127 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e835d2c8469ed045b262849b3816054625cf16c2;p=sonarqube.git SONAR-2804 changes based on feedback --- diff --git a/HelloWorld.class b/HelloWorld.class new file mode 100644 index 00000000000..e9d34004571 Binary files /dev/null and b/HelloWorld.class differ 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 7dacd86b642..49b7f8b8ac1 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,9 @@ 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.AllTestsBranchCoverageDecorator; -import org.sonar.plugins.core.sensors.AllTestsCoverageDecorator; -import org.sonar.plugins.core.sensors.AllTestsLineCoverageDecorator; +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; @@ -89,7 +89,6 @@ import org.sonar.plugins.core.timemachine.ViolationPersisterDecorator; import org.sonar.plugins.core.timemachine.ViolationTrackingDecorator; import org.sonar.plugins.core.web.Lcom4Viewer; import org.sonar.plugins.core.widgets.AlertsWidget; -import org.sonar.plugins.core.widgets.AllTestsCoverageWidget; import org.sonar.plugins.core.widgets.CommentsDuplicationsWidget; import org.sonar.plugins.core.widgets.ComplexityWidget; import org.sonar.plugins.core.widgets.CoverageWidget; @@ -345,7 +344,6 @@ public final class CorePlugin extends SonarPlugin { AlertsWidget.class, CoverageWidget.class, ItCoverageWidget.class, - AllTestsCoverageWidget.class, CommentsDuplicationsWidget.class, DescriptionWidget.class, ComplexityWidget.class, @@ -403,9 +401,9 @@ public final class CorePlugin extends SonarPlugin { ItLineCoverageDecorator.class, ItCoverageDecorator.class, ItBranchCoverageDecorator.class, - AllTestsLineCoverageDecorator.class, - AllTestsCoverageDecorator.class, - AllTestsBranchCoverageDecorator.class, + OverallLineCoverageDecorator.class, + OverallCoverageDecorator.class, + OverallBranchCoverageDecorator.class, DefaultResourcePermissions.class, ApplyProjectRolesDecorator.class, ExcludedResourceFilter.class, diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsBranchCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsBranchCoverageDecorator.java deleted file mode 100644 index bdc66eae8df..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsBranchCoverageDecorator.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.sensors; - -import com.google.common.collect.ImmutableList; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.MeasureUtils; -import org.sonar.api.measures.Metric; - -import java.util.List; - -public final class AllTestsBranchCoverageDecorator extends AbstractCoverageDecorator { - @DependsUpon - public List dependsUponMetrics() { - return ImmutableList.of(CoreMetrics.MERGED_UNCOVERED_CONDITIONS, CoreMetrics.MERGED_CONDITIONS_TO_COVER, - CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS, CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER); - } - - @Override - protected Metric getGeneratedMetric() { - return CoreMetrics.MERGED_BRANCH_COVERAGE; - } - - @Override - protected Long countElements(DecoratorContext context) { - return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER), 0L); - } - - @Override - protected long countCoveredElements(DecoratorContext context) { - long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS), 0L); - long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER), 0L); - - return conditions - uncoveredConditions; - } - - @Override - protected Metric getGeneratedMetricForNewCode() { - return CoreMetrics.NEW_MERGED_BRANCH_COVERAGE; - } - - @Override - protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) { - return MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex); - } - - @Override - protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) { - long uncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS), periodIndex, 0L); - long conditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L); - - return conditions - uncoveredConditions; - } -} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecorator.java deleted file mode 100644 index 5cd791570c8..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecorator.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.sensors; - -import com.google.common.collect.ImmutableList; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.MeasureUtils; -import org.sonar.api.measures.Metric; - -import java.util.Collection; - -public final class AllTestsCoverageDecorator extends AbstractCoverageDecorator { - @DependsUpon - public Collection usedMetrics() { - return ImmutableList.of(CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.NEW_MERGED_LINES_TO_COVER, - CoreMetrics.NEW_MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_CONDITIONS_TO_COVER, CoreMetrics.MERGED_UNCOVERED_CONDITIONS, - CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS); - } - - @Override - protected Metric getGeneratedMetric() { - return CoreMetrics.MERGED_COVERAGE; - } - - @Override - protected Long countElements(DecoratorContext context) { - long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L); - long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER), 0L); - - return lines + conditions; - } - - @Override - protected long countCoveredElements(DecoratorContext context) { - long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_LINES), 0L); - long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L); - long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS), 0L); - long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER), 0L); - - return lines + conditions - uncoveredConditions - uncoveredLines; - } - - @Override - protected Metric getGeneratedMetricForNewCode() { - return CoreMetrics.NEW_MERGED_COVERAGE; - } - - @Override - protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) { - Long newLinesToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_LINES_TO_COVER), periodIndex); - if (newLinesToCover == null) { - return null; - } - - long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L); - - return newLinesToCover + newConditionsToCover; - } - - @Override - protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) { - long newLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_LINES_TO_COVER), periodIndex, 0L); - long newUncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_LINES), periodIndex, 0L); - long newUncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS), periodIndex, 0L); - long newConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L); - - return newLines + newConditions - newUncoveredConditions - newUncoveredLines; - } -} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecorator.java deleted file mode 100644 index e815cdc3244..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecorator.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.sensors; - -import com.google.common.collect.ImmutableList; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.MeasureUtils; -import org.sonar.api.measures.Metric; - -import java.util.List; - -public final class AllTestsLineCoverageDecorator extends AbstractCoverageDecorator { - @DependsUpon - public List dependsUponMetrics() { - return ImmutableList.of(CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_LINES, - CoreMetrics.NEW_MERGED_LINES_TO_COVER); - } - - @Override - protected Metric getGeneratedMetric() { - return CoreMetrics.MERGED_LINE_COVERAGE; - } - - @Override - protected Long countElements(DecoratorContext context) { - return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L); - } - - @Override - protected long countCoveredElements(DecoratorContext context) { - long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_LINES), 0L); - long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L); - - return lines - uncoveredLines; - } - - @Override - protected Metric getGeneratedMetricForNewCode() { - return CoreMetrics.NEW_MERGED_LINE_COVERAGE; - } - - @Override - protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) { - return MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_LINES_TO_COVER), periodIndex); - } - - @Override - protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) { - long uncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_LINES), periodIndex, 0L); - long lines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_LINES_TO_COVER), periodIndex, 0L); - - return lines - uncoveredLines; - } -} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecorator.java new file mode 100644 index 00000000000..c9e459b937d --- /dev/null +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecorator.java @@ -0,0 +1,73 @@ +/* + * 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.sensors; + +import com.google.common.collect.ImmutableList; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.batch.DependsUpon; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.MeasureUtils; +import org.sonar.api.measures.Metric; + +import java.util.List; + +public final class OverallBranchCoverageDecorator extends AbstractCoverageDecorator { + @DependsUpon + public List dependsUponMetrics() { + return ImmutableList.of(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, CoreMetrics.OVERALL_CONDITIONS_TO_COVER, + CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS, CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER); + } + + @Override + protected Metric getGeneratedMetric() { + return CoreMetrics.OVERALL_BRANCH_COVERAGE; + } + + @Override + protected Long countElements(DecoratorContext context) { + return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER), 0L); + } + + @Override + protected long countCoveredElements(DecoratorContext context) { + long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS), 0L); + long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER), 0L); + + return conditions - uncoveredConditions; + } + + @Override + protected Metric getGeneratedMetricForNewCode() { + return CoreMetrics.NEW_OVERALL_BRANCH_COVERAGE; + } + + @Override + protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) { + return MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER), periodIndex); + } + + @Override + protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) { + long uncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS), periodIndex, 0L); + long conditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER), periodIndex, 0L); + + return conditions - uncoveredConditions; + } +} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallCoverageDecorator.java new file mode 100644 index 00000000000..70c74386d42 --- /dev/null +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallCoverageDecorator.java @@ -0,0 +1,88 @@ +/* + * 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.sensors; + +import com.google.common.collect.ImmutableList; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.batch.DependsUpon; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.MeasureUtils; +import org.sonar.api.measures.Metric; + +import java.util.Collection; + +public final class OverallCoverageDecorator extends AbstractCoverageDecorator { + @DependsUpon + public Collection usedMetrics() { + return ImmutableList.of(CoreMetrics.OVERALL_LINES_TO_COVER, CoreMetrics.OVERALL_UNCOVERED_LINES, CoreMetrics.NEW_OVERALL_LINES_TO_COVER, + CoreMetrics.NEW_OVERALL_UNCOVERED_LINES, CoreMetrics.OVERALL_CONDITIONS_TO_COVER, CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, + CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER, CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS); + } + + @Override + protected Metric getGeneratedMetric() { + return CoreMetrics.OVERALL_COVERAGE; + } + + @Override + protected Long countElements(DecoratorContext context) { + long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER), 0L); + long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER), 0L); + + return lines + conditions; + } + + @Override + protected long countCoveredElements(DecoratorContext context) { + long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_LINES), 0L); + long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER), 0L); + long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS), 0L); + long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER), 0L); + + return lines + conditions - uncoveredConditions - uncoveredLines; + } + + @Override + protected Metric getGeneratedMetricForNewCode() { + return CoreMetrics.NEW_OVERALL_COVERAGE; + } + + @Override + protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) { + Long newLinesToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_LINES_TO_COVER), periodIndex); + if (newLinesToCover == null) { + return null; + } + + long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER), periodIndex, 0L); + + return newLinesToCover + newConditionsToCover; + } + + @Override + protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) { + long newLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_LINES_TO_COVER), periodIndex, 0L); + long newUncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_UNCOVERED_LINES), periodIndex, 0L); + long newUncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS), periodIndex, 0L); + long newConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER), periodIndex, 0L); + + return newLines + newConditions - newUncoveredConditions - newUncoveredLines; + } +} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecorator.java new file mode 100644 index 00000000000..ccf73faa3f5 --- /dev/null +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecorator.java @@ -0,0 +1,73 @@ +/* + * 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.sensors; + +import com.google.common.collect.ImmutableList; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.batch.DependsUpon; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.MeasureUtils; +import org.sonar.api.measures.Metric; + +import java.util.List; + +public final class OverallLineCoverageDecorator extends AbstractCoverageDecorator { + @DependsUpon + public List dependsUponMetrics() { + return ImmutableList.of(CoreMetrics.OVERALL_UNCOVERED_LINES, CoreMetrics.OVERALL_LINES_TO_COVER, CoreMetrics.NEW_OVERALL_UNCOVERED_LINES, + CoreMetrics.NEW_OVERALL_LINES_TO_COVER); + } + + @Override + protected Metric getGeneratedMetric() { + return CoreMetrics.OVERALL_LINE_COVERAGE; + } + + @Override + protected Long countElements(DecoratorContext context) { + return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER), 0L); + } + + @Override + protected long countCoveredElements(DecoratorContext context) { + long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_LINES), 0L); + long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER), 0L); + + return lines - uncoveredLines; + } + + @Override + protected Metric getGeneratedMetricForNewCode() { + return CoreMetrics.NEW_OVERALL_LINE_COVERAGE; + } + + @Override + protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) { + return MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_LINES_TO_COVER), periodIndex); + } + + @Override + protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) { + long uncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_UNCOVERED_LINES), periodIndex, 0L); + long lines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_OVERALL_LINES_TO_COVER), periodIndex, 0L); + + return lines - uncoveredLines; + } +} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidget.java deleted file mode 100644 index 619352fd3fa..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidget.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.widgets; - -import org.sonar.api.web.AbstractRubyTemplate; -import org.sonar.api.web.RubyRailsWidget; -import org.sonar.api.web.UserRole; -import org.sonar.api.web.WidgetCategory; - -@WidgetCategory("Tests") -@UserRole(UserRole.USER) -public class AllTestsCoverageWidget extends AbstractRubyTemplate implements RubyRailsWidget { - public String getId() { - return "merged-coverage"; - } - - public String getTitle() { - return "All Tests Coverage"; - } - - @Override - protected String getTemplatePath() { - return "/org/sonar/plugins/core/widgets/merged_coverage.html.erb"; - } -} diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 563a2c217a0..94175a42bc5 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -709,7 +709,7 @@ widget.alerts.description=Display current alerts on the project. widget.alerts.no_alert=No alerts widget.alerts.alerts=Alerts -widget.code_coverage.name=Code coverage +widget.code_coverage.name=Unit tests coverage widget.code_coverage.description=Reports on units tests and code coverage by unit tests. widget.code_coverage.line_coverage.suffix=\ line coverage widget.code_coverage.branch_coverage.suffix=\ branch coverage @@ -722,7 +722,7 @@ widget.code_coverage.tests.suffix=\ tests widget.code_coverage.skipped.suffix=\ skipped # id of this widget does not use underscore in order to be backward-compatible with previous version of JaCoCo plugin -widget.it-coverage.name=Integration test coverage +widget.it-coverage.name=Integration tests coverage widget.it-coverage.description=Reports on code coverage by integration tests widget.it-coverage.line_coverage.suffix=\ line coverage widget.it-coverage.branch_coverage.suffix=\ branch coverage @@ -731,13 +731,13 @@ widget.it-coverage.on_new_code=On new code widget.it-coverage.no_new_lines_to_cover=No new lines to cover # id of this widget does not use underscore in order to be backward-compatible with previous version of JaCoCo plugin -widget.merged-coverage.name=All tests coverage -widget.merged-coverage.description=Reports on code coverage by all tests -widget.merged-coverage.line_coverage.suffix=\ line coverage -widget.merged-coverage.branch_coverage.suffix=\ branch coverage -widget.merged-coverage.lines_to_cover.suffix=\ lines to cover -widget.merged-coverage.on_new_code=On new code -widget.merged-coverage.no_new_lines_to_cover=No new lines to cover +widget.overall-coverage.name=Overall coverage +widget.overall-coverage.description=Reports on code coverage by all tests +widget.overall-coverage.line_coverage.suffix=\ line coverage +widget.overall-coverage.branch_coverage.suffix=\ branch coverage +widget.overall-coverage.lines_to_cover.suffix=\ lines to cover +widget.overall-coverage.on_new_code=On new code +widget.overall-coverage.no_new_lines_to_cover=No new lines to cover widget.comments_duplications.name=Comments & Duplications widget.comments_duplications.description=Reports on copy/paste and documentation @@ -969,9 +969,11 @@ duplications.collapse=Collapse # #------------------------------------------------------------------------------ coverage_viewer.on_new_code=On new code +coverage_viewer.by.unit_tests=By UTs coverage_viewer.unit_tests=Unit Tests +coverage_viewer.by.integration_tests=By ITs coverage_viewer.integration_tests=Integration Tests -coverage_viewer.all_tests=All Tests +coverage_viewer.overall_tests=All Tests #------------------------------------------------------------------------------ @@ -1555,16 +1557,16 @@ metric.tests.description=Number of unit tests metric.test_execution_time.name=Unit tests duration metric.test_execution_time.description=Execution duration of unit tests -metric.test_errors.name=Unit test errors +metric.test_errors.name=Unit tests errors metric.test_errors.description=Number of unit test errors metric.skipped_tests.name=Skipped unit tests metric.skipped_tests.description=Number of skipped unit tests -metric.test_failures.name=Unit test failures +metric.test_failures.name=Unit tests failures metric.test_failures.description=Number of unit test failures -metric.test_success_density.name=Unit test success (%) +metric.test_success_density.name=Unit tests success (%) metric.test_success_density.description=Density of successful unit tests metric.test_data.name=Unit tests details @@ -1631,56 +1633,113 @@ metric.covered_conditions_by_line.description=Covered branches by line # #-------------------------------------------------------------------------------------------------------------------- -metric.it_coverage.name=IT Coverage -metric.it_coverage.description=Integration Test Coverage +metric.it_coverage.name=IT coverage +metric.it_coverage.description=Integration tests coverage -metric.it_lines_to_cover.name=IT Lines to Cover -metric.it_lines_to_cover.description=Lines to cover by Integration Tests +metric.it_lines_to_cover.name=IT lines to cover +metric.it_lines_to_cover.description=Lines to cover by integration tests -metric.it_uncovered_lines.name=IT Uncovered Lines -metric.it_uncovered_lines.description=Uncovered lines by Integration Tests +metric.it_uncovered_lines.name=IT uncovered lines +metric.it_uncovered_lines.description=Uncovered lines by integration tests -metric.it_line_coverage.name=IT Line Coverage -metric.it_line_coverage.description=Line coverage by Integration Tests +metric.it_line_coverage.name=IT line coverage +metric.it_line_coverage.description=Line coverage by integration tests -metric.it_coverage_line_hits_data.name=IT Coverage hits by line -metric.it_coverage_line_hits_data.description=Coverage hits by line by Integration Tests +metric.it_coverage_line_hits_data.name=IT coverage hits by line +metric.it_coverage_line_hits_data.description=Coverage hits by line by integration tests -metric.it_conditions_to_cover.name=IT Branches to Cover -metric.it_conditions_to_cover.description=Branches to cover by Integration Tests +metric.it_conditions_to_cover.name=IT branches to cover +metric.it_conditions_to_cover.description=Branches to cover by integration tests -metric.it_uncovered_conditions.name=IT Uncovered Branches -metric.it_uncovered_conditions.description=Uncovered branches by Integration Tests +metric.it_uncovered_conditions.name=IT uncovered branches +metric.it_uncovered_conditions.description=Uncovered branches by integration tests -metric.it_branch_coverage.name=IT Branch Coverage -metric.it_branch_coverage.description=Branch coverage by Integration Tests +metric.it_branch_coverage.name=IT branch coverage +metric.it_branch_coverage.description=Branch coverage by integration tests -metric.it_conditions_by_line.name=IT Branches by Line -metric.it_conditions_by_line.description=IT Branches by line +metric.it_conditions_by_line.name=IT branches by line +metric.it_conditions_by_line.description=IT branches by line -metric.it_covered_conditions_by_line.name=IT Covered Branches by Line -metric.it_covered_conditions_by_line.description=IT Covered branches by line +metric.it_covered_conditions_by_line.name=IT covered branches by line +metric.it_covered_conditions_by_line.description=IT covered branches by line -metric.new_it_coverage.name=New IT Coverage -metric.new_it_coverage.description=Integration Test Coverage of new/changed code +metric.new_it_coverage.name=New IT coverage +metric.new_it_coverage.description=Integration tests coverage of new/changed code -metric.new_it_lines_to_cover.name=New Lines to Cover by IT +metric.new_it_lines_to_cover.name=New lines to cover by IT metric.new_it_lines_to_cover.description=New lines to cover by integration tests -metric.new_it_uncovered_lines.name=New Lines Uncovered by IT +metric.new_it_uncovered_lines.name=New lines uncovered by IT metric.new_it_uncovered_lines.description=New lines that are not covered by integration tests -metric.new_it_line_coverage.name=New IT Line Coverage -metric.new_it_line_coverage.description=Integration Test Line coverage of added/changed code +metric.new_it_line_coverage.name=New IT line coverage +metric.new_it_line_coverage.description=Integration tests line coverage of added/changed code -metric.new_it_conditions_to_cover.name=New Branches to Cover by IT +metric.new_it_conditions_to_cover.name=New branches to cover by IT metric.new_it_conditions_to_cover.description=New branches to cover by integration tests -metric.new_it_uncovered_conditions.name=New Branches Uncovered by IT -metric.new_it_uncovered_conditions.description=New branches that are not covered by IT +metric.new_it_uncovered_conditions.name=New branches uncovered by IT +metric.new_it_uncovered_conditions.description=New branches that are not covered by integration tests -metric.new_it_branch_coverage.name=New IT Branch Coverage -metric.new_it_branch_coverage.description=Integration Test Branch Coverage of new/changed code +metric.new_it_branch_coverage.name=New IT branch coverage +metric.new_it_branch_coverage.description=Integration tests branch coverage of new/changed code + +#-------------------------------------------------------------------------------------------------------------------- +# +# OVERALL TESTS +# +#-------------------------------------------------------------------------------------------------------------------- + +metric.overall_coverage.name=Overall coverage +metric.overall_coverage.description=Overall test coverage + +metric.overall_lines_to_cover.name=Overall lines to cover +metric.overall_lines_to_cover.description=Lines to cover by all tests + +metric.overall_uncovered_lines.name=Overall uncovered lines +metric.overall_uncovered_lines.description=Uncovered lines by all tests + +metric.overall_line_coverage.name=Overall line coverage +metric.overall_line_coverage.description=Line coverage by all tests + +metric.overall_coverage_line_hits_data.name=Overall coverage hits by line +metric.overall_coverage_line_hits_data.description=Coverage hits by all tests and by line + +metric.overall_conditions_to_cover.name=Overall branches to cover +metric.overall_conditions_to_cover.description=Branches to cover by all tests + +metric.overall_uncovered_conditions.name=Overall uncovered branches +metric.overall_uncovered_conditions.description=Uncovered branches by all tests + +metric.overall_branch_coverage.name=Overall branch coverage +metric.overall_branch_coverage.description=Branch coverage by all tests + +metric.overall_conditions_by_line.name=Overall branches by line +metric.overall_conditions_by_line.description=Overall branches by all tests and by line + +metric.overall_covered_conditions_by_line.name=Overall covered branches by line +metric.overall_covered_conditions_by_line.description=Overall covered branches by all tests and by line + +metric.new_overall_coverage.name=Overall new coverage +metric.new_overall_coverage.description=Overall coverage of new/changed code + +metric.new_overall_lines_to_cover.name=Overall new lines to cover +metric.new_overall_lines_to_cover.description=New lines to cover by all tests + +metric.new_overall_uncovered_lines.name=Overall new lines uncovered +metric.new_overall_uncovered_lines.description=New lines that are not covered by any tests + +metric.new_overall_line_coverage.name=Overall new line coverage +metric.new_overall_line_coverage.description=Line coverage of added/changed code by all tests + +metric.new_overall_conditions_to_cover.name=Overall new branches to cover +metric.new_overall_conditions_to_cover.description=New branches to cover by all tests + +metric.new_overall_uncovered_conditions.name=Overall new branches uncovered +metric.new_overall_uncovered_conditions.description=New branches that are not covered by any test + +metric.new_overall_branch_coverage.name=Overall new branch coverage +metric.new_overall_branch_coverage.description=Branch coverage of new/changed code by all tests #-------------------------------------------------------------------------------------------------------------------- # 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 f039205bc53..e21eb58dbe0 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 @@ -1,76 +1,147 @@ <% - coverage_measure=measure('it_coverage') - if coverage_measure -%> - - - - + + <% end -%> + +
-
-

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

-

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

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

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

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

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

- <% end %> -
-
-
- <% - if dashboard_configuration.selected_period? - new_lines_to_cover_measure=measure('new_it_lines_to_cover') - if new_lines_to_cover_measure - new_lines=new_lines_to_cover_measure.variation(dashboard_configuration.period_index) - if new_lines - new_coverage=measure('new_it_coverage') - new_line_coverage=measure('new_it_line_coverage') - new_branch_coverage=measure('new_it_branch_coverage') - %> -

<%= message('widget.it-coverage.on_new_code') -%>:

- <% if new_lines.to_i==0 %> -

<%= message('widget.it-coverage.no_new_lines_to_cover') -%>

- <% else %> - <% if new_coverage %> -

+ it_coverage=measure('it_coverage') + overall_coverage=measure('overall_coverage') + + if it_coverage || overall_coverage +-%> + + + <% if it_coverage -%> + + + <% end -%> + <% if overall_coverage -%> + - -
+
+

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

+ +

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

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

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

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

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

+ <% end %> +
+
+
+ <% + if dashboard_configuration.selected_period? + new_lines_to_cover_measure=measure('new_it_lines_to_cover') + if new_lines_to_cover_measure + new_lines=new_lines_to_cover_measure.variation(dashboard_configuration.period_index) + if new_lines + new_coverage=measure('new_it_coverage') + new_line_coverage=measure('new_it_line_coverage') + new_branch_coverage=measure('new_it_branch_coverage') + %> +

<%= message('widget.it-coverage.on_new_code') -%>:

+ <% if new_lines.to_i==0 %> +

<%= message('widget.it-coverage.no_new_lines_to_cover') -%>

+ <% else %> + <% if new_coverage %> +

<%= format_variation(new_coverage, :style => 'none', :default => '-') -%> -

- <% end %> +

+ <% end %> +

+ <%= format_variation(new_lines_to_cover_measure, :style => 'none', :default => '-') -%><%= message('widget.it-coverage.lines_to_cover.suffix') -%> +

+ <% if new_line_coverage %> +

+ <%= format_variation(new_line_coverage, :style => 'none', :default => '-') -%><%= message('widget.it-coverage.line_coverage.suffix') -%> +

+ <% end %> + <% if new_branch_coverage %> +

+ <%= format_variation(new_branch_coverage, :style => 'none', :default => '-') -%><%= message('widget.it-coverage.branch_coverage.suffix') -%> +

+ <% end -%> + <% end -%> + <% end -%> + <% end -%> + <% end -%> +
+
+
+

<%= 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_variation(new_lines_to_cover_measure, :style => 'none', :default => '-') -%><%= message('widget.it-coverage.lines_to_cover.suffix') -%> + <%= 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) -%>

- <% if new_line_coverage %> -

- <%= format_variation(new_line_coverage, :style => 'none', :default => '-') -%><%= message('widget.it-coverage.line_coverage.suffix') -%> -

- <% end %> - <% if new_branch_coverage %> -

- <%= format_variation(new_branch_coverage, :style => 'none', :default => '-') -%><%= message('widget.it-coverage.branch_coverage.suffix') -%> -

- <% - end - end - end - end - end - %> -
-
+ <% 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 %> +
+
+
+ <% + if dashboard_configuration.selected_period? + new_lines_to_cover_measure=measure('new_overall_lines_to_cover') + if new_lines_to_cover_measure + new_lines=new_lines_to_cover_measure.variation(dashboard_configuration.period_index) + if new_lines + new_coverage=measure('new_overall_coverage') + new_line_coverage=measure('new_overall_line_coverage') + new_branch_coverage=measure('new_overall_branch_coverage') + %> +

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

+ <% if new_lines.to_i==0 %> +

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

+ <% else %> + <% if new_coverage %> +

+ + <%= format_variation(new_coverage, :style => 'none', :default => '-') -%> + +

+ <% end %> +

+ <%= format_variation(new_lines_to_cover_measure, :style => 'none', :default => '-') -%><%= message('widget.merged-coverage.lines_to_cover.suffix') -%> +

+ <% if new_line_coverage %> +

+ <%= format_variation(new_line_coverage, :style => 'none', :default => '-') -%><%= message('widget.merged-coverage.line_coverage.suffix') -%> +

+ <% end %> + <% if new_branch_coverage %> +

+ <%= format_variation(new_branch_coverage, :style => 'none', :default => '-') -%><%= message('widget.merged-coverage.branch_coverage.suffix') -%> +

+ <% end -%> + <% end -%> + <% end -%> + <% end -%> + <% end -%> +
+
<% end %> diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/merged_coverage.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/merged_coverage.html.erb deleted file mode 100644 index 8fae498e7ff..00000000000 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/merged_coverage.html.erb +++ /dev/null @@ -1,76 +0,0 @@ -<% - coverage_measure=measure('merged_coverage') - if coverage_measure -%> - - - - - -
-
-

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

-

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

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

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

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

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

- <% end %> -
-
-
- <% - if dashboard_configuration.selected_period? - new_lines_to_cover_measure=measure('new_merged_lines_to_cover') - if new_lines_to_cover_measure - new_lines=new_lines_to_cover_measure.variation(dashboard_configuration.period_index) - if new_lines - new_coverage=measure('new_merged_coverage') - new_line_coverage=measure('new_merged_line_coverage') - new_branch_coverage=measure('new_merged_branch_coverage') - %> -

<%= message('widget.merged-coverage.on_new_code') -%>:

- <% if new_lines.to_i==0 %> -

<%= message('widget.merged-coverage.no_new_lines_to_cover') -%>

- <% else %> - <% if new_coverage %> -

- - <%= format_variation(new_coverage, :style => 'none', :default => '-') -%> - -

- <% end %> -

- <%= format_variation(new_lines_to_cover_measure, :style => 'none', :default => '-') -%><%= message('widget.merged-coverage.lines_to_cover.suffix') -%> -

- <% if new_line_coverage %> -

- <%= format_variation(new_line_coverage, :style => 'none', :default => '-') -%><%= message('widget.merged-coverage.line_coverage.suffix') -%> -

- <% end %> - <% if new_branch_coverage %> -

- <%= format_variation(new_branch_coverage, :style => 'none', :default => '-') -%><%= message('widget.merged-coverage.branch_coverage.suffix') -%> -

- <% - end - end - end - end - end - %> -
-
-<% end %> diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsBranchCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsBranchCoverageDecoratorTest.java deleted file mode 100644 index 58f79a7ad4a..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsBranchCoverageDecoratorTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.sensors; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.Scopes; - -import static org.mockito.Matchers.anyDouble; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class AllTestsBranchCoverageDecoratorTest { - private final AllTestsBranchCoverageDecorator decorator = new AllTestsBranchCoverageDecorator(); - private final Project resource = mock(Project.class); - - @Before - public void setUp() { - when(resource.getScope()).thenReturn(Scopes.PROJECT); - when(resource.getQualifier()).thenReturn(Qualifiers.PROJECT); - } - - @Test - public void shouldSaveBranchCoverage() { - DecoratorContext context = mockContext(20, 15); - - decorator.decorate(resource, context); - - verify(context).saveMeasure(CoreMetrics.MERGED_BRANCH_COVERAGE, 25.0); - } - - @Test - public void shouldNotSaveBranchCoverageIfMissingConditions() { - DecoratorContext context = mock(DecoratorContext.class); - - decorator.decorate(resource, context); - - verify(context, never()).saveMeasure(eq(CoreMetrics.MERGED_BRANCH_COVERAGE), anyDouble()); - } - - private static DecoratorContext mockContext(int conditions, int uncoveredConditions) { - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.MERGED_CONDITIONS_TO_COVER, (double) conditions)); - when(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS, (double) uncoveredConditions)); - return context; - } -} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecoratorTest.java deleted file mode 100644 index b5c4ef15c8a..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecoratorTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.sensors; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Scopes; - -import java.util.Collection; - -import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Matchers.anyDouble; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class AllTestsCoverageDecoratorTest { - private final AllTestsCoverageDecorator decorator = new AllTestsCoverageDecorator(); - private final Project project = mock(Project.class); - - @Before - public void before() { - when(project.getScope()).thenReturn(Scopes.PROJECT); - } - - @Test - public void should_use_metrics() { - Collection metrics = decorator.usedMetrics(); - - assertThat(metrics).containsOnly(CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.NEW_MERGED_LINES_TO_COVER, - CoreMetrics.NEW_MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_CONDITIONS_TO_COVER, CoreMetrics.MERGED_UNCOVERED_CONDITIONS, - CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS); - } - - @Test - public void noCoverageWhenStaticAnalysis() { - when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC); - assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isFalse(); - - when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS); - assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isTrue(); - - when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC); - assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isTrue(); - } - - @Test - public void coverage() { - DecoratorContext context = mockContext(50, 40, 10, 8); - - decorator.decorate(project, context); - - // (50-40 covered lines + 10-8 covered conditions) / (50 lines + 10 conditions) - verify(context).saveMeasure(CoreMetrics.MERGED_COVERAGE, 20.0); - } - - @Test - public void coverageCanBe0() { - DecoratorContext context = mockContext(50, 50, 5, 5); - - decorator.decorate(project, context); - - verify(context).saveMeasure(CoreMetrics.MERGED_COVERAGE, 0.0); - } - - @Test - public void coverageCanBe100() { - DecoratorContext context = mockContext(50, 0, 5, 0); - - decorator.decorate(project, context); - - verify(context).saveMeasure(CoreMetrics.MERGED_COVERAGE, 100.0); - } - - @Test - public void noCoverageIfNoElements() { - DecoratorContext context = mock(DecoratorContext.class); - - decorator.decorate(project, context); - - verify(context, never()).saveMeasure(eq(CoreMetrics.MERGED_COVERAGE), anyDouble()); - } - - private static DecoratorContext mockContext(int lines, int uncoveredLines, int conditions, int uncoveredConditions) { - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.MERGED_LINES_TO_COVER, (double) lines)); - when(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.MERGED_UNCOVERED_LINES, (double) uncoveredLines)); - when(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.MERGED_CONDITIONS_TO_COVER, (double) conditions)); - when(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS, (double) uncoveredConditions)); - return context; - } -} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecoratorTest.java deleted file mode 100644 index d9eb3f67744..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecoratorTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.sensors; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Scopes; - -import java.util.List; - -import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Mockito.anyDouble; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class AllTestsLineCoverageDecoratorTest { - private final AllTestsLineCoverageDecorator decorator = new AllTestsLineCoverageDecorator(); - private final Project project = mock(Project.class); - - @Before - public void before() { - when(project.getScope()).thenReturn(Scopes.PROJECT); - } - - @Test - public void should_depend_on_coverage_metrics() { - List metrics = decorator.dependsUponMetrics(); - - assertThat(metrics).containsOnly(CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_LINES, - CoreMetrics.NEW_MERGED_LINES_TO_COVER); - } - - @Test - public void noCoverageWhenStaticAnalysis() { - when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC); - assertThat(decorator.shouldExecuteOnProject(project)).isFalse(); - - when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS); - assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); - - when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC); - assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); - } - - @Test - public void lineCoverage() { - DecoratorContext context = mockContext(50, 10); - - decorator.decorate(project, context); - - // 50-10 covered lines / 50 lines - verify(context).saveMeasure(CoreMetrics.MERGED_LINE_COVERAGE, 80.0); - } - - @Test - public void zeroCoveredLines() { - DecoratorContext context = mockContext(50, 50); - - decorator.decorate(project, context); - - verify(context).saveMeasure(CoreMetrics.MERGED_LINE_COVERAGE, 0.0); - } - - @Test - public void allCoveredLines() { - DecoratorContext context = mockContext(50, 00); - - decorator.decorate(project, context); - - verify(context).saveMeasure(CoreMetrics.MERGED_LINE_COVERAGE, 100.0); - } - - @Test - public void noLineCoverageIfNoLines() { - DecoratorContext context = mock(DecoratorContext.class); - - decorator.decorate(project, context); - - verify(context, never()).saveMeasure(eq(CoreMetrics.MERGED_LINE_COVERAGE), anyDouble()); - } - - private static DecoratorContext mockContext(int lines, int uncoveredLines) { - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.MERGED_LINES_TO_COVER, (double) lines)); - when(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.MERGED_UNCOVERED_LINES, (double) uncoveredLines)); - return context; - } -} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecoratorTest.java new file mode 100644 index 00000000000..3d139a17779 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallBranchCoverageDecoratorTest.java @@ -0,0 +1,72 @@ +/* + * 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.sensors; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.resources.Scopes; + +import static org.mockito.Matchers.anyDouble; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class OverallBranchCoverageDecoratorTest { + private final OverallBranchCoverageDecorator decorator = new OverallBranchCoverageDecorator(); + private final Project resource = mock(Project.class); + + @Before + public void setUp() { + when(resource.getScope()).thenReturn(Scopes.PROJECT); + when(resource.getQualifier()).thenReturn(Qualifiers.PROJECT); + } + + @Test + public void shouldSaveBranchCoverage() { + DecoratorContext context = mockContext(20, 15); + + decorator.decorate(resource, context); + + verify(context).saveMeasure(CoreMetrics.OVERALL_BRANCH_COVERAGE, 25.0); + } + + @Test + public void shouldNotSaveBranchCoverageIfMissingConditions() { + DecoratorContext context = mock(DecoratorContext.class); + + decorator.decorate(resource, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.OVERALL_BRANCH_COVERAGE), anyDouble()); + } + + private static DecoratorContext mockContext(int conditions, int uncoveredConditions) { + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER, (double) conditions)); + when(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, (double) uncoveredConditions)); + return context; + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java new file mode 100644 index 00000000000..7ec96574cee --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java @@ -0,0 +1,116 @@ +/* + * 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.sensors; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.measures.Metric; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Scopes; + +import java.util.Collection; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Matchers.anyDouble; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class OverallCoverageDecoratorTest { + private final OverallCoverageDecorator decorator = new OverallCoverageDecorator(); + private final Project project = mock(Project.class); + + @Before + public void before() { + when(project.getScope()).thenReturn(Scopes.PROJECT); + } + + @Test + public void should_use_metrics() { + Collection metrics = decorator.usedMetrics(); + + assertThat(metrics).containsOnly(CoreMetrics.OVERALL_LINES_TO_COVER, CoreMetrics.OVERALL_UNCOVERED_LINES, CoreMetrics.NEW_OVERALL_LINES_TO_COVER, + CoreMetrics.NEW_OVERALL_UNCOVERED_LINES, CoreMetrics.OVERALL_CONDITIONS_TO_COVER, CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, + CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER, CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS); + } + + @Test + public void noCoverageWhenStaticAnalysis() { + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC); + assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isFalse(); + + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS); + assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isTrue(); + + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC); + assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isTrue(); + } + + @Test + public void coverage() { + DecoratorContext context = mockContext(50, 40, 10, 8); + + decorator.decorate(project, context); + + // (50-40 covered lines + 10-8 covered conditions) / (50 lines + 10 conditions) + verify(context).saveMeasure(CoreMetrics.OVERALL_COVERAGE, 20.0); + } + + @Test + public void coverageCanBe0() { + DecoratorContext context = mockContext(50, 50, 5, 5); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.OVERALL_COVERAGE, 0.0); + } + + @Test + public void coverageCanBe100() { + DecoratorContext context = mockContext(50, 0, 5, 0); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.OVERALL_COVERAGE, 100.0); + } + + @Test + public void noCoverageIfNoElements() { + DecoratorContext context = mock(DecoratorContext.class); + + decorator.decorate(project, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.OVERALL_COVERAGE), anyDouble()); + } + + private static DecoratorContext mockContext(int lines, int uncoveredLines, int conditions, int uncoveredConditions) { + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.OVERALL_LINES_TO_COVER, (double) lines)); + when(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.OVERALL_UNCOVERED_LINES, (double) uncoveredLines)); + when(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER, (double) conditions)); + when(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, (double) uncoveredConditions)); + return context; + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecoratorTest.java new file mode 100644 index 00000000000..2fa58ac2e97 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallLineCoverageDecoratorTest.java @@ -0,0 +1,113 @@ +/* + * 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.sensors; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.measures.Metric; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Scopes; + +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.anyDouble; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class OverallLineCoverageDecoratorTest { + private final OverallLineCoverageDecorator decorator = new OverallLineCoverageDecorator(); + private final Project project = mock(Project.class); + + @Before + public void before() { + when(project.getScope()).thenReturn(Scopes.PROJECT); + } + + @Test + public void should_depend_on_coverage_metrics() { + List metrics = decorator.dependsUponMetrics(); + + assertThat(metrics).containsOnly(CoreMetrics.OVERALL_UNCOVERED_LINES, CoreMetrics.OVERALL_LINES_TO_COVER, CoreMetrics.NEW_OVERALL_UNCOVERED_LINES, + CoreMetrics.NEW_OVERALL_LINES_TO_COVER); + } + + @Test + public void noCoverageWhenStaticAnalysis() { + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC); + assertThat(decorator.shouldExecuteOnProject(project)).isFalse(); + + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS); + assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); + + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC); + assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); + } + + @Test + public void lineCoverage() { + DecoratorContext context = mockContext(50, 10); + + decorator.decorate(project, context); + + // 50-10 covered lines / 50 lines + verify(context).saveMeasure(CoreMetrics.OVERALL_LINE_COVERAGE, 80.0); + } + + @Test + public void zeroCoveredLines() { + DecoratorContext context = mockContext(50, 50); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.OVERALL_LINE_COVERAGE, 0.0); + } + + @Test + public void allCoveredLines() { + DecoratorContext context = mockContext(50, 00); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.OVERALL_LINE_COVERAGE, 100.0); + } + + @Test + public void noLineCoverageIfNoLines() { + DecoratorContext context = mock(DecoratorContext.class); + + decorator.decorate(project, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.OVERALL_LINE_COVERAGE), anyDouble()); + } + + private static DecoratorContext mockContext(int lines, int uncoveredLines) { + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.OVERALL_LINES_TO_COVER, (double) lines)); + when(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.OVERALL_UNCOVERED_LINES, (double) uncoveredLines)); + return context; + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidgetTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidgetTest.java deleted file mode 100644 index fc472d38cc5..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidgetTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.widgets; - -import org.junit.Test; - -import static org.fest.assertions.Assertions.assertThat; - -public class AllTestsCoverageWidgetTest { - @Test - public void should_define_widget() { - AllTestsCoverageWidget widget = new AllTestsCoverageWidget(); - - assertThat(widget.getId()).isEqualTo("merged-coverage"); - assertThat(widget.getTitle()).isEqualTo("All Tests Coverage"); - } - - @Test - public void should_use_relative_path_for_template() { - AllTestsCoverageWidget widget = new AllTestsCoverageWidget(); - - assertThat(widget.getTemplatePath()).startsWith("/"); - } -} diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoAllTestsSensor.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoAllTestsSensor.java deleted file mode 100644 index 79a24239cb4..00000000000 --- a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoAllTestsSensor.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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.jacoco; - -import com.google.common.io.Closeables; -import org.apache.commons.lang.StringUtils; -import org.jacoco.core.data.ExecutionDataReader; -import org.jacoco.core.data.ExecutionDataStore; -import org.jacoco.core.data.ExecutionDataWriter; -import org.jacoco.core.data.SessionInfoStore; -import org.sonar.api.batch.Sensor; -import org.sonar.api.batch.SensorContext; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.resources.JavaFile; -import org.sonar.api.resources.Project; -import org.sonar.api.utils.SonarException; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collection; - -public class JaCoCoAllTestsSensor implements Sensor { - private static final String MERGED_EXEC = "target/sonar/merged.exec"; - - private final JacocoConfiguration configuration; - - public JaCoCoAllTestsSensor(JacocoConfiguration configuration) { - this.configuration = configuration; - } - - public boolean shouldExecuteOnProject(Project project) { - return StringUtils.isNotBlank(configuration.getItReportPath()) - && project.getAnalysisType().isDynamic(true); - } - - public void analyse(Project project, SensorContext context) { - mergeReports(project); - - new AllTestsAnalyzer().analyse(project, context); - } - - private void mergeReports(Project project) { - File reportUTs = project.getFileSystem().resolvePath(configuration.getReportPath()); - File reportITs = project.getFileSystem().resolvePath(configuration.getItReportPath()); - File reportAllTests = project.getFileSystem().resolvePath(MERGED_EXEC); - reportAllTests.getParentFile().mkdirs(); - - SessionInfoStore infoStore = new SessionInfoStore(); - ExecutionDataStore dataStore = new ExecutionDataStore(); - - loadSourceFiles(infoStore, dataStore, reportUTs, reportITs); - - BufferedOutputStream outputStream = null; - try { - outputStream = new BufferedOutputStream(new FileOutputStream(reportAllTests)); - ExecutionDataWriter dataWriter = new ExecutionDataWriter(outputStream); - - infoStore.accept(dataWriter); - dataStore.accept(dataWriter); - } catch (IOException e) { - throw new SonarException(String.format("Unable to write merged file %s", reportAllTests.getAbsolutePath()), e); - } finally { - Closeables.closeQuietly(outputStream); - } - } - - private void loadSourceFiles(SessionInfoStore infoStore, ExecutionDataStore dataStore, File... files) { - for (File file : files) { - InputStream resourceStream = null; - try { - resourceStream = new BufferedInputStream(new FileInputStream(file)); - ExecutionDataReader reader = new ExecutionDataReader(resourceStream); - reader.setSessionInfoVisitor(infoStore); - reader.setExecutionDataVisitor(dataStore); - reader.read(); - } catch (IOException e) { - throw new SonarException(String.format("Unable to read %s", file.getAbsolutePath()), e); - } finally { - Closeables.closeQuietly(resourceStream); - } - } - } - - class AllTestsAnalyzer extends AbstractAnalyzer { - @Override - protected String getReportPath(Project project) { - return MERGED_EXEC; - } - - @Override - protected String getExcludes(Project project) { - return configuration.getExcludes(); - } - - @Override - protected void saveMeasures(SensorContext context, JavaFile resource, Collection measures) { - for (Measure measure : measures) { - Measure mergedMeasure = convertForAllTests(measure); - if (mergedMeasure != null) { - context.saveMeasure(resource, mergedMeasure); - } - } - } - - private Measure convertForAllTests(Measure measure) { - if (CoreMetrics.LINES_TO_COVER.equals(measure.getMetric())) { - return new Measure(CoreMetrics.MERGED_LINES_TO_COVER, measure.getValue()); - } else if (CoreMetrics.UNCOVERED_LINES.equals(measure.getMetric())) { - return new Measure(CoreMetrics.MERGED_UNCOVERED_LINES, measure.getValue()); - } else if (CoreMetrics.COVERAGE_LINE_HITS_DATA.equals(measure.getMetric())) { - return new Measure(CoreMetrics.MERGED_COVERAGE_LINE_HITS_DATA, measure.getData()); - } else if (CoreMetrics.CONDITIONS_TO_COVER.equals(measure.getMetric())) { - return new Measure(CoreMetrics.MERGED_CONDITIONS_TO_COVER, measure.getValue()); - } else if (CoreMetrics.UNCOVERED_CONDITIONS.equals(measure.getMetric())) { - return new Measure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS, measure.getValue()); - } else if (CoreMetrics.COVERED_CONDITIONS_BY_LINE.equals(measure.getMetric())) { - return new Measure(CoreMetrics.MERGED_COVERED_CONDITIONS_BY_LINE, measure.getData()); - } else if (CoreMetrics.CONDITIONS_BY_LINE.equals(measure.getMetric())) { - return new Measure(CoreMetrics.MERGED_CONDITIONS_BY_LINE, measure.getData()); - } - return null; - } - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoOverallSensor.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoOverallSensor.java new file mode 100644 index 00000000000..8ce1aa6e51e --- /dev/null +++ b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoOverallSensor.java @@ -0,0 +1,152 @@ +/* + * 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.jacoco; + +import com.google.common.io.Closeables; +import org.apache.commons.lang.StringUtils; +import org.jacoco.core.data.ExecutionDataReader; +import org.jacoco.core.data.ExecutionDataStore; +import org.jacoco.core.data.ExecutionDataWriter; +import org.jacoco.core.data.SessionInfoStore; +import org.sonar.api.batch.Sensor; +import org.sonar.api.batch.SensorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.resources.JavaFile; +import org.sonar.api.resources.Project; +import org.sonar.api.utils.SonarException; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; + +public class JaCoCoOverallSensor implements Sensor { + private static final String JACOCO_OVERALL = "target/sonar/jacoco-overall.exec"; + + private final JacocoConfiguration configuration; + + public JaCoCoOverallSensor(JacocoConfiguration configuration) { + this.configuration = configuration; + } + + public boolean shouldExecuteOnProject(Project project) { + return StringUtils.isNotBlank(configuration.getItReportPath()) + && project.getAnalysisType().isDynamic(true); + } + + public void analyse(Project project, SensorContext context) { + mergeReports(project); + + new OverallAnalyzer().analyse(project, context); + } + + private void mergeReports(Project project) { + File reportUTs = project.getFileSystem().resolvePath(configuration.getReportPath()); + File reportITs = project.getFileSystem().resolvePath(configuration.getItReportPath()); + File reportOverall = project.getFileSystem().resolvePath(JACOCO_OVERALL); + reportOverall.getParentFile().mkdirs(); + + SessionInfoStore infoStore = new SessionInfoStore(); + ExecutionDataStore dataStore = new ExecutionDataStore(); + + loadSourceFiles(infoStore, dataStore, reportUTs, reportITs); + + BufferedOutputStream outputStream = null; + try { + outputStream = new BufferedOutputStream(new FileOutputStream(reportOverall)); + ExecutionDataWriter dataWriter = new ExecutionDataWriter(outputStream); + + infoStore.accept(dataWriter); + dataStore.accept(dataWriter); + } catch (IOException e) { + throw new SonarException(String.format("Unable to write overall coverage report %s", reportOverall.getAbsolutePath()), e); + } finally { + Closeables.closeQuietly(outputStream); + } + } + + private void loadSourceFiles(SessionInfoStore infoStore, ExecutionDataStore dataStore, File... files) { + for (File file : files) { + InputStream resourceStream = null; + try { + resourceStream = new BufferedInputStream(new FileInputStream(file)); + ExecutionDataReader reader = new ExecutionDataReader(resourceStream); + reader.setSessionInfoVisitor(infoStore); + reader.setExecutionDataVisitor(dataStore); + reader.read(); + } catch (IOException e) { + throw new SonarException(String.format("Unable to read %s", file.getAbsolutePath()), e); + } finally { + Closeables.closeQuietly(resourceStream); + } + } + } + + class OverallAnalyzer extends AbstractAnalyzer { + @Override + protected String getReportPath(Project project) { + return JACOCO_OVERALL; + } + + @Override + protected String getExcludes(Project project) { + return configuration.getExcludes(); + } + + @Override + protected void saveMeasures(SensorContext context, JavaFile resource, Collection measures) { + for (Measure measure : measures) { + Measure mergedMeasure = convertForAllTests(measure); + if (mergedMeasure != null) { + context.saveMeasure(resource, mergedMeasure); + } + } + } + + private Measure convertForAllTests(Measure measure) { + if (CoreMetrics.LINES_TO_COVER.equals(measure.getMetric())) { + return new Measure(CoreMetrics.OVERALL_LINES_TO_COVER, measure.getValue()); + } else if (CoreMetrics.UNCOVERED_LINES.equals(measure.getMetric())) { + return new Measure(CoreMetrics.OVERALL_UNCOVERED_LINES, measure.getValue()); + } else if (CoreMetrics.COVERAGE_LINE_HITS_DATA.equals(measure.getMetric())) { + return new Measure(CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA, measure.getData()); + } else if (CoreMetrics.CONDITIONS_TO_COVER.equals(measure.getMetric())) { + return new Measure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER, measure.getValue()); + } else if (CoreMetrics.UNCOVERED_CONDITIONS.equals(measure.getMetric())) { + return new Measure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, measure.getValue()); + } else if (CoreMetrics.COVERED_CONDITIONS_BY_LINE.equals(measure.getMetric())) { + return new Measure(CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE, measure.getData()); + } else if (CoreMetrics.CONDITIONS_BY_LINE.equals(measure.getMetric())) { + return new Measure(CoreMetrics.OVERALL_CONDITIONS_BY_LINE, measure.getData()); + } + return null; + } + } + + @Override + public String toString() { + return getClass().getSimpleName(); + } +} diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoPlugin.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoPlugin.java index 9a6a2016982..d6150513661 100644 --- a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoPlugin.java +++ b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoPlugin.java @@ -40,6 +40,6 @@ public class JaCoCoPlugin extends SonarPlugin { JaCoCoSensor.class, // Integration tests JaCoCoItSensor.class, - JaCoCoAllTestsSensor.class); + JaCoCoOverallSensor.class); } } diff --git a/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoAllTestsSensorTest.java b/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoAllTestsSensorTest.java deleted file mode 100644 index bc318e66b6f..00000000000 --- a/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoAllTestsSensorTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.jacoco; - -import com.google.common.io.Files; -import org.junit.Test; -import org.sonar.api.batch.SensorContext; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.resources.JavaFile; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.ProjectFileSystem; -import org.sonar.api.resources.Resource; -import org.sonar.test.TestUtils; - -import java.io.File; -import java.io.IOException; - -import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -public class JaCoCoAllTestsSensorTest { - private final JacocoConfiguration configuration= mock(JacocoConfiguration.class); - private final SensorContext context = mock(SensorContext.class); - private final ProjectFileSystem pfs = mock(ProjectFileSystem.class); - private final Project project = mock(Project.class); - private final JaCoCoAllTestsSensor sensor = new JaCoCoAllTestsSensor(configuration); - - @Test - public void should_execute_on_project() { - Project project = mock(Project.class); - when(configuration.getItReportPath()).thenReturn("target/it-jacoco.exec"); - when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC).thenReturn(Project.AnalysisType.REUSE_REPORTS); - - assertThat(sensor.shouldExecuteOnProject(project)).isTrue(); - } - - @Test - public void do_not_execute_when_report_path_not_specified() { - Project project = mock(Project.class); - when(configuration.getItReportPath()).thenReturn(""); - - assertThat(sensor.shouldExecuteOnProject(project)).isFalse(); - } - - @Test - public void should_save_measures() throws IOException { - File outputDir = TestUtils.getResource(JaCoCoAllTestsSensorTest.class, "."); - Files.copy(TestUtils.getResource("HelloWorld.class.toCopy"), new File(outputDir, "HelloWorld.class")); - - JavaFile resource = new JavaFile("com.sonar.coverages.HelloWorld"); - - when(project.getFileSystem()).thenReturn(pfs); - when(context.getResource(any(Resource.class))).thenReturn(resource); - when(configuration.getReportPath()).thenReturn("ut.exec"); - when(configuration.getItReportPath()).thenReturn("it.exec"); - when(pfs.getBuildOutputDir()).thenReturn(outputDir); - when(pfs.resolvePath("ut.exec")).thenReturn(new File(outputDir, "ut.exec")); - when(pfs.resolvePath("it.exec")).thenReturn(new File(outputDir, "it.exec")); - when(pfs.resolvePath("target/sonar/merged.exec")).thenReturn(new File("target/sonar/merged.exec")); - - sensor.analyse(project, context); - - verify(context).getResource(resource); - verify(context).saveMeasure(resource, new Measure(CoreMetrics.MERGED_LINES_TO_COVER, 5.0)); - verify(context).saveMeasure(resource, new Measure(CoreMetrics.MERGED_UNCOVERED_LINES, 0.0)); - verify(context).saveMeasure(resource, new Measure(CoreMetrics.MERGED_COVERAGE_LINE_HITS_DATA, "3=1;6=1;7=1;10=1;11=1")); - verifyNoMoreInteractions(context); - } - - @Test - public void testSensorDefinition() { - assertThat(sensor.toString()).isEqualTo("JaCoCoAllTestsSensor"); - } -} diff --git a/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest.java b/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest.java new file mode 100644 index 00000000000..98d63538619 --- /dev/null +++ b/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest.java @@ -0,0 +1,96 @@ +/* + * 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.jacoco; + +import com.google.common.io.Files; +import org.junit.Test; +import org.sonar.api.batch.SensorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.resources.JavaFile; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.ProjectFileSystem; +import org.sonar.api.resources.Resource; +import org.sonar.test.TestUtils; + +import java.io.File; +import java.io.IOException; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +public class JaCoCoOverallSensorTest { + private final JacocoConfiguration configuration= mock(JacocoConfiguration.class); + private final SensorContext context = mock(SensorContext.class); + private final ProjectFileSystem pfs = mock(ProjectFileSystem.class); + private final Project project = mock(Project.class); + private final JaCoCoOverallSensor sensor = new JaCoCoOverallSensor(configuration); + + @Test + public void should_execute_on_project() { + Project project = mock(Project.class); + when(configuration.getItReportPath()).thenReturn("target/it-jacoco.exec"); + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC).thenReturn(Project.AnalysisType.REUSE_REPORTS); + + assertThat(sensor.shouldExecuteOnProject(project)).isTrue(); + } + + @Test + public void do_not_execute_when_report_path_not_specified() { + Project project = mock(Project.class); + when(configuration.getItReportPath()).thenReturn(""); + + assertThat(sensor.shouldExecuteOnProject(project)).isFalse(); + } + + @Test + public void should_save_measures() throws IOException { + File outputDir = TestUtils.getResource(JaCoCoOverallSensorTest.class, "."); + Files.copy(TestUtils.getResource("HelloWorld.class.toCopy"), new File(outputDir, "HelloWorld.class")); + + JavaFile resource = new JavaFile("com.sonar.coverages.HelloWorld"); + + when(project.getFileSystem()).thenReturn(pfs); + when(context.getResource(any(Resource.class))).thenReturn(resource); + when(configuration.getReportPath()).thenReturn("ut.exec"); + when(configuration.getItReportPath()).thenReturn("it.exec"); + when(pfs.getBuildOutputDir()).thenReturn(outputDir); + when(pfs.resolvePath("ut.exec")).thenReturn(new File(outputDir, "ut.exec")); + when(pfs.resolvePath("it.exec")).thenReturn(new File(outputDir, "it.exec")); + when(pfs.resolvePath("target/sonar/jacoco-overall.exec")).thenReturn(new File("target/sonar/jacoco-overall.exec")); + + sensor.analyse(project, context); + + verify(context).getResource(resource); + verify(context).saveMeasure(resource, new Measure(CoreMetrics.OVERALL_LINES_TO_COVER, 5.0)); + verify(context).saveMeasure(resource, new Measure(CoreMetrics.OVERALL_UNCOVERED_LINES, 0.0)); + verify(context).saveMeasure(resource, new Measure(CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA, "3=1;6=1;7=1;10=1;11=1")); + verifyNoMoreInteractions(context); + } + + @Test + public void testSensorDefinition() { + assertThat(sensor.toString()).isEqualTo("JaCoCoOverallSensor"); + } +} diff --git a/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoAllTestsSensorTest/it.exec b/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoAllTestsSensorTest/it.exec deleted file mode 100644 index ce2421df376..00000000000 Binary files a/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoAllTestsSensorTest/it.exec and /dev/null differ diff --git a/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoAllTestsSensorTest/ut.exec b/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoAllTestsSensorTest/ut.exec deleted file mode 100644 index 09d84373641..00000000000 Binary files a/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoAllTestsSensorTest/ut.exec and /dev/null differ diff --git a/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/it.exec b/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/it.exec new file mode 100644 index 00000000000..ce2421df376 Binary files /dev/null and b/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/it.exec differ diff --git a/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/ut.exec b/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/ut.exec new file mode 100644 index 00000000000..09d84373641 Binary files /dev/null and b/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/ut.exec differ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java index a03ab232ef8..c609da95d8f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java @@ -40,7 +40,7 @@ public final class CoreMetrics { public static final String DOMAIN_SIZE = "Size"; public static final String DOMAIN_TESTS = "Tests"; public static final String DOMAIN_INTEGRATION_TESTS = "Integration Tests"; - public static final String DOMAIN_MERGED_TESTS = "Merged Tests"; + public static final String DOMAIN_OVERALL_TESTS = "All Tests"; public static final String DOMAIN_COMPLEXITY = "Complexity"; public static final String DOMAIN_DOCUMENTATION = "Documentation"; public static final String DOMAIN_RULES = "Rules"; @@ -688,7 +688,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric IT_COVERAGE = new Metric.Builder(IT_COVERAGE_KEY, "IT Coverage", Metric.ValueType.PERCENT) + public static final Metric IT_COVERAGE = new Metric.Builder(IT_COVERAGE_KEY, "IT coverage", Metric.ValueType.PERCENT) .setDescription("Coverage by integration tests") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(true) @@ -705,7 +705,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric NEW_IT_COVERAGE = new Metric.Builder(NEW_IT_COVERAGE_KEY, "New Coverage by IT", Metric.ValueType.PERCENT) + public static final Metric NEW_IT_COVERAGE = new Metric.Builder(NEW_IT_COVERAGE_KEY, "New coverage by IT", Metric.ValueType.PERCENT) .setDescription("Integration Tests Coverage of new/changed code") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(true) @@ -723,7 +723,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric IT_LINES_TO_COVER = new Metric.Builder(IT_LINES_TO_COVER_KEY, "IT Lines to Cover", Metric.ValueType.INT) + public static final Metric IT_LINES_TO_COVER = new Metric.Builder(IT_LINES_TO_COVER_KEY, "IT lines to cover", Metric.ValueType.INT) .setDescription("Lines to cover by Integration Tests") .setDirection(Metric.DIRECTION_BETTER) .setDomain(DOMAIN_INTEGRATION_TESTS) @@ -741,7 +741,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric NEW_IT_LINES_TO_COVER = new Metric.Builder(NEW_IT_LINES_TO_COVER_KEY, "New Lines to Cover by IT", Metric.ValueType.INT) + public static final Metric NEW_IT_LINES_TO_COVER = new Metric.Builder(NEW_IT_LINES_TO_COVER_KEY, "New lines to cover by IT", Metric.ValueType.INT) .setDescription("New lines to cover by Integration Tests") .setDirection(Metric.DIRECTION_WORST) .setQualitative(false) @@ -758,7 +758,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric IT_UNCOVERED_LINES = new Metric.Builder(IT_UNCOVERED_LINES_KEY, "IT Uncovered Lines", Metric.ValueType.INT) + public static final Metric IT_UNCOVERED_LINES = new Metric.Builder(IT_UNCOVERED_LINES_KEY, "IT uncovered lines", Metric.ValueType.INT) .setDescription("IT uncovered lines") .setDirection(Metric.DIRECTION_WORST) .setQualitative(false) @@ -774,7 +774,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric NEW_IT_UNCOVERED_LINES = new Metric.Builder(NEW_IT_UNCOVERED_LINES_KEY, "New Uncovered Lines by IT", Metric.ValueType.INT) + public static final Metric NEW_IT_UNCOVERED_LINES = new Metric.Builder(NEW_IT_UNCOVERED_LINES_KEY, "New uncovered lines by IT", Metric.ValueType.INT) .setDescription("New uncovered lines by Integration Tests") .setDirection(Metric.DIRECTION_WORST) .setDomain(DOMAIN_INTEGRATION_TESTS) @@ -791,7 +791,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric IT_LINE_COVERAGE = new Metric.Builder(IT_LINE_COVERAGE_KEY, "IT Line coverage", Metric.ValueType.PERCENT) + public static final Metric IT_LINE_COVERAGE = new Metric.Builder(IT_LINE_COVERAGE_KEY, "IT line coverage", Metric.ValueType.PERCENT) .setDescription("IT line coverage") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(true) @@ -806,7 +806,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric NEW_IT_LINE_COVERAGE = new Metric.Builder(NEW_IT_LINE_COVERAGE_KEY, "New Line Coverage by IT", Metric.ValueType.PERCENT) + public static final Metric NEW_IT_LINE_COVERAGE = new Metric.Builder(NEW_IT_LINE_COVERAGE_KEY, "New line coverage by IT", Metric.ValueType.PERCENT) .setDescription("Line Coverage by Integration Tests of added/changed code") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(true) @@ -824,7 +824,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric IT_COVERAGE_LINE_HITS_DATA = new Metric.Builder(IT_COVERAGE_LINE_HITS_DATA_KEY, "IT Coverage Hits Data", Metric.ValueType.DATA) + public static final Metric IT_COVERAGE_LINE_HITS_DATA = new Metric.Builder(IT_COVERAGE_LINE_HITS_DATA_KEY, "IT coverage hits data", Metric.ValueType.DATA) .setDescription("IT Code coverage line hits data") .setDirection(Metric.DIRECTION_NONE) .setQualitative(false) @@ -840,7 +840,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric IT_CONDITIONS_TO_COVER = new Metric.Builder(IT_CONDITIONS_TO_COVER_KEY, "IT Branches to Cover", Metric.ValueType.INT) + public static final Metric IT_CONDITIONS_TO_COVER = new Metric.Builder(IT_CONDITIONS_TO_COVER_KEY, "IT branches to cover", Metric.ValueType.INT) .setDescription("IT Conditions to cover") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(false) @@ -858,7 +858,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric NEW_IT_CONDITIONS_TO_COVER = new Metric.Builder(NEW_IT_CONDITIONS_TO_COVER_KEY, "New Conditions to Cover by IT", Metric.ValueType.INT) + public static final Metric NEW_IT_CONDITIONS_TO_COVER = new Metric.Builder(NEW_IT_CONDITIONS_TO_COVER_KEY, "New conditions to cover by IT", Metric.ValueType.INT) .setDescription("New conditions to cover by Integration Tests") .setDomain(DOMAIN_INTEGRATION_TESTS) .setFormula(new SumChildValuesFormula(false)) @@ -873,7 +873,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric IT_UNCOVERED_CONDITIONS = new Metric.Builder(IT_UNCOVERED_CONDITIONS_KEY, "IT Uncovered Branches", Metric.ValueType.INT) + public static final Metric IT_UNCOVERED_CONDITIONS = new Metric.Builder(IT_UNCOVERED_CONDITIONS_KEY, "IT uncovered branches", Metric.ValueType.INT) .setDescription("IT Uncovered conditions") .setDirection(Metric.DIRECTION_WORST) .setDomain(DOMAIN_INTEGRATION_TESTS) @@ -888,7 +888,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric NEW_IT_UNCOVERED_CONDITIONS = new Metric.Builder(NEW_IT_UNCOVERED_CONDITIONS_KEY, "New Uncovered Conditions by IT", Metric.ValueType.INT) + public static final Metric NEW_IT_UNCOVERED_CONDITIONS = new Metric.Builder(NEW_IT_UNCOVERED_CONDITIONS_KEY, "New uncovered conditions by IT", Metric.ValueType.INT) .setDescription("New uncovered conditions by Integration Tests") .setDirection(Metric.DIRECTION_WORST) .setDomain(DOMAIN_INTEGRATION_TESTS) @@ -905,7 +905,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric IT_BRANCH_COVERAGE = new Metric.Builder(IT_BRANCH_COVERAGE_KEY, "IT Branch Coverage", Metric.ValueType.PERCENT) + public static final Metric IT_BRANCH_COVERAGE = new Metric.Builder(IT_BRANCH_COVERAGE_KEY, "IT branch coverage", Metric.ValueType.PERCENT) .setDescription("IT Branch coverage") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(true) @@ -922,7 +922,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric NEW_IT_BRANCH_COVERAGE = new Metric.Builder(NEW_IT_BRANCH_COVERAGE_KEY, "New Branch Coverage by IT", Metric.ValueType.PERCENT) + public static final Metric NEW_IT_BRANCH_COVERAGE = new Metric.Builder(NEW_IT_BRANCH_COVERAGE_KEY, "New branch coverage by IT", Metric.ValueType.PERCENT) .setDescription("Branch coverage by Integration Tests of new/changed code") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(true) @@ -940,7 +940,7 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric IT_CONDITIONS_BY_LINE = new Metric.Builder(IT_CONDITIONS_BY_LINE_KEY, "IT Branches by Line", Metric.ValueType.DATA) + public static final Metric IT_CONDITIONS_BY_LINE = new Metric.Builder(IT_CONDITIONS_BY_LINE_KEY, "IT branches by line", Metric.ValueType.DATA) .setDomain(DOMAIN_INTEGRATION_TESTS) .setDeleteHistoricalData(true) .create(); @@ -953,30 +953,30 @@ public final class CoreMetrics { /** * @since 2.12 */ - public static final Metric IT_COVERED_CONDITIONS_BY_LINE = new Metric.Builder(IT_COVERED_CONDITIONS_BY_LINE_KEY, "IT Covered Branches by Line", Metric.ValueType.DATA) + public static final Metric IT_COVERED_CONDITIONS_BY_LINE = new Metric.Builder(IT_COVERED_CONDITIONS_BY_LINE_KEY, "IT covered branches by line", Metric.ValueType.DATA) .setDomain(DOMAIN_INTEGRATION_TESTS) .setDeleteHistoricalData(true) .create(); // -------------------------------------------------------------------------------------------------------------------- // - // MERGED TESTS + // OVERALL TESTS // // -------------------------------------------------------------------------------------------------------------------- /** * @since 3.3 */ - public static final String MERGED_COVERAGE_KEY = "merged_coverage"; + public static final String OVERALL_COVERAGE_KEY = "overall_coverage"; /** * @since 3.3 */ - public static final Metric MERGED_COVERAGE = new Metric.Builder(MERGED_COVERAGE_KEY, "All Tests Coverage", Metric.ValueType.PERCENT) - .setDescription("Coverage by All Tests") + public static final Metric OVERALL_COVERAGE = new Metric.Builder(OVERALL_COVERAGE_KEY, "Overall coverage", Metric.ValueType.PERCENT) + .setDescription("Overall test coverage") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(true) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setWorstValue(0.0) .setBestValue(100.0) .create(); @@ -984,16 +984,16 @@ public final class CoreMetrics { /** * @since 3.3 */ - public static final String NEW_MERGED_COVERAGE_KEY = "new_merged_coverage"; + public static final String NEW_OVERALL_COVERAGE_KEY = "new_overall_coverage"; /** * @since 3.3 */ - public static final Metric NEW_MERGED_COVERAGE = new Metric.Builder(NEW_MERGED_COVERAGE_KEY, "New Coverage by All Tests", Metric.ValueType.PERCENT) - .setDescription("All Tests Coverage of new/changed code") + public static final Metric NEW_OVERALL_COVERAGE = new Metric.Builder(NEW_OVERALL_COVERAGE_KEY, "Overall new coverage", Metric.ValueType.PERCENT) + .setDescription("Overall coverage of new/changed code") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(true) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setWorstValue(0.0) .setBestValue(100.0) .setDeleteHistoricalData(true) @@ -1002,15 +1002,15 @@ public final class CoreMetrics { /** * @since 3.3 */ - public static final String MERGED_LINES_TO_COVER_KEY = "merged_lines_to_cover"; + public static final String OVERALL_LINES_TO_COVER_KEY = "overall_lines_to_cover"; /** * @since 3.3 */ - public static final Metric MERGED_LINES_TO_COVER = new Metric.Builder(MERGED_LINES_TO_COVER_KEY, "All Tests Lines to Cover", Metric.ValueType.INT) - .setDescription("Lines to cover by All Tests") + public static final Metric OVERALL_LINES_TO_COVER = new Metric.Builder(OVERALL_LINES_TO_COVER_KEY, "Overall lines to cover", Metric.ValueType.INT) + .setDescription("Overall lines to cover by all tests") .setDirection(Metric.DIRECTION_BETTER) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setQualitative(false) .setFormula(new SumChildValuesFormula(false)) .setHidden(true) @@ -1020,16 +1020,16 @@ public final class CoreMetrics { /** * @since 3.3 */ - public static final String NEW_MERGED_LINES_TO_COVER_KEY = "new_merged_lines_to_cover"; + public static final String NEW_OVERALL_LINES_TO_COVER_KEY = "new_overall_lines_to_cover"; /** * @since 3.3 */ - public static final Metric NEW_MERGED_LINES_TO_COVER = new Metric.Builder(NEW_MERGED_LINES_TO_COVER_KEY, "New Lines to Cover by All Tests", Metric.ValueType.INT) - .setDescription("New lines to cover by All Tests") + public static final Metric NEW_OVERALL_LINES_TO_COVER = new Metric.Builder(NEW_OVERALL_LINES_TO_COVER_KEY, "Overall new lines to cover", Metric.ValueType.INT) + .setDescription("New lines to cover by all tests") .setDirection(Metric.DIRECTION_WORST) .setQualitative(false) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setFormula(new SumChildValuesFormula(false)) .setDeleteHistoricalData(true) .create(); @@ -1037,31 +1037,31 @@ public final class CoreMetrics { /** * @since 3.3 */ - public static final String MERGED_UNCOVERED_LINES_KEY = "merged_uncovered_lines"; + public static final String OVERALL_UNCOVERED_LINES_KEY = "overall_uncovered_lines"; /** * @since 3.3 */ - public static final Metric MERGED_UNCOVERED_LINES = new Metric.Builder(MERGED_UNCOVERED_LINES_KEY, "All Tests Uncovered Lines", Metric.ValueType.INT) - .setDescription("All Tests uncovered lines") + public static final Metric OVERALL_UNCOVERED_LINES = new Metric.Builder(OVERALL_UNCOVERED_LINES_KEY, "Overall uncovered lines", Metric.ValueType.INT) + .setDescription("Uncovered lines by all tests") .setDirection(Metric.DIRECTION_WORST) .setQualitative(false) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setFormula(new SumChildValuesFormula(false)) .create(); /** * @since 3.3 */ - public static final String NEW_MERGED_UNCOVERED_LINES_KEY = "new_merged_uncovered_lines"; + public static final String NEW_OVERALL_UNCOVERED_LINES_KEY = "new_overall_uncovered_lines"; /** * @since 3.3 */ - public static final Metric NEW_MERGED_UNCOVERED_LINES = new Metric.Builder(NEW_MERGED_UNCOVERED_LINES_KEY, "New Uncovered Lines by All Tests", Metric.ValueType.INT) - .setDescription("New uncovered lines by All Tests") + public static final Metric NEW_OVERALL_UNCOVERED_LINES = new Metric.Builder(NEW_OVERALL_UNCOVERED_LINES_KEY, "Overall new lines uncovered", Metric.ValueType.INT) + .setDescription("New lines that are not covered by any tests") .setDirection(Metric.DIRECTION_WORST) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setFormula(new SumChildValuesFormula(false)) .setBestValue(0.0) .setDeleteHistoricalData(true) @@ -1070,65 +1070,65 @@ public final class CoreMetrics { /** * @since 3.3 */ - public static final String MERGED_LINE_COVERAGE_KEY = "merged_line_coverage"; + public static final String OVERALL_LINE_COVERAGE_KEY = "overall_line_coverage"; /** * @since 3.3 */ - public static final Metric MERGED_LINE_COVERAGE = new Metric.Builder(MERGED_LINE_COVERAGE_KEY, "All Tests Line coverage", Metric.ValueType.PERCENT) - .setDescription("All Tests line coverage") + public static final Metric OVERALL_LINE_COVERAGE = new Metric.Builder(OVERALL_LINE_COVERAGE_KEY, "Overall line coverage", Metric.ValueType.PERCENT) + .setDescription("Line coverage by all tests") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(true) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .create(); /** * @since 3.3 */ - public static final String NEW_MERGED_LINE_COVERAGE_KEY = "new_merged_line_coverage"; + public static final String NEW_OVERALL_LINE_COVERAGE_KEY = "new_overall_line_coverage"; /** * @since 3.3 */ - public static final Metric NEW_MERGED_LINE_COVERAGE = new Metric.Builder(NEW_MERGED_LINE_COVERAGE_KEY, "New Line Coverage by All Tests", Metric.ValueType.PERCENT) - .setDescription("Line Coverage by All Tests of added/changed code") + public static final Metric NEW_OVERALL_LINE_COVERAGE = new Metric.Builder(NEW_OVERALL_LINE_COVERAGE_KEY, "Overall new line coverage", Metric.ValueType.PERCENT) + .setDescription("Line coverage of added/changed code by all tests") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(true) .setWorstValue(0.0) .setBestValue(100.0) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setDeleteHistoricalData(true) .create(); /** * @since 3.3 */ - public static final String MERGED_COVERAGE_LINE_HITS_DATA_KEY = "merged_coverage_line_hits_data"; + public static final String OVERALL_COVERAGE_LINE_HITS_DATA_KEY = "overall_coverage_line_hits_data"; /** * @since 3.3 */ - public static final Metric MERGED_COVERAGE_LINE_HITS_DATA = new Metric.Builder(MERGED_COVERAGE_LINE_HITS_DATA_KEY, "All Tests Coverage Hits Data", Metric.ValueType.DATA) - .setDescription("All Tests Code coverage line hits data") + public static final Metric OVERALL_COVERAGE_LINE_HITS_DATA = new Metric.Builder(OVERALL_COVERAGE_LINE_HITS_DATA_KEY, "Overall coverage hits by line", Metric.ValueType.DATA) + .setDescription("Coverage hits by all tests and by line") .setDirection(Metric.DIRECTION_NONE) .setQualitative(false) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setDeleteHistoricalData(true) .create(); /** * @since 3.3 */ - public static final String MERGED_CONDITIONS_TO_COVER_KEY = "merged_conditions_to_cover"; + public static final String OVERALL_CONDITIONS_TO_COVER_KEY = "overall_conditions_to_cover"; /** * @since 3.3 */ - public static final Metric MERGED_CONDITIONS_TO_COVER = new Metric.Builder(MERGED_CONDITIONS_TO_COVER_KEY, "All Tests Branches to Cover", Metric.ValueType.INT) - .setDescription("All Tests Conditions to cover") + public static final Metric OVERALL_CONDITIONS_TO_COVER = new Metric.Builder(OVERALL_CONDITIONS_TO_COVER_KEY, "Overall branches to cover", Metric.ValueType.INT) + .setDescription("Branches to cover by all tests") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(false) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setFormula(new SumChildValuesFormula(false)) .setHidden(true) .setDeleteHistoricalData(true) @@ -1137,14 +1137,14 @@ public final class CoreMetrics { /** * @since 3.3 */ - public static final String NEW_MERGED_CONDITIONS_TO_COVER_KEY = "new_merged_conditions_to_cover"; + public static final String NEW_OVERALL_CONDITIONS_TO_COVER_KEY = "new_overall_conditions_to_cover"; /** * @since 3.3 */ - public static final Metric NEW_MERGED_CONDITIONS_TO_COVER = new Metric.Builder(NEW_MERGED_CONDITIONS_TO_COVER_KEY, "New Conditions to Cover by All Tests", Metric.ValueType.INT) - .setDescription("New conditions to cover by All Tests") - .setDomain(DOMAIN_MERGED_TESTS) + public static final Metric NEW_OVERALL_CONDITIONS_TO_COVER = new Metric.Builder(NEW_OVERALL_CONDITIONS_TO_COVER_KEY, "Overall new branches to cover", Metric.ValueType.INT) + .setDescription("New branches to cover by all tests") + .setDomain(DOMAIN_OVERALL_TESTS) .setFormula(new SumChildValuesFormula(false)) .setDeleteHistoricalData(true) .create(); @@ -1152,30 +1152,30 @@ public final class CoreMetrics { /** * @since 3.3 */ - public static final String MERGED_UNCOVERED_CONDITIONS_KEY = "merged_uncovered_conditions"; + public static final String OVERALL_UNCOVERED_CONDITIONS_KEY = "overall_uncovered_conditions"; /** * @since 3.3 */ - public static final Metric MERGED_UNCOVERED_CONDITIONS = new Metric.Builder(MERGED_UNCOVERED_CONDITIONS_KEY, "All Tests Uncovered Branches", Metric.ValueType.INT) - .setDescription("All Tests Uncovered conditions") + public static final Metric OVERALL_UNCOVERED_CONDITIONS = new Metric.Builder(OVERALL_UNCOVERED_CONDITIONS_KEY, "Overall uncovered branches", Metric.ValueType.INT) + .setDescription("Uncovered branches by all tests") .setDirection(Metric.DIRECTION_WORST) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setFormula(new SumChildValuesFormula(false)) .create(); /** * @since 3.3 */ - public static final String NEW_MERGED_UNCOVERED_CONDITIONS_KEY = "new_merged_uncovered_conditions"; + public static final String NEW_OVERALL_UNCOVERED_CONDITIONS_KEY = "new_overall_uncovered_conditions"; /** * @since 3.3 */ - public static final Metric NEW_MERGED_UNCOVERED_CONDITIONS = new Metric.Builder(NEW_MERGED_UNCOVERED_CONDITIONS_KEY, "New Uncovered Conditions by All Tests", Metric.ValueType.INT) - .setDescription("New uncovered conditions by All Tests") + public static final Metric NEW_OVERALL_UNCOVERED_CONDITIONS = new Metric.Builder(NEW_OVERALL_UNCOVERED_CONDITIONS_KEY, "Overall new branches uncovered", Metric.ValueType.INT) + .setDescription("New branches that are not covered by any test") .setDirection(Metric.DIRECTION_WORST) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setFormula(new SumChildValuesFormula(false)) .setBestValue(0.0) .setDeleteHistoricalData(true) @@ -1184,16 +1184,16 @@ public final class CoreMetrics { /** * @since 3.3 */ - public static final String MERGED_BRANCH_COVERAGE_KEY = "merged_branch_coverage"; + public static final String OVERALL_BRANCH_COVERAGE_KEY = "overall_branch_coverage"; /** * @since 3.3 */ - public static final Metric MERGED_BRANCH_COVERAGE = new Metric.Builder(MERGED_BRANCH_COVERAGE_KEY, "All Tests Branch Coverage", Metric.ValueType.PERCENT) - .setDescription("All Tests Branch coverage") + public static final Metric OVERALL_BRANCH_COVERAGE = new Metric.Builder(OVERALL_BRANCH_COVERAGE_KEY, "Overall branch coverage", Metric.ValueType.PERCENT) + .setDescription("Branch coverage by all tests") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(true) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setWorstValue(0.0) .setBestValue(100.0) .create(); @@ -1201,16 +1201,16 @@ public final class CoreMetrics { /** * @since 3.3 */ - public static final String NEW_MERGED_BRANCH_COVERAGE_KEY = "new_merged_branch_coverage"; + public static final String NEW_OVERALL_BRANCH_COVERAGE_KEY = "new_overall_branch_coverage"; /** * @since 3.3 */ - public static final Metric NEW_MERGED_BRANCH_COVERAGE = new Metric.Builder(NEW_MERGED_BRANCH_COVERAGE_KEY, "New Branch Coverage by All Tests", Metric.ValueType.PERCENT) - .setDescription("Branch coverage by All Tests of new/changed code") + public static final Metric NEW_OVERALL_BRANCH_COVERAGE = new Metric.Builder(NEW_OVERALL_BRANCH_COVERAGE_KEY, "Overall new branch coverage", Metric.ValueType.PERCENT) + .setDescription("Branch coverage of new/changed code by all tests") .setDirection(Metric.DIRECTION_BETTER) .setQualitative(true) - .setDomain(DOMAIN_MERGED_TESTS) + .setDomain(DOMAIN_OVERALL_TESTS) .setWorstValue(0.0) .setBestValue(100.0) .setDeleteHistoricalData(true) @@ -1219,26 +1219,28 @@ public final class CoreMetrics { /** * @since 3.3 */ - public static final String MERGED_CONDITIONS_BY_LINE_KEY = "merged_conditions_by_line"; + public static final String OVERALL_CONDITIONS_BY_LINE_KEY = "overall_conditions_by_line"; /** * @since 3.3 */ - public static final Metric MERGED_CONDITIONS_BY_LINE = new Metric.Builder(MERGED_CONDITIONS_BY_LINE_KEY, "All Tests Branches by Line", Metric.ValueType.DATA) - .setDomain(DOMAIN_MERGED_TESTS) + public static final Metric OVERALL_CONDITIONS_BY_LINE = new Metric.Builder(OVERALL_CONDITIONS_BY_LINE_KEY, "Overall branches by line", Metric.ValueType.DATA) + .setDescription("Overall branches by all tests and by line") + .setDomain(DOMAIN_OVERALL_TESTS) .setDeleteHistoricalData(true) .create(); /** * @since 3.3 */ - public static final String MERGED_COVERED_CONDITIONS_BY_LINE_KEY = "merged_covered_conditions_by_line"; + public static final String OVERALL_COVERED_CONDITIONS_BY_LINE_KEY = "overall_covered_conditions_by_line"; /** * @since 3.3 */ - public static final Metric MERGED_COVERED_CONDITIONS_BY_LINE = new Metric.Builder(MERGED_COVERED_CONDITIONS_BY_LINE_KEY, "All Tests Covered Branches by Line", Metric.ValueType.DATA) - .setDomain(DOMAIN_MERGED_TESTS) + public static final Metric OVERALL_COVERED_CONDITIONS_BY_LINE = new Metric.Builder(OVERALL_COVERED_CONDITIONS_BY_LINE_KEY, "Overall covered branches by line", Metric.ValueType.DATA) + .setDescription("Overall covered branches by all tests and by line") + .setDomain(DOMAIN_OVERALL_TESTS) .setDeleteHistoricalData(true) .create(); diff --git a/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java b/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java index 54ac8b6c780..ec3c0852363 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java @@ -67,13 +67,19 @@ public final class DefaultPages { CoreMetrics.NEW_COVERAGE_KEY, CoreMetrics.NEW_UNCOVERED_LINES_KEY, CoreMetrics.NEW_LINE_COVERAGE_KEY, CoreMetrics.NEW_LINES_TO_COVER_KEY, CoreMetrics.NEW_BRANCH_COVERAGE_KEY, CoreMetrics.NEW_CONDITIONS_TO_COVER_KEY, CoreMetrics.NEW_UNCOVERED_CONDITIONS_KEY, - /* integration tests */ - CoreMetrics.IT_COVERAGE_KEY, CoreMetrics.IT_LINES_TO_COVER_KEY, CoreMetrics.IT_UNCOVERED_LINES_KEY, CoreMetrics.IT_LINE_COVERAGE_KEY, - CoreMetrics.IT_CONDITIONS_TO_COVER_KEY, CoreMetrics.IT_UNCOVERED_CONDITIONS_KEY, CoreMetrics.IT_BRANCH_COVERAGE_KEY, - CoreMetrics.NEW_IT_COVERAGE_KEY, CoreMetrics.NEW_IT_UNCOVERED_LINES_KEY, CoreMetrics.NEW_IT_LINE_COVERAGE_KEY, - CoreMetrics.NEW_IT_LINES_TO_COVER_KEY, CoreMetrics.NEW_IT_BRANCH_COVERAGE_KEY, CoreMetrics.NEW_IT_CONDITIONS_TO_COVER_KEY, CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS_KEY - }) - @RequiredMeasures(anyOf = {CoreMetrics.COVERAGE_KEY, CoreMetrics.IT_COVERAGE_KEY}) + /* integration tests */ + CoreMetrics.IT_COVERAGE_KEY, CoreMetrics.IT_LINES_TO_COVER_KEY, CoreMetrics.IT_UNCOVERED_LINES_KEY, CoreMetrics.IT_LINE_COVERAGE_KEY, + CoreMetrics.IT_CONDITIONS_TO_COVER_KEY, CoreMetrics.IT_UNCOVERED_CONDITIONS_KEY, CoreMetrics.IT_BRANCH_COVERAGE_KEY, + CoreMetrics.NEW_IT_COVERAGE_KEY, CoreMetrics.NEW_IT_UNCOVERED_LINES_KEY, CoreMetrics.NEW_IT_LINE_COVERAGE_KEY, + CoreMetrics.NEW_IT_LINES_TO_COVER_KEY, CoreMetrics.NEW_IT_BRANCH_COVERAGE_KEY, CoreMetrics.NEW_IT_CONDITIONS_TO_COVER_KEY, CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS_KEY, + + /* overall tests */ + CoreMetrics.OVERALL_COVERAGE_KEY, CoreMetrics.OVERALL_LINES_TO_COVER_KEY, CoreMetrics.OVERALL_UNCOVERED_LINES_KEY, CoreMetrics.OVERALL_LINE_COVERAGE_KEY, + CoreMetrics.OVERALL_CONDITIONS_TO_COVER_KEY, CoreMetrics.OVERALL_UNCOVERED_CONDITIONS_KEY, CoreMetrics.OVERALL_BRANCH_COVERAGE_KEY, + CoreMetrics.NEW_OVERALL_COVERAGE_KEY, CoreMetrics.NEW_OVERALL_UNCOVERED_LINES_KEY, CoreMetrics.NEW_OVERALL_LINE_COVERAGE_KEY, + CoreMetrics.NEW_OVERALL_LINES_TO_COVER_KEY, CoreMetrics.NEW_OVERALL_BRANCH_COVERAGE_KEY, CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER_KEY, CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS_KEY + }) + @RequiredMeasures(anyOf = {CoreMetrics.COVERAGE_KEY, CoreMetrics.IT_COVERAGE_KEY, CoreMetrics.OVERALL_COVERAGE_KEY}) @UserRole(UserRole.CODEVIEWER) private static final class CoverageTab implements RubyRailsPage { public String getTemplate() { diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index a539cd819b5..1b49f23e2e1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -45,6 +45,7 @@ class ResourceController < ApplicationController if @extension.getId()=='violations' render_violations() elsif (@extension.getId()=='coverage') + puts '-------------------------------------------' render_coverage() elsif (@extension.getId()=='source') render_source() @@ -177,7 +178,7 @@ class ResourceController < ApplicationController load_sources() @display_coverage = true @display_it_coverage = (!@snapshot.measure('it_coverage').nil?) - @display_all_tests_coverage = (!@snapshot.measure('merged_coverage').nil?) + @display_overall_coverage = (!@snapshot.measure('overall_coverage').nil?) @expandable = (@lines!=nil) if @lines metric = Metric.by_key(params[:coverage_filter]||params[:metric]) @@ -185,7 +186,7 @@ class ResourceController < ApplicationController it_prefix = '' it_prefix = 'it_' if @coverage_filter.start_with?('it_') - it_prefix = 'merged_' if @coverage_filter.start_with?('merged_') + it_prefix = 'overall_' if @coverage_filter.start_with?('overall_') @hits_by_line = load_distribution("#{it_prefix}coverage_line_hits_data") @conditions_by_line = load_distribution("#{it_prefix}conditions_by_line") @@ -217,14 +218,14 @@ class ResourceController < ApplicationController 'new_lines_to_cover'==@coverage_filter || 'new_coverage'==@coverage_filter || 'new_line_coverage'==@coverage_filter || 'it_lines_to_cover'==@coverage_filter || 'it_coverage'==@coverage_filter || 'it_line_coverage'==@coverage_filter || 'new_it_lines_to_cover'==@coverage_filter || 'new_it_coverage'==@coverage_filter || 'new_it_line_coverage'==@coverage_filter || - 'merged_lines_to_cover'==@coverage_filter || 'merged_coverage'==@coverage_filter || 'merged_line_coverage'==@coverage_filter || - 'new_merged_lines_to_cover'==@coverage_filter || 'new_merged_coverage'==@coverage_filter || 'new_merged_line_coverage'==@coverage_filter) + 'overall_lines_to_cover'==@coverage_filter || 'overall_coverage'==@coverage_filter || 'overall_line_coverage'==@coverage_filter || + 'new_overall_lines_to_cover'==@coverage_filter || 'new_overall_coverage'==@coverage_filter || 'new_overall_line_coverage'==@coverage_filter) @coverage_filter = "#{it_prefix}lines_to_cover" filter_lines { |line| line.hits && line.after(to) } elsif ('uncovered_lines'==@coverage_filter || 'new_uncovered_lines'==@coverage_filter || 'it_uncovered_lines'==@coverage_filter || 'new_it_uncovered_lines'==@coverage_filter || - 'merged_uncovered_lines'==@coverage_filter || 'new_merged_uncovered_lines'==@coverage_filter) + 'overall_uncovered_lines'==@coverage_filter || 'new_overall_uncovered_lines'==@coverage_filter) @coverage_filter = "#{it_prefix}uncovered_lines" filter_lines { |line| line.hits && line.hits==0 && line.after(to) } @@ -232,14 +233,14 @@ class ResourceController < ApplicationController 'new_conditions_to_cover'==@coverage_filter || 'new_branch_coverage'==@coverage_filter || 'it_conditions_to_cover'==@coverage_filter || 'it_branch_coverage'==@coverage_filter || 'new_it_conditions_to_cover' == @coverage_filter || 'new_it_branch_coverage'==@coverage_filter || - 'merged_conditions_to_cover'==@coverage_filter || 'merged_branch_coverage'==@coverage_filter || - 'new_merged_conditions_to_cover' == @coverage_filter || 'new_merged_branch_coverage'==@coverage_filter) + 'overall_conditions_to_cover'==@coverage_filter || 'overall_branch_coverage'==@coverage_filter || + 'new_overall_conditions_to_cover' == @coverage_filter || 'new_overall_branch_coverage'==@coverage_filter) @coverage_filter="#{it_prefix}conditions_to_cover" filter_lines { |line| line.conditions && line.conditions>0 && line.after(to) } elsif ('uncovered_conditions' == @coverage_filter || 'new_uncovered_conditions' == @coverage_filter || 'it_uncovered_conditions'==@coverage_filter || 'new_it_uncovered_conditions' == @coverage_filter || - 'merged_uncovered_conditions'==@coverage_filter || 'new_merged_uncovered_conditions' == @coverage_filter) + 'overall_uncovered_conditions'==@coverage_filter || 'new_overall_uncovered_conditions' == @coverage_filter) @coverage_filter="#{it_prefix}uncovered_conditions" filter_lines { |line| line.conditions && line.covered_conditions && line.covered_conditions - <% if @period && (measure('new_coverage') || measure('new_it_coverage')) %> -

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

- - - + <% if @period && (measure('new_coverage') || measure('new_it_coverage')|| measure('new_overall_coverage')) %> +

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

+
<%= format_variation('new_coverage', :period => @period, :default => '-', :style => 'none') -%>
+ + - + - <% if m=measure('new_line_coverage') %> - - - <% else %> - - <% end %> + <% if m=measure('new_line_coverage') %> + + + <% else %> + + <% end %> - - <% if m=measure('new_branch_coverage') %> - - - <% else %> - - <% end %> - - - - <% if m=measure('new_uncovered_lines') %> - - - <% else %> - - <% end %> + + <% if m=measure('new_branch_coverage') %> + + + <% else %> + + <% end %> + + + + <% if m=measure('new_uncovered_lines') %> + + + <% else %> + + <% end %> - - <% if m=measure('new_uncovered_conditions') %> - - - <% else %> - - <% end %> - + + <% if m=measure('new_uncovered_conditions') %> + + + <% else %> + + <% end %> + <% if measure('new_it_coverage') %> @@ -46,7 +48,7 @@ - + <% if m=measure('new_it_line_coverage') %> @@ -55,7 +57,7 @@ <% end %> - + <% if m=measure('new_it_branch_coverage') %> @@ -64,84 +66,74 @@ <% end %> - + <% if m=measure('new_it_uncovered_lines') %> - + <% else %> <% end %> - + <% if m=measure('new_it_uncovered_conditions') %> - - + + <% else %> <% end %> <% end %> +
<%= format_variation('new_coverage', :period => @period, :default => '-', :style => 'none') -%> <%= Metric.name_for('line_coverage') -%>:<%= format_variation(m, :period => @period, :default => '-', :style => 'none') -%><%= Metric.name_for('line_coverage') -%>:<%= format_variation(m, :period => @period, :default => '-', :style => 'none') -%> <%= Metric.name_for('branch_coverage') -%>:<%= format_variation(m, :period => @period, :default => '-', :style => 'none') -%>
<%= Metric.name_for('uncovered_lines') -%>:<%= format_variation(m, :period => @period, :style => 'none') -%>/<%= format_variation('new_lines_to_cover', :period => @period, :style => 'none') -%><%= Metric.name_for('branch_coverage') -%>:<%= format_variation(m, :period => @period, :default => '-', :style => 'none') -%>
<%= Metric.name_for('uncovered_lines') -%>:<%= format_variation(m, :period => @period, :style => 'none') -%> + /<%= format_variation('new_lines_to_cover', :period => @period, :style => 'none') -%> <%= Metric.name_for('uncovered_conditions') -%>: <%= format_variation(m, :period => @period, :style => 'none') -%>/<%= format_variation('new_conditions_to_cover', :period => @period, :style => 'none') -%>
<%= Metric.name_for('uncovered_conditions') -%>:<%= format_variation(m, :period => @period, :style => 'none') -%> + /<%= format_variation('new_conditions_to_cover', :period => @period, :style => 'none') -%>

<%= message('coverage_viewer.integration_tests') -%>
<%= format_variation('new_it_coverage', :period => @period, :default => '-', :style => 'none') -%> <%= Metric.name_for('it_line_coverage') -%>: <%= Metric.name_for('it_branch_coverage') -%>: <%= format_variation(m, :period => @period, :default => '-', :style => 'none') -%>
<%= Metric.name_for('it_uncovered_lines') -%>:<%= format_variation(m, :period => @period, :style => 'none') -%>/<%= format_variation('new_it_lines_to_cover', :period => @period, :style => 'none') -%><%= format_variation(m, :period => @period, :style => 'none') -%> + /<%= format_variation('new_it_lines_to_cover', :period => @period, :style => 'none') -%> <%= Metric.name_for('it_uncovered_conditions') -%>: <%= format_variation(m, :period => @period, :style => 'none') -%>/<%= format_variation('new_it_conditions_to_cover', :period => @period, :style => 'none') -%><%= Metric.name_for('it_uncovered_conditions') -%>:<%= format_variation(m, :period => @period, :style => 'none') -%> + /<%= format_variation('new_it_conditions_to_cover', :period => @period, :style => 'none') -%>
+ <% else %> + <% if @display_it_coverage || @display_overall_coverage -%> + + + + + + <%= render :partial => 'measure', :locals => {:measure => measure('overall_uncovered_lines'), :title => Metric.name_for('uncovered_lines'), :ratio => measure('overall_lines_to_cover')} -%> + + <%= render :partial => 'measure', :locals => {:measure => measure('overall_uncovered_conditions'), :title => Metric.name_for('uncovered_conditions'), :ratio => measure('overall_conditions_to_cover')} -%> + + + + + + + <%= render :partial => 'measure', :locals => {:measure => measure('uncovered_lines'), :title => message('coverage_viewer.by.unit_tests'), :ratio => measure('lines_to_cover')} -%> + + <%= render :partial => 'measure', :locals => {:measure => measure('uncovered_conditions'), :title => message('coverage_viewer.by.unit_tests'), :ratio => measure('conditions_to_cover')} -%> + + + + + + + <%= render :partial => 'measure', :locals => {:measure => measure('it_uncovered_lines'), :title => message('coverage_viewer.by.integration_tests'), :ratio => measure('it_lines_to_cover')} -%> + + <%= render :partial => 'measure', :locals => {:measure => measure('it_uncovered_conditions'), :title => message('coverage_viewer.by.integration_tests'), :ratio => measure('it_conditions_to_cover')} -%> +
<%= format_measure('overall_coverage', :default => '-') -%>
<%= format_measure('coverage', :default => '-') -%> <%= message('coverage_viewer.unit_tests') -%>
<%= format_measure('it_coverage', :default => '-') -%> <%= message('coverage_viewer.integration_tests') -%>
- <% else %> + <% else -%> - <% if @display_it_coverage || @display_all_tests_coverage %> - - - - <% end %> - + <%= render :partial => 'measure', :locals => {:measure => measure('line_coverage'), :title => Metric.name_for('line_coverage')} -%> - + <%= render :partial => 'measure', :locals => {:measure => measure('branch_coverage'), :title => Metric.name_for('branch_coverage')} -%> - + <%= render :partial => 'measure', :locals => {:measure => measure('uncovered_lines'), :title => Metric.name_for('uncovered_lines'), :ratio => measure('lines_to_cover')} -%> - + <%= render :partial => 'measure', :locals => {:measure => measure('uncovered_conditions'), :title => Metric.name_for('uncovered_conditions'), :ratio => measure('conditions_to_cover')} -%> - - <% if @display_it_coverage %> - - - - - - - <%= render :partial => 'measure', :locals => {:measure => measure('it_line_coverage'), :title => Metric.name_for('it_line_coverage')} -%> - - <%= render :partial => 'measure', :locals => {:measure => measure('it_branch_coverage'), :title => Metric.name_for('it_branch_coverage')} -%> - - - - <%= render :partial => 'measure', :locals => {:measure => measure('it_uncovered_lines'), :title => Metric.name_for('it_uncovered_lines'), :ratio => measure('it_lines_to_cover')} -%> - - <%= render :partial => 'measure', :locals => {:measure => measure('it_uncovered_conditions'), :title => Metric.name_for('it_uncovered_conditions'), :ratio => measure('it_conditions_to_cover')} -%> - - <% end %> - - <% if @display_all_tests_coverage %> - - - - - - - <%= render :partial => 'measure', :locals => {:measure => measure('merged_line_coverage'), :title => Metric.name_for('merged_line_coverage')} -%> - - <%= render :partial => 'measure', :locals => {:measure => measure('merged_branch_coverage'), :title => Metric.name_for('merged_branch_coverage')} -%> - - - - <%= render :partial => 'measure', :locals => {:measure => measure('merged_uncovered_lines'), :title => Metric.name_for('merged_uncovered_lines'), :ratio => measure('merged_lines_to_cover')} -%> - - <%= render :partial => 'measure', :locals => {:measure => measure('merged_uncovered_conditions'), :title => Metric.name_for('merged_uncovered_conditions'), :ratio => measure('merged_conditions_to_cover')} -%> - - <% end %>
<%= message('coverage_viewer.unit_tests') -%>
<%= format_measure('coverage', :default => '-') -%>

<%= message('coverage_viewer.integration_tests') -%>
<%= format_measure('it_coverage', :default => '-') -%>

<%= message('coverage_viewer.all_tests') -%>
<%= format_measure('merged_coverage', :default => '-') -%>
- <% end %> + <% end -%> + <% end %> <%= render :partial => 'options' -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb index 07e4d531b24..8da520a23c2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb @@ -67,6 +67,14 @@ <% if @display_coverage %> <% first=false diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index 418a0ba500b..72499036b58 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -2437,3 +2437,11 @@ textarea.width100 { margin-top: 3px; margin-left: 88px; } + +.coverage tr { + line-height: 1.8em; +} + +.coverage td.name { + text-align: right; +}