]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6993 Rename DuplicationBlock into CpdTextBlock
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 10 Nov 2015 16:44:56 +0000 (17:44 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 12 Nov 2015 10:01:30 +0000 (11:01 +0100)
13 files changed:
server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReader.java
server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java
server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderRule.java
sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java
sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java
sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/FileStructure.java
sonar-batch-protocol/src/main/protobuf/batch_report.proto
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java
sonar-batch/src/main/java/org/sonar/batch/cpd/index/SonarDuplicationsIndex.java
sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java

index 9fd55110cc3194da63b6387e2189413cef144796..8d7177b408c1ff69f17ae14dc656ea0f3a1690fa 100644 (file)
@@ -42,7 +42,7 @@ public interface BatchReportReader {
 
   CloseableIterator<BatchReport.Duplication> readComponentDuplications(int componentRef);
 
-  CloseableIterator<BatchReport.DuplicationBlock> readComponentDuplicationBlocks(int componentRef);
+  CloseableIterator<BatchReport.CpdTextBlock> readCpdTextBlocks(int componentRef);
 
   CloseableIterator<BatchReport.Symbol> readComponentSymbols(int componentRef);
 
index 392f69d39b2837b70308b9929f443463ed27ca7c..ee574986dbee80169d6689b0ca1533b7f4f8f299 100644 (file)
@@ -100,8 +100,8 @@ public class BatchReportReaderImpl implements BatchReportReader {
   }
 
   @Override
-  public CloseableIterator<BatchReport.DuplicationBlock> readComponentDuplicationBlocks(int componentRef) {
-    return delegate.readComponentDuplicationBlocks(componentRef);
+  public CloseableIterator<BatchReport.CpdTextBlock> readCpdTextBlocks(int componentRef) {
+    return delegate.readCpdTextBlocks(componentRef);
   }
 
   @Override
index f561215ed1b5a48dfb8cdb384bb348acdf3f3ca6..0a12831269c87fff8d716b023da239ffb95c2927 100644 (file)
@@ -41,7 +41,7 @@ public class BatchReportReaderImplTest {
   private static final BatchReport.Component COMPONENT = BatchReport.Component.newBuilder().setRef(COMPONENT_REF).build();
   private static final BatchReport.Issue ISSUE = BatchReport.Issue.newBuilder().build();
   private static final BatchReport.Duplication DUPLICATION = BatchReport.Duplication.newBuilder().build();
-  private static final BatchReport.DuplicationBlock DUPLICATION_BLOCK = BatchReport.DuplicationBlock.newBuilder().build();
+  private static final BatchReport.CpdTextBlock DUPLICATION_BLOCK = BatchReport.CpdTextBlock.newBuilder().build();
   private static final BatchReport.Symbol SYMBOL = BatchReport.Symbol.newBuilder().build();
   private static final BatchReport.SyntaxHighlighting SYNTAX_HIGHLIGHTING_1 = BatchReport.SyntaxHighlighting.newBuilder().build();
   private static final BatchReport.SyntaxHighlighting SYNTAX_HIGHLIGHTING_2 = BatchReport.SyntaxHighlighting.newBuilder().build();
@@ -203,14 +203,14 @@ public class BatchReportReaderImplTest {
 
   @Test
   public void readComponentDuplicationBlocks_returns_empty_list_if_file_does_not_exist() {
-    assertThat(underTest.readComponentDuplicationBlocks(COMPONENT_REF)).isEmpty();
+    assertThat(underTest.readCpdTextBlocks(COMPONENT_REF)).isEmpty();
   }
 
   @Test
   public void verify_readComponentDuplicationBlocks_returns_Issues() {
-    writer.writeDuplicationBlocks(COMPONENT_REF, of(DUPLICATION_BLOCK));
+    writer.writeCpdTextBlocks(COMPONENT_REF, of(DUPLICATION_BLOCK));
 
-    try (CloseableIterator<BatchReport.DuplicationBlock> res = underTest.readComponentDuplicationBlocks(COMPONENT_REF)) {
+    try (CloseableIterator<BatchReport.CpdTextBlock> res = underTest.readCpdTextBlocks(COMPONENT_REF)) {
       assertThat(res.next()).isEqualTo(DUPLICATION_BLOCK);
       assertThat(res.hasNext()).isFalse();
     }
@@ -218,9 +218,9 @@ public class BatchReportReaderImplTest {
 
   @Test
   public void readComponentDuplicationBlocks_is_not_cached() {
-    writer.writeDuplicationBlocks(COMPONENT_REF, of(DUPLICATION_BLOCK));
+    writer.writeCpdTextBlocks(COMPONENT_REF, of(DUPLICATION_BLOCK));
 
-    assertThat(underTest.readComponentDuplicationBlocks(COMPONENT_REF)).isNotSameAs(underTest.readComponentDuplicationBlocks(COMPONENT_REF));
+    assertThat(underTest.readCpdTextBlocks(COMPONENT_REF)).isNotSameAs(underTest.readCpdTextBlocks(COMPONENT_REF));
   }
 
   @Test
index 579e333d70acb51e1da6bbfd4733e0ed0e3fbedf..e4dcbe41944b75ff3c245f7939446c43b2342f66 100644 (file)
@@ -43,7 +43,7 @@ public class BatchReportReaderRule implements TestRule, BatchReportReader {
   private Map<Integer, BatchReport.Component> components = new HashMap<>();
   private Map<Integer, List<BatchReport.Issue>> issues = new HashMap<>();
   private Map<Integer, List<BatchReport.Duplication>> duplications = new HashMap<>();
-  private Map<Integer, List<BatchReport.DuplicationBlock>> duplicationBlocks = new HashMap<>();
+  private Map<Integer, List<BatchReport.CpdTextBlock>> duplicationBlocks = new HashMap<>();
   private Map<Integer, List<BatchReport.Symbol>> symbols = new HashMap<>();
   private Map<Integer, List<BatchReport.SyntaxHighlighting>> syntaxHighlightings = new HashMap<>();
   private Map<Integer, List<BatchReport.Coverage>> coverages = new HashMap<>();
@@ -177,11 +177,11 @@ public class BatchReportReaderRule implements TestRule, BatchReportReader {
   }
 
   @Override
-  public CloseableIterator<BatchReport.DuplicationBlock> readComponentDuplicationBlocks(int componentRef) {
+  public CloseableIterator<BatchReport.CpdTextBlock> readCpdTextBlocks(int componentRef) {
     return closeableIterator(this.duplicationBlocks.get(componentRef));
   }
 
-  public BatchReportReaderRule putDuplicationBlocks(int componentRef, List<BatchReport.DuplicationBlock> duplicationBlocks) {
+  public BatchReportReaderRule putDuplicationBlocks(int componentRef, List<BatchReport.CpdTextBlock> duplicationBlocks) {
     this.duplicationBlocks.put(componentRef, duplicationBlocks);
     return this;
   }
index 786fcaaa9fb9c3b0684fe992dbacc030a230c48a..89af7f43e746cf8e2ffbee98206bf6e02ceb5471 100644 (file)
@@ -91,10 +91,10 @@ public class BatchReportReader {
     return emptyCloseableIterator();
   }
 
-  public CloseableIterator<BatchReport.DuplicationBlock> readComponentDuplicationBlocks(int componentRef) {
-    File file = fileStructure.fileFor(FileStructure.Domain.DUPLICATION_BLOCKS, componentRef);
+  public CloseableIterator<BatchReport.CpdTextBlock> readCpdTextBlocks(int componentRef) {
+    File file = fileStructure.fileFor(FileStructure.Domain.CPD_TEXT_BLOCKS, componentRef);
     if (fileExists(file)) {
-      return Protobuf.readStream(file, BatchReport.DuplicationBlock.parser());
+      return Protobuf.readStream(file, BatchReport.CpdTextBlock.parser());
     }
     return emptyCloseableIterator();
   }
index 224bfdd6935f517a17a0c029c303b56b0bd9a67a..7faabbb2d15d54949967fb0982b8b66186d28ed5 100644 (file)
@@ -98,9 +98,9 @@ public class BatchReportWriter {
     return file;
   }
 
-  public File writeDuplicationBlocks(int componentRef, Iterable<BatchReport.DuplicationBlock> duplicationBlocks) {
-    File file = fileStructure.fileFor(FileStructure.Domain.DUPLICATION_BLOCKS, componentRef);
-    Protobuf.writeStream(duplicationBlocks, file, false);
+  public File writeCpdTextBlocks(int componentRef, Iterable<BatchReport.CpdTextBlock> blocks) {
+    File file = fileStructure.fileFor(FileStructure.Domain.CPD_TEXT_BLOCKS, componentRef);
+    Protobuf.writeStream(blocks, file, false);
     return file;
   }
 
index 23575dcdec652d77c2dfd6ce9d85969762591ea7..9f4e8014e11e7ed4f05d31b73abc1fdab8255076 100644 (file)
@@ -31,7 +31,7 @@ public class FileStructure {
     COMPONENT("component-", Domain.PB),
     MEASURES("measures-", Domain.PB),
     DUPLICATIONS("duplications-", Domain.PB),
-    DUPLICATION_BLOCKS("duplication-blocks-", Domain.PB),
+    CPD_TEXT_BLOCKS("cpd-text-block-", Domain.PB),
     SYNTAX_HIGHLIGHTINGS("syntax-highlightings-", Domain.PB),
     CHANGESETS("changesets-", Domain.PB),
     SYMBOLS("symbols-", Domain.PB),
index 7937353fe9fbd9e9b6c414e9018e6be05e80b8bf..ae012d0fc2db8d41024af927e81497f1f4f7fc71 100644 (file)
@@ -143,7 +143,7 @@ message Duplication {
 }
 
 // Used for cross project duplication
-message DuplicationBlock {
+message CpdTextBlock {
   repeated int32 hash = 1 [packed = true];
   optional int32 start_line = 2;
   optional int32 end_line = 3;
index 3c2c5ac5da98794b458e2f0cc6e30a0153962290..1cd26e0a34b2fd74fed4f88f17dae9941c26d9ec 100644 (file)
@@ -180,17 +180,17 @@ public class BatchReportReaderTest {
     writer.writeComponent(BatchReport.Component.newBuilder()
       .setRef(1).build());
 
-    BatchReport.DuplicationBlock duplicationBlock = BatchReport.DuplicationBlock.newBuilder()
+    BatchReport.CpdTextBlock duplicationBlock = BatchReport.CpdTextBlock.newBuilder()
       .addAllHash(asList(1, 2, 3, 5, 7))
       .setStartLine(1)
       .setEndLine(2)
       .setStartTokenIndex(10)
       .setEndTokenIndex(15)
       .build();
-    writer.writeDuplicationBlocks(1, singletonList(duplicationBlock));
+    writer.writeCpdTextBlocks(1, singletonList(duplicationBlock));
 
     BatchReportReader sut = new BatchReportReader(dir);
-    assertThat(sut.readComponentDuplicationBlocks(1)).hasSize(1);
+    assertThat(sut.readCpdTextBlocks(1)).hasSize(1);
   }
 
   @Test
index fdd1ba2b67b9d06215bf643aa9fb93c0c9725fcd..13f0765c83ed4338bbd21cfcad6dc9d67ca5797f 100644 (file)
@@ -191,22 +191,22 @@ public class BatchReportWriterTest {
 
   @Test
   public void write_duplication_blocks() {
-    assertThat(underTest.hasComponentData(FileStructure.Domain.DUPLICATION_BLOCKS, 1)).isFalse();
+    assertThat(underTest.hasComponentData(FileStructure.Domain.CPD_TEXT_BLOCKS, 1)).isFalse();
 
-    BatchReport.DuplicationBlock duplicationBlock = BatchReport.DuplicationBlock.newBuilder()
+    BatchReport.CpdTextBlock duplicationBlock = BatchReport.CpdTextBlock.newBuilder()
       .addAllHash(asList(1, 2, 3, 5, 7))
       .setStartLine(1)
       .setEndLine(2)
       .setStartTokenIndex(10)
       .setEndTokenIndex(15)
       .build();
-    underTest.writeDuplicationBlocks(1, asList(duplicationBlock));
+    underTest.writeCpdTextBlocks(1, asList(duplicationBlock));
 
-    assertThat(underTest.hasComponentData(FileStructure.Domain.DUPLICATION_BLOCKS, 1)).isTrue();
-    File file = underTest.getFileStructure().fileFor(FileStructure.Domain.DUPLICATION_BLOCKS, 1);
+    assertThat(underTest.hasComponentData(FileStructure.Domain.CPD_TEXT_BLOCKS, 1)).isTrue();
+    File file = underTest.getFileStructure().fileFor(FileStructure.Domain.CPD_TEXT_BLOCKS, 1);
     assertThat(file).exists().isFile();
-    try (CloseableIterator<BatchReport.DuplicationBlock> duplicationBlocks = Protobuf.readStream(file, BatchReport.DuplicationBlock.parser())) {
-      BatchReport.DuplicationBlock duplicationBlockResult = duplicationBlocks.next();
+    try (CloseableIterator<BatchReport.CpdTextBlock> duplicationBlocks = Protobuf.readStream(file, BatchReport.CpdTextBlock.parser())) {
+      BatchReport.CpdTextBlock duplicationBlockResult = duplicationBlocks.next();
       assertThat(duplicationBlockResult.getHashList()).containsOnly(1, 2, 3, 5, 7);
       assertThat(duplicationBlockResult.getStartLine()).isEqualTo(1);
       assertThat(duplicationBlockResult.getEndLine()).isEqualTo(2);
index 51a094a869e4efa80be5449fcd895304b21f5a27..ca331ebeb2cbe793d34b200d3f5f764c85dd2b10 100644 (file)
@@ -28,7 +28,6 @@ import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.config.Settings;
 import org.sonar.batch.index.BatchComponentCache;
 import org.sonar.batch.protocol.output.BatchReport;
-import org.sonar.batch.protocol.output.BatchReport.DuplicationBlock;
 import org.sonar.batch.report.ReportPublisher;
 import org.sonar.duplications.block.Block;
 import org.sonar.duplications.block.ByteArray;
@@ -52,10 +51,10 @@ public class SonarDuplicationsIndex extends AbstractCloneIndex {
   public void insert(InputFile inputFile, Collection<Block> blocks) {
     if (isCrossProjectDuplicationEnabled(settings)) {
       int id = batchComponentCache.get(inputFile).batchId();
-      final BatchReport.DuplicationBlock.Builder builder = BatchReport.DuplicationBlock.newBuilder();
-      publisher.getWriter().writeDuplicationBlocks(id, Iterables.transform(blocks, new Function<Block, BatchReport.DuplicationBlock>() {
+      final BatchReport.CpdTextBlock.Builder builder = BatchReport.CpdTextBlock.newBuilder();
+      publisher.getWriter().writeCpdTextBlocks(id, Iterables.transform(blocks, new Function<Block, BatchReport.CpdTextBlock>() {
         @Override
-        public DuplicationBlock apply(Block input) {
+        public BatchReport.CpdTextBlock apply(Block input) {
           builder.clear();
           builder.setStartLine(input.getStartLine());
           builder.setEndLine(input.getEndLine());
index 2254fa0798fd83c051c5887f3b31809886c1ac73..d823886ad08f10e25d0aac1cc7ab8bc0ca4bd26b 100644 (file)
  */
 package org.sonar.batch.mediumtest;
 
-import org.sonar.batch.issue.tracking.TrackedIssue;
-
 import com.google.common.collect.Iterators;
 import com.google.common.collect.Lists;
-
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -31,10 +28,8 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-
 import org.apache.commons.io.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -48,6 +43,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputDir;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.sensor.highlighting.TypeOfText;
 import org.sonar.batch.issue.IssueCache;
+import org.sonar.batch.issue.tracking.TrackedIssue;
 import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.batch.protocol.output.BatchReport.Component;
 import org.sonar.batch.protocol.output.BatchReport.Metadata;
@@ -231,10 +227,10 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
     return result;
   }
 
-  public List<BatchReport.DuplicationBlock> duplicationBlocksFor(InputFile file) {
-    List<BatchReport.DuplicationBlock> result = new ArrayList<>();
+  public List<BatchReport.CpdTextBlock> duplicationBlocksFor(InputFile file) {
+    List<BatchReport.CpdTextBlock> result = new ArrayList<>();
     int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef();
-    try (CloseableIterator<BatchReport.DuplicationBlock> it = getReportReader().readComponentDuplicationBlocks(ref)) {
+    try (CloseableIterator<BatchReport.CpdTextBlock> it = getReportReader().readCpdTextBlocks(ref)) {
       while (it.hasNext()) {
         result.add(it.next());
       }
index 2e734e0063df225514b64dacb4e80377fb76277a..acc0f5255acaeaa9f693975d083ebb019df66915 100644 (file)
@@ -37,7 +37,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.batch.mediumtest.BatchMediumTester;
 import org.sonar.batch.mediumtest.TaskResult;
-import org.sonar.batch.protocol.output.BatchReport.DuplicationBlock;
+import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.batch.protocol.output.BatchReport.Measure;
 import org.sonar.xoo.XooPlugin;
 
@@ -152,7 +152,7 @@ public class CpdMediumTest {
 
     InputFile inputFile1 = result.inputFile("src/sample1.xoo");
 
-    List<DuplicationBlock> duplicationBlocks = result.duplicationBlocksFor(inputFile1);
+    List<BatchReport.CpdTextBlock> duplicationBlocks = result.duplicationBlocksFor(inputFile1);
     assertThat(duplicationBlocks).hasSize(3);
     assertThat(duplicationBlocks.get(0).getStartLine()).isEqualTo(1);
     assertThat(duplicationBlocks.get(0).getEndLine()).isEqualTo(5);