diff options
13 files changed, 39 insertions, 44 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReader.java b/server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReader.java index 9fd55110cc3..8d7177b408c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReader.java @@ -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); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java index 392f69d39b2..ee574986dbe 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderImplTest.java index f561215ed1b..0a12831269c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderImplTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderRule.java index 579e333d70a..e4dcbe41944 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderRule.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderRule.java @@ -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; } diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java index 786fcaaa9fb..89af7f43e74 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java @@ -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(); } diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java index 224bfdd6935..7faabbb2d15 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java @@ -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; } diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/FileStructure.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/FileStructure.java index 23575dcdec6..9f4e8014e11 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/FileStructure.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/FileStructure.java @@ -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), diff --git a/sonar-batch-protocol/src/main/protobuf/batch_report.proto b/sonar-batch-protocol/src/main/protobuf/batch_report.proto index 7937353fe9f..ae012d0fc2d 100644 --- a/sonar-batch-protocol/src/main/protobuf/batch_report.proto +++ b/sonar-batch-protocol/src/main/protobuf/batch_report.proto @@ -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; diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java index 3c2c5ac5da9..1cd26e0a34b 100644 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java @@ -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 diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java index fdd1ba2b67b..13f0765c83e 100644 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java @@ -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); diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/SonarDuplicationsIndex.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/index/SonarDuplicationsIndex.java index 51a094a869e..ca331ebeb2c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/SonarDuplicationsIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/cpd/index/SonarDuplicationsIndex.java @@ -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()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java index 2254fa0798f..d823886ad08 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java @@ -19,11 +19,8 @@ */ 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()); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java index 2e734e0063d..acc0f5255ac 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java @@ -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); |