diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-03-26 17:36:21 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-03-26 17:43:06 +0100 |
commit | a3bf358944e6245fbf8c69da6a786f4a4620b8a7 (patch) | |
tree | 3d7188085d59b6f897ac447baa945e9bcc7948a4 /sonar-batch | |
parent | c14dc04fddfd11aba13806cc9965f86365079a0a (diff) | |
download | sonarqube-a3bf358944e6245fbf8c69da6a786f4a4620b8a7.tar.gz sonarqube-a3bf358944e6245fbf8c69da6a786f4a4620b8a7.zip |
SONAR-6280 Use a range to represent duplication position
Diffstat (limited to 'sonar-batch')
3 files changed, 39 insertions, 36 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/DuplicationsPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/DuplicationsPublisher.java index 3648f47cc12..896ef5aba08 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/DuplicationsPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/DuplicationsPublisher.java @@ -26,10 +26,10 @@ import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.index.BatchResource; import org.sonar.batch.index.ResourceCache; -import org.sonar.batch.protocol.output.BatchReport; +import org.sonar.batch.protocol.output.*; +import org.sonar.batch.protocol.output.BatchReport.Duplicate; import org.sonar.batch.protocol.output.BatchReport.Duplication; -import org.sonar.batch.protocol.output.BatchReport.DuplicationBlock; -import org.sonar.batch.protocol.output.BatchReportWriter; +import org.sonar.batch.protocol.output.BatchReport.Range; public class DuplicationsPublisher implements ReportPublisher { @@ -49,7 +49,7 @@ public class DuplicationsPublisher implements ReportPublisher { Iterable<org.sonar.batch.protocol.output.BatchReport.Duplication> reportDuplications = Iterables.transform(dups, new Function<DefaultDuplication, BatchReport.Duplication>() { private final BatchReport.Duplication.Builder dupBuilder = BatchReport.Duplication.newBuilder(); - private final BatchReport.DuplicationBlock.Builder blockBuilder = BatchReport.DuplicationBlock.newBuilder(); + private final BatchReport.Duplicate.Builder blockBuilder = BatchReport.Duplicate.newBuilder(); @Override public BatchReport.Duplication apply(DefaultDuplication input) { @@ -62,27 +62,31 @@ public class DuplicationsPublisher implements ReportPublisher { } } - private Duplication toReportDuplication(String currentComponentKey, Duplication.Builder dupBuilder, DuplicationBlock.Builder blockBuilder, DefaultDuplication input) { + private Duplication toReportDuplication(String currentComponentKey, Duplication.Builder dupBuilder, Duplicate.Builder blockBuilder, DefaultDuplication input) { dupBuilder.clear(); Block originBlock = input.originBlock(); blockBuilder.clear(); - dupBuilder.setOriginBlock(blockBuilder + dupBuilder.setOriginPosition(Range.newBuilder() .setStartLine(originBlock.startLine()) - .setEndLine(originBlock.startLine() + originBlock.length() - 1).build()); + .setEndLine(originBlock.startLine() + originBlock.length() - 1) + .build()); for (Block duplicate : input.duplicates()) { blockBuilder.clear(); String componentKey = duplicate.resourceKey(); if (!currentComponentKey.equals(componentKey)) { BatchResource sameProjectComponent = resourceCache.get(componentKey); if (sameProjectComponent != null) { - blockBuilder.setOtherComponentRef(sameProjectComponent.batchId()); + blockBuilder.setOtherFileRef(sameProjectComponent.batchId()); } else { - blockBuilder.setComponentKey(componentKey); + blockBuilder.setOtherFileKey(componentKey); } } - dupBuilder.addDuplicatedBy(blockBuilder - .setStartLine(duplicate.startLine()) - .setEndLine(duplicate.startLine() + duplicate.length() - 1).build()); + dupBuilder.addDuplicate(blockBuilder + .setRange(Range.newBuilder() + .setStartLine(duplicate.startLine()) + .setEndLine(duplicate.startLine() + duplicate.length() - 1) + .build()) + .build()); } return dupBuilder.build(); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/language/Language.java b/sonar-batch/src/main/java/org/sonar/batch/repository/language/Language.java index 67629ae50ad..12241dab086 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/language/Language.java +++ b/sonar-batch/src/main/java/org/sonar/batch/repository/language/Language.java @@ -54,4 +54,9 @@ public final class Language { return Arrays.asList(fileSuffixes); } + @Override + public String toString() { + return name; + } + } diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java index b75efb3f275..a3536f2ada1 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java @@ -88,34 +88,28 @@ public class DuplicationsPublisherTest { List<org.sonar.batch.protocol.output.BatchReport.Duplication> componentDuplications = reader.readComponentDuplications(2); assertThat(componentDuplications).hasSize(3); org.sonar.batch.protocol.output.BatchReport.Duplication savedDup1 = componentDuplications.get(0); - assertThat(savedDup1.getOriginBlock().hasComponentKey()).isFalse(); - assertThat(savedDup1.getOriginBlock().hasOtherComponentRef()).isFalse(); - assertThat(savedDup1.getOriginBlock().getStartLine()).isEqualTo(1); - assertThat(savedDup1.getOriginBlock().getEndLine()).isEqualTo(10); - assertThat(savedDup1.getDuplicatedBy(0).hasComponentKey()).isFalse(); - assertThat(savedDup1.getDuplicatedBy(0).hasOtherComponentRef()).isFalse(); - assertThat(savedDup1.getDuplicatedBy(0).getStartLine()).isEqualTo(20); - assertThat(savedDup1.getDuplicatedBy(0).getEndLine()).isEqualTo(50); + assertThat(savedDup1.getOriginPosition().getStartLine()).isEqualTo(1); + assertThat(savedDup1.getOriginPosition().getEndLine()).isEqualTo(10); + assertThat(savedDup1.getDuplicate(0).hasOtherFileKey()).isFalse(); + assertThat(savedDup1.getDuplicate(0).hasOtherFileRef()).isFalse(); + assertThat(savedDup1.getDuplicate(0).getRange().getStartLine()).isEqualTo(20); + assertThat(savedDup1.getDuplicate(0).getRange().getEndLine()).isEqualTo(50); org.sonar.batch.protocol.output.BatchReport.Duplication savedDup2 = componentDuplications.get(1); - assertThat(savedDup2.getOriginBlock().hasComponentKey()).isFalse(); - assertThat(savedDup2.getOriginBlock().hasOtherComponentRef()).isFalse(); - assertThat(savedDup2.getOriginBlock().getStartLine()).isEqualTo(11); - assertThat(savedDup2.getOriginBlock().getEndLine()).isEqualTo(20); - assertThat(savedDup2.getDuplicatedBy(0).getComponentKey()).isEqualTo("another"); - assertThat(savedDup2.getDuplicatedBy(0).hasOtherComponentRef()).isFalse(); - assertThat(savedDup2.getDuplicatedBy(0).getStartLine()).isEqualTo(20); - assertThat(savedDup2.getDuplicatedBy(0).getEndLine()).isEqualTo(50); + assertThat(savedDup2.getOriginPosition().getStartLine()).isEqualTo(11); + assertThat(savedDup2.getOriginPosition().getEndLine()).isEqualTo(20); + assertThat(savedDup2.getDuplicate(0).getOtherFileKey()).isEqualTo("another"); + assertThat(savedDup2.getDuplicate(0).hasOtherFileRef()).isFalse(); + assertThat(savedDup2.getDuplicate(0).getRange().getStartLine()).isEqualTo(20); + assertThat(savedDup2.getDuplicate(0).getRange().getEndLine()).isEqualTo(50); org.sonar.batch.protocol.output.BatchReport.Duplication savedDup3 = componentDuplications.get(2); - assertThat(savedDup3.getOriginBlock().hasComponentKey()).isFalse(); - assertThat(savedDup3.getOriginBlock().hasOtherComponentRef()).isFalse(); - assertThat(savedDup3.getOriginBlock().getStartLine()).isEqualTo(11); - assertThat(savedDup3.getOriginBlock().getEndLine()).isEqualTo(20); - assertThat(savedDup3.getDuplicatedBy(0).hasComponentKey()).isFalse(); - assertThat(savedDup3.getDuplicatedBy(0).getOtherComponentRef()).isEqualTo(3); - assertThat(savedDup3.getDuplicatedBy(0).getStartLine()).isEqualTo(20); - assertThat(savedDup3.getDuplicatedBy(0).getEndLine()).isEqualTo(50); + assertThat(savedDup3.getOriginPosition().getStartLine()).isEqualTo(11); + assertThat(savedDup3.getOriginPosition().getEndLine()).isEqualTo(20); + assertThat(savedDup3.getDuplicate(0).hasOtherFileKey()).isFalse(); + assertThat(savedDup3.getDuplicate(0).getOtherFileRef()).isEqualTo(3); + assertThat(savedDup3.getDuplicate(0).getRange().getStartLine()).isEqualTo(20); + assertThat(savedDup3.getDuplicate(0).getRange().getEndLine()).isEqualTo(50); } |