diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-20 09:30:07 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-20 09:36:21 +0100 |
commit | 464054561f5ce5ca9c48f36684774cd3eb98338b (patch) | |
tree | 0a80d778d19ab8e8c1e5bf43cd8b2dd56d9105f6 /plugins/sonar-core-plugin/src | |
parent | 272fb51fc5f7dcbef163938c3230ef1e4f87640a (diff) | |
download | sonarqube-464054561f5ce5ca9c48f36684774cd3eb98338b.tar.gz sonarqube-464054561f5ce5ca9c48f36684774cd3eb98338b.zip |
Revert SONAR-5772
Diffstat (limited to 'plugins/sonar-core-plugin/src')
3 files changed, 0 insertions, 213 deletions
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 602948249a4..5f00719dd59 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,7 +48,6 @@ import org.sonar.plugins.core.sensors.ItCoverageDecorator; import org.sonar.plugins.core.sensors.ItLineCoverageDecorator; import org.sonar.plugins.core.sensors.LineCoverageDecorator; import org.sonar.plugins.core.sensors.ManualMeasureDecorator; -import org.sonar.plugins.core.sensors.MissingCoverageDecorator; import org.sonar.plugins.core.sensors.MissingOverallCoverageDecorator; import org.sonar.plugins.core.sensors.OverallBranchCoverageDecorator; import org.sonar.plugins.core.sensors.OverallCoverageDecorator; @@ -337,7 +336,6 @@ public final class CorePlugin extends SonarPlugin { DirectoriesDecorator.class, FilesDecorator.class, ManualMeasureDecorator.class, - MissingCoverageDecorator.class, MissingOverallCoverageDecorator.class, // time machine diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/MissingCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/MissingCoverageDecorator.java deleted file mode 100644 index ef7ad46fd04..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/MissingCoverageDecorator.java +++ /dev/null @@ -1,91 +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.CoreProperties; -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.config.Settings; -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 org.sonar.api.utils.KeyValueFormat; - -import java.util.Map; - -/** - * Compute coverage when it was not already saved by language plugin. - */ -public final class MissingCoverageDecorator implements Decorator { - - private final Settings settings; - - public MissingCoverageDecorator(Settings settings) { - this.settings = settings; - } - - @DependsUpon - public Metric dependsUpon() { - return CoreMetrics.NCLOC; - } - - @DependedUpon - public Metric provides() { - return CoreMetrics.LINES_TO_COVER; - } - - @Override - public boolean shouldExecuteOnProject(Project project) { - return !settings.getBoolean(CoreProperties.COVERAGE_UNFORCED_KEY); - } - - @Override - public void decorate(Resource resource, DecoratorContext context) { - if (Qualifiers.isFile(resource)) { - if (!MeasureUtils.hasValue(context.getMeasure(CoreMetrics.LINES_TO_COVER))) { - Measure nclocData = context.getMeasure(CoreMetrics.NCLOC_DATA); - if (MeasureUtils.hasData(nclocData)) { - CoverageMeasuresBuilder builder = CoverageMeasuresBuilder.create(); - Map<Integer, Integer> nclocByLine = KeyValueFormat.parseIntInt(nclocData.getData()); - for (Map.Entry<Integer, Integer> entry : nclocByLine.entrySet()) { - if (entry.getValue() == 1) { - builder.setHits(entry.getKey(), 0); - } - } - for (Measure m : builder.createMeasures()) { - context.saveMeasure(m); - } - } else { - // No details about ncloc so fallback on setting high level metrics - double ncloc = MeasureUtils.getValue(context.getMeasure(CoreMetrics.NCLOC), 0.0); - context.saveMeasure(CoreMetrics.LINES_TO_COVER, ncloc); - context.saveMeasure(CoreMetrics.UNCOVERED_LINES, ncloc); - } - } - } - } -} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/MissingCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/MissingCoverageDecoratorTest.java deleted file mode 100644 index 45cb50cfd07..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/MissingCoverageDecoratorTest.java +++ /dev/null @@ -1,120 +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.CoreProperties; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.Settings; -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 org.sonar.core.config.CorePropertyDefinitions; - -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 MissingCoverageDecoratorTest { - - private Settings settings; - private MissingCoverageDecorator decorator; - - @Before - public void prepare() { - settings = new Settings(new PropertyDefinitions(CorePropertyDefinitions.all())); - decorator = new MissingCoverageDecorator(settings); - } - - @Test - public void increaseCoverage() { - assertThat(decorator.provides()).isEqualTo(CoreMetrics.LINES_TO_COVER); - assertThat(decorator.dependsUpon()).isEqualTo(CoreMetrics.NCLOC); - } - - @Test - public void testShouldExecute() { - assertThat(decorator.shouldExecuteOnProject(new Project("foo"))).isTrue(); - settings.setProperty(CoreProperties.COVERAGE_UNFORCED_KEY, "true"); - assertThat(decorator.shouldExecuteOnProject(new Project("foo"))).isFalse(); - } - - @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 dontDoAnythingIfLinesToCoverAlreadyDefined() { - 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, 0.0)); - when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure<>(CoreMetrics.NCLOC, 10.0)); - - decorator.decorate(file, context); - - verify(context, never()).saveMeasure(eq(CoreMetrics.LINES_TO_COVER), anyDouble()); - verify(context, never()).saveMeasure(eq(CoreMetrics.UNCOVERED_LINES), anyDouble()); - } - - @Test - public void testUseNclocDataIfPossible() { - DecoratorContext context = mock(DecoratorContext.class); - File file = File.create("src/Foo.java"); - - when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(null); - when(context.getMeasure(CoreMetrics.NCLOC_DATA)).thenReturn(new Measure<>(CoreMetrics.NCLOC_DATA, "1=0;2=1;3=0;4=1")); - - decorator.decorate(file, context); - - verify(context).saveMeasure(new Measure(CoreMetrics.LINES_TO_COVER, 2.0)); - verify(context).saveMeasure(new Measure(CoreMetrics.UNCOVERED_LINES, 2.0)); - verify(context).saveMeasure(new Measure(CoreMetrics.COVERAGE_LINE_HITS_DATA, "2=0;4=0")); - } - - @Test - public void testUseNclocAsLinesToCover() { - DecoratorContext context = mock(DecoratorContext.class); - File file = File.create("src/Foo.java"); - - when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(null); - when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure<>(CoreMetrics.NCLOC, 10.0)); - - decorator.decorate(file, context); - - verify(context).saveMeasure(CoreMetrics.LINES_TO_COVER, 10.0); - verify(context).saveMeasure(CoreMetrics.UNCOVERED_LINES, 10.0); - } -} |