]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6993 Replace hash of CpdTextBlock from a list of int to a string
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 10 Nov 2015 16:29:52 +0000 (17:29 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 12 Nov 2015 10:01:30 +0000 (11:01 +0100)
Having a the hash represented as a list of int in the report brings too much complexity in the compute engine, as we need only a string.

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/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java

index ae012d0fc2db8d41024af927e81497f1f4f7fc71..2913e856fb20c3e89b31bad1738aae6ad381fc06 100644 (file)
@@ -144,7 +144,7 @@ message Duplication {
 
 // Used for cross project duplication
 message CpdTextBlock {
-  repeated int32 hash = 1 [packed = true];
+  optional string hash = 1;
   optional int32 start_line = 2;
   optional int32 end_line = 3;
   optional int32 start_token_index = 4;
index 1cd26e0a34b2fd74fed4f88f17dae9941c26d9ec..8a1d8f126da76088cb1686ebb045df7873b3bc83 100644 (file)
@@ -181,7 +181,7 @@ public class BatchReportReaderTest {
       .setRef(1).build());
 
     BatchReport.CpdTextBlock duplicationBlock = BatchReport.CpdTextBlock.newBuilder()
-      .addAllHash(asList(1, 2, 3, 5, 7))
+      .setHash("abcdefghijklmnop")
       .setStartLine(1)
       .setEndLine(2)
       .setStartTokenIndex(10)
index 13f0765c83ed4338bbd21cfcad6dc9d67ca5797f..9af4b5dd6a644cee5925e898ff5166f2eac611fb 100644 (file)
@@ -194,7 +194,7 @@ public class BatchReportWriterTest {
     assertThat(underTest.hasComponentData(FileStructure.Domain.CPD_TEXT_BLOCKS, 1)).isFalse();
 
     BatchReport.CpdTextBlock duplicationBlock = BatchReport.CpdTextBlock.newBuilder()
-      .addAllHash(asList(1, 2, 3, 5, 7))
+      .setHash("abcdefghijklmnop")
       .setStartLine(1)
       .setEndLine(2)
       .setStartTokenIndex(10)
@@ -207,7 +207,7 @@ public class BatchReportWriterTest {
     assertThat(file).exists().isFile();
     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.getHash()).isEqualTo("abcdefghijklmnop");
       assertThat(duplicationBlockResult.getStartLine()).isEqualTo(1);
       assertThat(duplicationBlockResult.getEndLine()).isEqualTo(2);
       assertThat(duplicationBlockResult.getStartTokenIndex()).isEqualTo(10);
index ca331ebeb2cbe793d34b200d3f5f764c85dd2b10..f5872efdd505969394729d2a40f1ea5a20d29ede 100644 (file)
@@ -60,9 +60,7 @@ public class SonarDuplicationsIndex extends AbstractCloneIndex {
           builder.setEndLine(input.getEndLine());
           builder.setStartTokenIndex(input.getStartUnit());
           builder.setEndTokenIndex(input.getEndUnit());
-          for (int i : input.getBlockHash().toIntArray()) {
-            builder.addHash(i);
-          }
+          builder.setHash(input.getBlockHash().toHexString());
           return builder.build();
         }
       }));
index acc0f5255acaeaa9f693975d083ebb019df66915..bb41a88d7e651bda8ca9b862f5cc737b1ce70a5e 100644 (file)
@@ -158,19 +158,19 @@ public class CpdMediumTest {
     assertThat(duplicationBlocks.get(0).getEndLine()).isEqualTo(5);
     assertThat(duplicationBlocks.get(0).getStartTokenIndex()).isEqualTo(1);
     assertThat(duplicationBlocks.get(0).getEndTokenIndex()).isEqualTo(6);
-    assertThat(duplicationBlocks.get(0).getHashList()).isNotEmpty();
+    assertThat(duplicationBlocks.get(0).getHash()).isNotEmpty();
 
     assertThat(duplicationBlocks.get(1).getStartLine()).isEqualTo(2);
     assertThat(duplicationBlocks.get(1).getEndLine()).isEqualTo(6);
     assertThat(duplicationBlocks.get(1).getStartTokenIndex()).isEqualTo(3);
     assertThat(duplicationBlocks.get(1).getEndTokenIndex()).isEqualTo(7);
-    assertThat(duplicationBlocks.get(0).getHashList()).isNotEmpty();
+    assertThat(duplicationBlocks.get(0).getHash()).isNotEmpty();
 
     assertThat(duplicationBlocks.get(2).getStartLine()).isEqualTo(3);
     assertThat(duplicationBlocks.get(2).getEndLine()).isEqualTo(7);
     assertThat(duplicationBlocks.get(2).getStartTokenIndex()).isEqualTo(4);
     assertThat(duplicationBlocks.get(2).getEndTokenIndex()).isEqualTo(8);
-    assertThat(duplicationBlocks.get(0).getHashList()).isNotEmpty();
+    assertThat(duplicationBlocks.get(0).getHash()).isNotEmpty();
   }
 
   // SONAR-6000