CloseableIterator<BatchReport.Duplication> readComponentDuplications(int componentRef);
- CloseableIterator<BatchReport.DuplicationBlock> readComponentDuplicationBlocks(int componentRef);
+ CloseableIterator<BatchReport.CpdTextBlock> readCpdTextBlocks(int componentRef);
CloseableIterator<BatchReport.Symbol> readComponentSymbols(int componentRef);
}
@Override
- public CloseableIterator<BatchReport.DuplicationBlock> readComponentDuplicationBlocks(int componentRef) {
- return delegate.readComponentDuplicationBlocks(componentRef);
+ public CloseableIterator<BatchReport.CpdTextBlock> readCpdTextBlocks(int componentRef) {
+ return delegate.readCpdTextBlocks(componentRef);
}
@Override
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();
@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();
}
@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
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<>();
}
@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;
}
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();
}
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;
}
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),
}
// 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;
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
@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);
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;
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());
*/
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;
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;
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;
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());
}
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;
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);