From 74917f111648f8dd0f12175808c291f69637e0ad Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 2 Mar 2015 11:57:44 +0100 Subject: update events widget --- .../src/main/resources/org/sonar/plugins/core/widgets/events.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/sonar-core-plugin') diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb index 1ee56e96fcf..9f0381f48cb 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb @@ -111,7 +111,7 @@ <%= message('widget.events.no_event') -%> -<%= message('widget.events.show_more') -%> +<%= message('widget.events.show_all') -%> <% else %> - <% + <% language_key = ncloc_language_dist_hash.first[0] - language = languages.find { |l| l.getKey()==language_key.to_s } - -%> - <%= language ? language.getName() : language_key -%> + if language_key.eql? '' %> + <%= message('other') -%> + <% else %> + <% language = languages.find { |l| l.getKey()==language_key.to_s } -%> + <%= language ? language.getName() : language_key -%> + <% end %> <% end %> <% end %> <% else %> diff --git a/sonar-batch/src/main/java/org/sonar/batch/language/LanguageDistributionDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/language/LanguageDistributionDecorator.java index cc246cfc793..ab9fb78b8ff 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/language/LanguageDistributionDecorator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/language/LanguageDistributionDecorator.java @@ -35,6 +35,8 @@ import org.sonar.api.resources.ResourceUtils; public class LanguageDistributionDecorator implements Decorator { + private static final String UNKNOWN_LANGUAGE_KEY = ""; + @Override public boolean shouldExecuteOnProject(Project project) { return true; @@ -56,8 +58,8 @@ public class LanguageDistributionDecorator implements Decorator { if (ResourceUtils.isFile(resource)) { Language language = resource.getLanguage(); Measure ncloc = context.getMeasure(CoreMetrics.NCLOC); - if (language != null && ncloc != null) { - nclocDistribution.add(language.getKey(), ncloc.getIntValue()); + if (ncloc != null) { + nclocDistribution.add(language != null ? language.getKey() : UNKNOWN_LANGUAGE_KEY, ncloc.getIntValue()); } } else { for (Measure measure : context.getChildrenMeasures(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION)) { diff --git a/sonar-batch/src/test/java/org/sonar/batch/language/LanguageDistributionDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/language/LanguageDistributionDecoratorTest.java index cb9d52bae9e..155b9cd4910 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/language/LanguageDistributionDecoratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/language/LanguageDistributionDecoratorTest.java @@ -92,6 +92,21 @@ public class LanguageDistributionDecoratorTest { assertThat(result.getData()).isEqualTo("xoo=200"); } + @Test + public void save_ncloc_language_distribution_on_file_without_language() { + + when(resource.getScope()).thenReturn(Scopes.FILE); + when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 200.0)); + + decorator.decorate(resource, context); + + verify(context).saveMeasure(measureCaptor.capture()); + + Measure result = measureCaptor.getValue(); + assertThat(result.getMetric()).isEqualTo(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION); + assertThat(result.getData()).isEqualTo("=200"); + } + @Test public void save_ncloc_language_distribution_on_project() { when(resource.getScope()).thenReturn(Scopes.PROJECT); diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 9f6f5dbfdfb..daa7a8c7a4a 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -104,6 +104,7 @@ open_verb=Open operations=Operations optional=Optional order=Order +other=Other owner=Owner package=Package packages=Packages -- cgit v1.2.3 From 7fec39b0b5d604167fefd615c5400cd597166685 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Mon, 2 Mar 2015 14:48:24 +0100 Subject: Revert "SONAR-6202 Compute overall coverage on all files" This reverts commit eac465bea9f5bf89a7beb8036e4d8eea4723f421. Conflicts: plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java --- .../java/org/sonar/plugins/core/CorePlugin.java | 1 - .../sensors/MissingOverallCoverageDecorator.java | 82 --------------- .../MissingOverallCoverageDecoratorTest.java | 114 --------------------- .../api/measures/CoverageMeasuresBuilder.java | 69 +++---------- 4 files changed, 15 insertions(+), 251 deletions(-) delete mode 100644 plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/MissingOverallCoverageDecorator.java delete mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/MissingOverallCoverageDecoratorTest.java (limited to 'plugins/sonar-core-plugin') 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 8dd1801b406..5a4962b256f 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 @@ -281,7 +281,6 @@ public final class CorePlugin extends SonarPlugin { DirectoriesDecorator.class, FilesDecorator.class, ManualMeasureDecorator.class, - MissingOverallCoverageDecorator.class, // time machine TendencyDecorator.class, diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/MissingOverallCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/MissingOverallCoverageDecorator.java deleted file mode 100644 index bdae925a865..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/MissingOverallCoverageDecorator.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.plugins.core.sensors; - -import org.sonar.api.batch.Decorator; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependedUpon; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.CoverageMeasuresBuilder; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.MeasureUtils; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.Resource; - -import java.util.List; - -/** - * Compute overall coverage when it was not already saved by language plugin. - */ -public final class MissingOverallCoverageDecorator implements Decorator { - - @DependsUpon - public Metric dependsUpon() { - return CoreMetrics.LINES_TO_COVER; - } - - @DependedUpon - public List provides() { - return CoverageMeasuresBuilder.CoverageType.OVERALL.all(); - } - - @Override - public boolean shouldExecuteOnProject(Project project) { - return true; - } - - @Override - public void decorate(Resource resource, DecoratorContext context) { - if (Qualifiers.isFile(resource) && !MeasureUtils.hasValue(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER))) { - copyMeasure(context, CoreMetrics.LINES_TO_COVER, CoreMetrics.OVERALL_LINES_TO_COVER); - copyMeasure(context, CoreMetrics.UNCOVERED_LINES, CoreMetrics.OVERALL_UNCOVERED_LINES); - copyMeasure(context, CoreMetrics.COVERAGE_LINE_HITS_DATA, CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA); - copyMeasure(context, CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.OVERALL_CONDITIONS_TO_COVER); - copyMeasure(context, CoreMetrics.UNCOVERED_CONDITIONS, CoreMetrics.OVERALL_UNCOVERED_CONDITIONS); - copyMeasure(context, CoreMetrics.CONDITIONS_BY_LINE, CoreMetrics.OVERALL_CONDITIONS_BY_LINE); - copyMeasure(context, CoreMetrics.COVERED_CONDITIONS_BY_LINE, CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE); - } - } - - private void copyMeasure(DecoratorContext context, Metric from, Metric to) { - Measure sourceMeasure = context.getMeasure(from); - if (sourceMeasure != null) { - Double value = sourceMeasure.getValue(); - if (value != null) { - context.saveMeasure(to, value); - } else if (sourceMeasure.hasData()) { - context.saveMeasure(new Measure(to, sourceMeasure.getData())); - } - } - - } -} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/MissingOverallCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/MissingOverallCoverageDecoratorTest.java deleted file mode 100644 index c94eb3bce52..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/MissingOverallCoverageDecoratorTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -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.Directory; -import org.sonar.api.resources.File; -import org.sonar.api.resources.Java; -import org.sonar.api.resources.Project; - -import static org.assertj.core.api.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.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -public class MissingOverallCoverageDecoratorTest { - - private MissingOverallCoverageDecorator decorator; - - @Before - public void prepare() { - decorator = new MissingOverallCoverageDecorator(); - } - - @Test - public void increaseCoverage() { - assertThat(decorator.provides()).isNotEmpty(); - assertThat(decorator.dependsUpon()).isEqualTo(CoreMetrics.LINES_TO_COVER); - assertThat(decorator.shouldExecuteOnProject(new Project("foo"))).isTrue(); - } - - @Test - public void testExecuteOnlyOnMainFile() { - DecoratorContext context = mock(DecoratorContext.class); - decorator.decorate(File.create("test/FooTest.java", Java.INSTANCE, true), context); - decorator.decorate(Directory.create("src"), context); - decorator.decorate(new Project("foo"), context); - verifyNoMoreInteractions(context); - } - - @Test - public void dontDoAnythingIfOverallCoverageAlreadyDefined() { - DecoratorContext context = mock(DecoratorContext.class); - File file = File.create("src/Foo.java"); - - when(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER)).thenReturn(new Measure<>(CoreMetrics.OVERALL_LINES_TO_COVER, 0.0)); - - decorator.decorate(file, context); - - verify(context, never()).saveMeasure(eq(CoreMetrics.OVERALL_LINES_TO_COVER), anyDouble()); - } - - @Test - public void testCopyUnitTestMeasures() { - DecoratorContext context = mock(DecoratorContext.class); - File file = File.create("src/Foo.java"); - - when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(new Measure<>(CoreMetrics.LINES_TO_COVER, 10.0)); - when(context.getMeasure(CoreMetrics.UNCOVERED_LINES)).thenReturn(new Measure<>(CoreMetrics.UNCOVERED_LINES, 5.0)); - when(context.getMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA)).thenReturn(new Measure<>(CoreMetrics.COVERAGE_LINE_HITS_DATA, "1=1;2=2;")); - when(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER)).thenReturn(new Measure<>(CoreMetrics.CONDITIONS_TO_COVER, 2.0)); - when(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS)).thenReturn(new Measure<>(CoreMetrics.UNCOVERED_CONDITIONS, 1.0)); - when(context.getMeasure(CoreMetrics.CONDITIONS_BY_LINE)).thenReturn(new Measure<>(CoreMetrics.CONDITIONS_BY_LINE, "1=4")); - when(context.getMeasure(CoreMetrics.COVERED_CONDITIONS_BY_LINE)).thenReturn(new Measure<>(CoreMetrics.COVERED_CONDITIONS_BY_LINE, "1=2")); - - decorator.decorate(file, context); - - verify(context).saveMeasure(CoreMetrics.OVERALL_LINES_TO_COVER, 10.0); - verify(context).saveMeasure(CoreMetrics.OVERALL_UNCOVERED_LINES, 5.0); - verify(context).saveMeasure(new Measure(CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA, "1=1;2=2;")); - verify(context).saveMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER, 2.0); - verify(context).saveMeasure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, 1.0); - verify(context).saveMeasure(new Measure(CoreMetrics.OVERALL_CONDITIONS_BY_LINE, "1=4")); - verify(context).saveMeasure(new Measure(CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE, "1=2")); - } - - @Test - public void dontFailOnBrokenValues() { - DecoratorContext context = mock(DecoratorContext.class); - File file = File.create("src/Foo.java"); - - when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(new Measure<>(CoreMetrics.LINES_TO_COVER, 10.0)); - when(context.getMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA)).thenReturn(new Measure<>(CoreMetrics.COVERAGE_LINE_HITS_DATA)); - - decorator.decorate(file, context); - - verify(context).saveMeasure(CoreMetrics.OVERALL_LINES_TO_COVER, 10.0); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java index 7648dac9e8e..823155b2d0a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java @@ -34,48 +34,13 @@ import java.util.SortedMap; */ public final class CoverageMeasuresBuilder { - /** - * @since 5.1 - */ - public static enum CoverageType { - UNIT(CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.COVERAGE_LINE_HITS_DATA, - CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS, CoreMetrics.CONDITIONS_BY_LINE, - CoreMetrics.COVERED_CONDITIONS_BY_LINE), - IT(CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.IT_COVERAGE_LINE_HITS_DATA, - CoreMetrics.IT_CONDITIONS_TO_COVER, CoreMetrics.IT_UNCOVERED_CONDITIONS, CoreMetrics.IT_CONDITIONS_BY_LINE, - CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE), - OVERALL(CoreMetrics.OVERALL_LINES_TO_COVER, CoreMetrics.OVERALL_UNCOVERED_LINES, CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA, - CoreMetrics.OVERALL_CONDITIONS_TO_COVER, CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, CoreMetrics.OVERALL_CONDITIONS_BY_LINE, - CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE); - - private final Metric linesToCover; - private final Metric uncoveredLines; - private final Metric lineHits; - private final Metric conditionsToCover; - private final Metric uncoveredConditions; - private final Metric conditionsByLine; - private final Metric coveredConditionsByLine; - - private CoverageType(Metric linesToCover, Metric uncoveredLines, Metric lineHits, Metric conditionsToCover, - Metric uncoveredConditions, Metric conditionsByLine, Metric coveredConditionsByLine) { - this.linesToCover = linesToCover; - this.uncoveredLines = uncoveredLines; - this.lineHits = lineHits; - this.conditionsToCover = conditionsToCover; - this.uncoveredConditions = uncoveredConditions; - this.conditionsByLine = conditionsByLine; - this.coveredConditionsByLine = coveredConditionsByLine; - } - - public List all() { - return Arrays.asList(linesToCover, uncoveredLines, lineHits, conditionsToCover, uncoveredConditions, conditionsByLine, coveredConditionsByLine); - } - } - /** * Metrics of generated measures */ - public static final List METRICS = CoverageType.UNIT.all(); + public static final List METRICS = Arrays.asList( + CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.COVERAGE_LINE_HITS_DATA, + CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS, CoreMetrics.CONDITIONS_BY_LINE, + CoreMetrics.COVERED_CONDITIONS_BY_LINE); private int totalCoveredLines = 0, totalConditions = 0, totalCoveredConditions = 0; private SortedMap hitsByLine = Maps.newTreeMap(); @@ -145,33 +110,29 @@ public final class CoverageMeasuresBuilder { } public Collection createMeasures() { - return createMeasures(CoverageType.UNIT); - } - - public Collection createMeasures(CoverageType type) { Collection measures = Lists.newArrayList(); if (getLinesToCover() > 0) { - measures.add(new Measure(type.linesToCover, (double) getLinesToCover())); - measures.add(new Measure(type.uncoveredLines, (double) (getLinesToCover() - getCoveredLines()))); - measures.add(new Measure(type.lineHits).setData(KeyValueFormat.format(hitsByLine)).setPersistenceMode(PersistenceMode.DATABASE)); + measures.add(new Measure(CoreMetrics.LINES_TO_COVER, (double) getLinesToCover())); + measures.add(new Measure(CoreMetrics.UNCOVERED_LINES, (double) (getLinesToCover() - getCoveredLines()))); + measures.add(new Measure(CoreMetrics.COVERAGE_LINE_HITS_DATA).setData(KeyValueFormat.format(hitsByLine)).setPersistenceMode(PersistenceMode.DATABASE)); } if (getConditions() > 0) { - measures.add(new Measure(type.conditionsToCover, (double) getConditions())); - measures.add(new Measure(type.uncoveredConditions, (double) (getConditions() - getCoveredConditions()))); - measures.add(createConditionsByLine(type)); - measures.add(createCoveredConditionsByLine(type)); + measures.add(new Measure(CoreMetrics.CONDITIONS_TO_COVER, (double) getConditions())); + measures.add(new Measure(CoreMetrics.UNCOVERED_CONDITIONS, (double) (getConditions() - getCoveredConditions()))); + measures.add(createConditionsByLine()); + measures.add(createCoveredConditionsByLine()); } return measures; } - private Measure createCoveredConditionsByLine(CoverageType type) { - return new Measure(type.coveredConditionsByLine) + private Measure createCoveredConditionsByLine() { + return new Measure(CoreMetrics.COVERED_CONDITIONS_BY_LINE) .setData(KeyValueFormat.format(coveredConditionsByLine)) .setPersistenceMode(PersistenceMode.DATABASE); } - private Measure createConditionsByLine(CoverageType type) { - return new Measure(type.conditionsByLine) + private Measure createConditionsByLine() { + return new Measure(CoreMetrics.CONDITIONS_BY_LINE) .setData(KeyValueFormat.format(conditionsByLine)) .setPersistenceMode(PersistenceMode.DATABASE); } -- cgit v1.2.3