]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6991 remove batch code generating duplicate_* measures 625/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 10 Nov 2015 09:55:57 +0000 (10:55 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 10 Nov 2015 15:36:01 +0000 (16:36 +0100)
sonar-batch/src/main/java/org/sonar/batch/cpd/JavaCpdEngine.java
sonar-batch/src/test/java/org/sonar/batch/cpd/JavaCpdEngineTest.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java

index 1adca4f11cace27e3aa4310679e5f3ce08a450f9..21bec46e794ec931dcfb5911996ee2a87eac9d5c 100644 (file)
@@ -27,9 +27,7 @@ import java.io.FileNotFoundException;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.util.Collection;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
@@ -48,9 +46,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.sensor.SensorContext;
 import org.sonar.api.batch.sensor.duplication.NewDuplication;
 import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication;
-import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
 import org.sonar.api.config.Settings;
-import org.sonar.api.measures.CoreMetrics;
 import org.sonar.batch.cpd.index.SonarDuplicationsIndex;
 import org.sonar.batch.index.BatchComponentCache;
 import org.sonar.batch.report.ReportPublisher;
@@ -188,33 +184,10 @@ public class JavaCpdEngine extends CpdEngine {
     if (duplications == null || Iterables.isEmpty(duplications)) {
       return;
     }
-    computeBlockAndLineCount(context, inputFile, duplications);
 
     saveDuplications(context, inputFile, duplications);
   }
 
-  private static void saveMeasures(org.sonar.api.batch.sensor.SensorContext context, InputFile inputFile, int duplicatedLines, int duplicatedBlocks) {
-    // Save
-    ((DefaultMeasure<Integer>) context.<Integer>newMeasure()
-      .forMetric(CoreMetrics.DUPLICATED_FILES)
-      .on(inputFile)
-      .withValue(1))
-        .setFromCore()
-        .save();
-    ((DefaultMeasure<Integer>) context.<Integer>newMeasure()
-      .forMetric(CoreMetrics.DUPLICATED_LINES)
-      .on(inputFile)
-      .withValue(duplicatedLines))
-        .setFromCore()
-        .save();
-    ((DefaultMeasure<Integer>) context.<Integer>newMeasure()
-      .forMetric(CoreMetrics.DUPLICATED_BLOCKS)
-      .on(inputFile)
-      .withValue(duplicatedBlocks))
-        .setFromCore()
-        .save();
-  }
-
   private static void saveDuplications(org.sonar.api.batch.sensor.SensorContext context, InputFile inputFile, Iterable<CloneGroup> duplications) {
     int cloneGroupCount = 0;
     for (CloneGroup duplication : duplications) {
@@ -242,21 +215,4 @@ public class JavaCpdEngine extends CpdEngine {
     }
   }
 
-  private static void computeBlockAndLineCount(org.sonar.api.batch.sensor.SensorContext context, InputFile inputFile, Iterable<CloneGroup> duplications) {
-    int duplicatedBlocks = 0;
-    Set<Integer> duplicatedLines = new HashSet<>();
-    for (CloneGroup clone : duplications) {
-      ClonePart origin = clone.getOriginPart();
-      for (ClonePart part : clone.getCloneParts()) {
-        if (part.getResourceId().equals(origin.getResourceId())) {
-          duplicatedBlocks++;
-          for (int duplicatedLine = part.getStartLine(); duplicatedLine < part.getStartLine() + part.getLines(); duplicatedLine++) {
-            duplicatedLines.add(duplicatedLine);
-          }
-        }
-      }
-    }
-    saveMeasures(context, inputFile, duplicatedLines.size(), duplicatedBlocks);
-  }
-
 }
index f3b802da8e6dfdb1dbf1352fa1111141ea8791d4..ea02cec106483e5c264c6d5d20a990b2915d3cbd 100644 (file)
@@ -36,7 +36,6 @@ import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.batch.sensor.measure.Measure;
 import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
-import org.sonar.api.measures.CoreMetrics;
 import org.sonar.duplications.index.CloneGroup;
 import org.sonar.duplications.index.ClonePart;
 
@@ -87,10 +86,6 @@ public class JavaCpdEngineTest {
     List<CloneGroup> groups = Arrays.asList(newCloneGroup(new ClonePart("key1", 0, 2, 4), new ClonePart("key2", 0, 15, 17)));
     JavaCpdEngine.save(context, inputFile, groups);
 
-    verify(storage).store(new DefaultMeasure().forMetric(CoreMetrics.DUPLICATED_FILES).on(inputFile).withValue(1));
-    verify(storage).store(new DefaultMeasure().forMetric(CoreMetrics.DUPLICATED_BLOCKS).on(inputFile).withValue(1));
-    verify(storage).store(new DefaultMeasure().forMetric(CoreMetrics.DUPLICATED_LINES).on(inputFile).withValue(3));
-
     verify(storage).store(new DefaultDuplication()
       .originBlock(inputFile, 2, 4)
       .isDuplicatedBy("key2", 15, 17));
@@ -101,10 +96,6 @@ public class JavaCpdEngineTest {
     List<CloneGroup> groups = Arrays.asList(newCloneGroup(new ClonePart("key1", 0, 5, 204), new ClonePart("key1", 0, 215, 414)));
     JavaCpdEngine.save(context, inputFile, groups);
 
-    verify(storage).store(new DefaultMeasure().forMetric(CoreMetrics.DUPLICATED_FILES).on(inputFile).withValue(1));
-    verify(storage).store(new DefaultMeasure().forMetric(CoreMetrics.DUPLICATED_BLOCKS).on(inputFile).withValue(2));
-    verify(storage).store(new DefaultMeasure().forMetric(CoreMetrics.DUPLICATED_LINES).on(inputFile).withValue(400));
-
     verify(storage).store(new DefaultDuplication()
       .originBlock(inputFile, 5, 204)
       .isDuplicatedBy("key1", 215, 414));
@@ -115,10 +106,6 @@ public class JavaCpdEngineTest {
     List<CloneGroup> groups = Arrays.asList(newCloneGroup(new ClonePart("key1", 0, 5, 204), new ClonePart("key2", 0, 15, 214), new ClonePart("key3", 0, 25, 224)));
     JavaCpdEngine.save(context, inputFile, groups);
 
-    verify(storage).store(new DefaultMeasure().forMetric(CoreMetrics.DUPLICATED_FILES).on(inputFile).withValue(1));
-    verify(storage).store(new DefaultMeasure().forMetric(CoreMetrics.DUPLICATED_BLOCKS).on(inputFile).withValue(1));
-    verify(storage).store(new DefaultMeasure().forMetric(CoreMetrics.DUPLICATED_LINES).on(inputFile).withValue(200));
-
     verify(storage).store(new DefaultDuplication()
       .originBlock(inputFile, 5, 204)
       .isDuplicatedBy("key2", 15, 214)
@@ -132,10 +119,6 @@ public class JavaCpdEngineTest {
       newCloneGroup(new ClonePart("key1", 0, 15, 214), new ClonePart("key3", 0, 15, 214)));
     JavaCpdEngine.save(context, inputFile, groups);
 
-    verify(storage).store(new DefaultMeasure().forMetric(CoreMetrics.DUPLICATED_FILES).on(inputFile).withValue(1));
-    verify(storage).store(new DefaultMeasure().forMetric(CoreMetrics.DUPLICATED_BLOCKS).on(inputFile).withValue(2));
-    verify(storage).store(new DefaultMeasure().forMetric(CoreMetrics.DUPLICATED_LINES).on(inputFile).withValue(210));
-
     verify(storage).store(new DefaultDuplication()
       .originBlock(inputFile, 5, 204)
       .isDuplicatedBy("key2", 15, 214));
index 7a0c260e4f72b99d002fb087ad2dabdb8d124dba..2e734e0063df225514b64dacb4e80377fb76277a 100644 (file)
@@ -42,7 +42,6 @@ import org.sonar.batch.protocol.output.BatchReport.Measure;
 import org.sonar.xoo.XooPlugin;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.tuple;
 
 public class CpdMediumTest {
 
@@ -105,10 +104,6 @@ public class CpdMediumTest {
     assertThat(result.inputFiles()).hasSize(2);
 
     Map<String, List<org.sonar.batch.protocol.output.BatchReport.Measure>> allMeasures = result.allMeasures();
-    assertThat(allMeasures.get("com.foo.project:src/sample1.xoo")).extracting("metricKey", "intValue")
-      .contains(tuple("duplicated_blocks", 1),
-        tuple("duplicated_files", 1),
-        tuple("duplicated_lines", 17));
 
     InputFile inputFile1 = result.inputFile("src/sample1.xoo");
     InputFile inputFile2 = result.inputFile("src/sample2.xoo");
@@ -208,10 +203,7 @@ public class CpdMediumTest {
         "[{\"key\":\"Sonar Way\",\"language\":\"xoo\",\"name\":\"Sonar Way\",\"rulesUpdatedAt\":\"2009-02-13T23:31:31+0000\"}]"));
 
     assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue").containsOnly(
-      Tuple.tuple(CoreMetrics.LINES_KEY, blockCount * 2 + 1),
-      Tuple.tuple(CoreMetrics.DUPLICATED_FILES_KEY, 1),
-      Tuple.tuple(CoreMetrics.DUPLICATED_BLOCKS_KEY, blockCount),
-      Tuple.tuple(CoreMetrics.DUPLICATED_LINES_KEY, blockCount));
+      Tuple.tuple(CoreMetrics.LINES_KEY, blockCount * 2 + 1));
 
     List<org.sonar.batch.protocol.output.BatchReport.Duplication> duplicationGroups = result.duplicationsFor(result.inputFile("src/sample.xoo"));
     assertThat(duplicationGroups).hasSize(1);
@@ -239,12 +231,6 @@ public class CpdMediumTest {
         .build())
       .start();
 
-    Map<String, List<org.sonar.batch.protocol.output.BatchReport.Measure>> allMeasures = result.allMeasures();
-    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue")
-      .contains(tuple("duplicated_blocks", 2),
-        tuple("duplicated_files", 1),
-        tuple("duplicated_lines", 4));
-
     InputFile inputFile = result.inputFile("src/sample.xoo");
     // One clone group
     List<org.sonar.batch.protocol.output.BatchReport.Duplication> duplicationGroups = result.duplicationsFor(inputFile);