Skip to content

Commit

Permalink
SONAR-6993 Replace hash of CpdTextBlock from a list of int to a string
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
julienlancelot committed Nov 12, 2015
1 parent dd16b88 commit c203430
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sonar-batch-protocol/src/main/protobuf/batch_report.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void read_duplication_blocks() {
.setRef(1).build());

BatchReport.CpdTextBlock duplicationBlock = BatchReport.CpdTextBlock.newBuilder()
.addAllHash(asList(1, 2, 3, 5, 7))
.setHash("abcdefghijklmnop")
.setStartLine(1)
.setEndLine(2)
.setStartTokenIndex(10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void write_duplication_blocks() {
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)
Expand All @@ -207,7 +207,7 @@ public void write_duplication_blocks() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public BatchReport.CpdTextBlock apply(Block input) {
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();
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,19 @@ public void enableCrossProjectDuplication() throws IOException {
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
Expand Down

0 comments on commit c203430

Please sign in to comment.