]> source.dussan.org Git - sonarqube.git/commitdiff
Revert SONAR-5772
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 20 Feb 2015 08:30:07 +0000 (09:30 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 20 Feb 2015 08:36:21 +0000 (09:36 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/MissingCoverageDecorator.java [deleted file]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/MissingCoverageDecoratorTest.java [deleted file]
sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java

index 602948249a4e6bc2fd5003afb1113de37965bd7d..5f00719dd5914334d0a85bb9da4fac5f5ea849f1 100644 (file)
@@ -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 (file)
index ef7ad46..0000000
+++ /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 (file)
index 45cb50c..0000000
+++ /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);
-  }
-}
index c7cb0a92db341b1d2522dc92df0bd5a32dc96664..97977cd2162d25c01c390452d27dadf47aabdb80 100644 (file)
@@ -152,16 +152,6 @@ public class CorePropertyDefinitions {
         .category(CoreProperties.CATEGORY_EXCLUSIONS)
         .subCategory(CoreProperties.SUBCATEGORY_DUPLICATIONS_EXCLUSIONS)
         .multiValues(true)
-        .build(),
-      PropertyDefinition.builder(CoreProperties.COVERAGE_UNFORCED_KEY)
-        .defaultValue("false")
-        .type(PropertyType.BOOLEAN)
-        .name("Don't force computation of test coverage")
-        .description("By default test coverage is computed for all languages even if no coverage information is provided. "
-          + "If test coverage is not applicable to your situation and you don't want to see 0% coverage on your dashboards then set this property to 'true' "
-          + "and coverage measures will only be computed when some input data are provided.")
-        .onQualifiers(Qualifiers.PROJECT)
-        .category(CoreProperties.CATEGORY_CODE_COVERAGE)
         .build()
       ));
     return defs;
index f65f046b7e14cd9035bb75f5ef817896dabb4186..296468c6ea640fe3c1b1ee497993437dd52ea2c3 100644 (file)
@@ -569,8 +569,4 @@ public interface CoreProperties {
    */
   String IMPORT_UNKNOWN_FILES_KEY = "sonar.import_unknown_files";
 
-  /**
-   * @since 5.1
-   */
-  String COVERAGE_UNFORCED_KEY = "sonar.coverage.unforced";
 }