aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStep.java31
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest.java123
2 files changed, 84 insertions, 70 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStep.java
index f86bc06ab71..3f9f538dadf 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStep.java
@@ -25,6 +25,7 @@ import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.resources.Qualifiers;
import org.sonar.batch.protocol.Constants;
import org.sonar.batch.protocol.output.BatchReport;
+import org.sonar.batch.protocol.output.BatchReport.Range;
import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.core.component.ComponentKeys;
import org.sonar.core.measure.db.MeasureDto;
@@ -99,8 +100,8 @@ public class PersistDuplicationMeasuresStep implements ComputationStep {
for (BatchReport.Duplication duplication : duplications) {
xml.append("<g>");
appendDuplication(xml, ComponentKeys.createKey(parentComponent.getKey(), componentPath, duplicationContext.context().getReportMetadata().getBranch()),
- duplication.getOriginBlock());
- for (BatchReport.DuplicationBlock duplicationBlock : duplication.getDuplicatedByList()) {
+ duplication.getOriginPosition());
+ for (BatchReport.Duplicate duplicationBlock : duplication.getDuplicateList()) {
processDuplicationBlock(duplicationContext, xml, duplicationBlock, parentComponent.getKey(), componentPath);
}
xml.append("</g>");
@@ -109,29 +110,33 @@ public class PersistDuplicationMeasuresStep implements ComputationStep {
return xml.toString();
}
- private void processDuplicationBlock(DuplicationContext duplicationContext, StringBuilder xml, BatchReport.DuplicationBlock duplicationBlock, String parentComponentKey,
+ private void processDuplicationBlock(DuplicationContext duplicationContext, StringBuilder xml, BatchReport.Duplicate duplicate, String parentComponentKey,
String componentPath) {
- if (duplicationBlock.hasComponentKey()) {
+ if (duplicate.hasOtherFileKey()) {
// componentKey is only set for cross project duplications
- String crossProjectComponentKey = duplicationBlock.getComponentKey();
- appendDuplication(xml, crossProjectComponentKey, duplicationBlock);
+ String crossProjectComponentKey = duplicate.getOtherFileKey();
+ appendDuplication(xml, crossProjectComponentKey, duplicate);
} else {
String branch = duplicationContext.context().getReportMetadata().getBranch();
- if (duplicationBlock.hasOtherComponentRef()) {
+ if (duplicate.hasOtherFileRef()) {
// Duplication is on a different file
- BatchReport.Component duplicationComponent = duplicationContext.context().getReportReader().readComponent(duplicationBlock.getOtherComponentRef());
- appendDuplication(xml, ComponentKeys.createKey(parentComponentKey, duplicationComponent.getPath(), branch), duplicationBlock);
+ BatchReport.Component duplicationComponent = duplicationContext.context().getReportReader().readComponent(duplicate.getOtherFileRef());
+ appendDuplication(xml, ComponentKeys.createKey(parentComponentKey, duplicationComponent.getPath(), branch), duplicate);
} else {
// Duplication is on a the same file
- appendDuplication(xml, ComponentKeys.createKey(parentComponentKey, componentPath, branch), duplicationBlock);
+ appendDuplication(xml, ComponentKeys.createKey(parentComponentKey, componentPath, branch), duplicate);
}
}
}
- private static void appendDuplication(StringBuilder xml, String componentKey, BatchReport.DuplicationBlock duplicationBlock) {
- int length = duplicationBlock.getEndLine() - duplicationBlock.getStartLine();
- xml.append("<b s=\"").append(duplicationBlock.getStartLine())
+ private static void appendDuplication(StringBuilder xml, String componentKey, BatchReport.Duplicate duplicate) {
+ appendDuplication(xml, componentKey, duplicate.getRange());
+ }
+
+ private static void appendDuplication(StringBuilder xml, String componentKey, Range range) {
+ int length = range.getEndLine() - range.getStartLine() + 1;
+ xml.append("<b s=\"").append(range.getStartLine())
.append("\" l=\"").append(length)
.append("\" r=\"").append(StringEscapeUtils.escapeXml(componentKey))
.append("\"/>");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest.java
index b403045472d..e5037e303e8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest.java
@@ -26,6 +26,7 @@ import org.junit.rules.TemporaryFolder;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.batch.protocol.Constants;
import org.sonar.batch.protocol.output.BatchReport;
+import org.sonar.batch.protocol.output.BatchReport.Range;
import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.core.measure.db.MetricDto;
@@ -100,15 +101,16 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
BatchReportWriter writer = initReportWithProjectAndFile();
BatchReport.Duplication duplication = BatchReport.Duplication.newBuilder()
- .setOriginBlock(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(2)
+ .setOriginPosition(Range.newBuilder()
.setStartLine(1)
.setEndLine(5)
.build())
- .addDuplicatedBy(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(2)
- .setStartLine(6)
- .setEndLine(10)
+ .addDuplicate(BatchReport.Duplicate.newBuilder()
+ .setOtherFileRef(2)
+ .setRange(Range.newBuilder()
+ .setStartLine(6)
+ .setEndLine(10)
+ .build())
.build())
.build();
writer.writeComponentDuplications(2, newArrayList(duplication));
@@ -117,10 +119,10 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
- Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", metric_id as \"metricId\", text_value as \"textValue\" from project_measures");
+ Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", metric_id as \"metricId\", text_value as \"textValue\" from project_measures");
assertThat(dto.get("snapshotId")).isEqualTo(11L);
assertThat(dto.get("metricId")).isEqualTo(duplicationMetric.getId().longValue());
- assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"4\" r=\"PROJECT_KEY:file\"/><b s=\"6\" l=\"4\" r=\"PROJECT_KEY:file\"/></g></duplications>");
+ assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"5\" r=\"PROJECT_KEY:file\"/><b s=\"6\" l=\"5\" r=\"PROJECT_KEY:file\"/></g></duplications>");
}
@Test
@@ -155,15 +157,16 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
.build());
BatchReport.Duplication duplication = BatchReport.Duplication.newBuilder()
- .setOriginBlock(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(3)
+ .setOriginPosition(Range.newBuilder()
.setStartLine(1)
.setEndLine(5)
.build())
- .addDuplicatedBy(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(3)
- .setStartLine(6)
- .setEndLine(10)
+ .addDuplicate(BatchReport.Duplicate.newBuilder()
+ .setOtherFileRef(3)
+ .setRange(Range.newBuilder()
+ .setStartLine(6)
+ .setEndLine(10)
+ .build())
.build())
.build();
writer.writeComponentDuplications(3, newArrayList(duplication));
@@ -172,9 +175,9 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
- Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", text_value as \"textValue\" from project_measures");
+ Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", text_value as \"textValue\" from project_measures");
assertThat(dto.get("snapshotId")).isEqualTo(12L);
- assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"4\" r=\"MODULE_KEY:file\"/><b s=\"6\" l=\"4\" r=\"MODULE_KEY:file\"/></g></duplications>");
+ assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"5\" r=\"MODULE_KEY:file\"/><b s=\"6\" l=\"5\" r=\"MODULE_KEY:file\"/></g></duplications>");
}
@Test
@@ -208,15 +211,16 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
.build());
BatchReport.Duplication duplication = BatchReport.Duplication.newBuilder()
- .setOriginBlock(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(3)
+ .setOriginPosition(Range.newBuilder()
.setStartLine(1)
.setEndLine(5)
.build())
- .addDuplicatedBy(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(3)
- .setStartLine(6)
- .setEndLine(10)
+ .addDuplicate(BatchReport.Duplicate.newBuilder()
+ .setOtherFileRef(3)
+ .setRange(Range.newBuilder()
+ .setStartLine(6)
+ .setEndLine(10)
+ .build())
.build())
.build();
writer.writeComponentDuplications(3, newArrayList(duplication));
@@ -225,9 +229,9 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
- Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", text_value as \"textValue\" from project_measures");
+ Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", text_value as \"textValue\" from project_measures");
assertThat(dto.get("snapshotId")).isEqualTo(12L);
- assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"4\" r=\"PROJECT_KEY:file\"/><b s=\"6\" l=\"4\" r=\"PROJECT_KEY:file\"/></g></duplications>");
+ assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"5\" r=\"PROJECT_KEY:file\"/><b s=\"6\" l=\"5\" r=\"PROJECT_KEY:file\"/></g></duplications>");
}
@Test
@@ -268,15 +272,16 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
.build());
BatchReport.Duplication duplication = BatchReport.Duplication.newBuilder()
- .setOriginBlock(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(10)
+ .setOriginPosition(Range.newBuilder()
.setStartLine(1)
.setEndLine(5)
.build())
- .addDuplicatedBy(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(10)
- .setStartLine(6)
- .setEndLine(10)
+ .addDuplicate(BatchReport.Duplicate.newBuilder()
+ .setOtherFileRef(10)
+ .setRange(Range.newBuilder()
+ .setStartLine(6)
+ .setEndLine(10)
+ .build())
.build())
.build();
writer.writeComponentDuplications(10, newArrayList(duplication));
@@ -285,8 +290,8 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
- Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", text_value as \"textValue\" from project_measures");
- assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"4\" r=\"PROJECT_KEY:file\"/><b s=\"6\" l=\"4\" r=\"PROJECT_KEY:file\"/></g></duplications>");
+ Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", text_value as \"textValue\" from project_measures");
+ assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"5\" r=\"PROJECT_KEY:file\"/><b s=\"6\" l=\"5\" r=\"PROJECT_KEY:file\"/></g></duplications>");
}
@Test
@@ -315,15 +320,16 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
.build());
BatchReport.Duplication duplication = BatchReport.Duplication.newBuilder()
- .setOriginBlock(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(2)
+ .setOriginPosition(Range.newBuilder()
.setStartLine(1)
.setEndLine(5)
.build())
- .addDuplicatedBy(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(2)
- .setStartLine(6)
- .setEndLine(10)
+ .addDuplicate(BatchReport.Duplicate.newBuilder()
+ .setOtherFileRef(2)
+ .setRange(Range.newBuilder()
+ .setStartLine(6)
+ .setEndLine(10)
+ .build())
.build())
.build();
writer.writeComponentDuplications(2, newArrayList(duplication));
@@ -332,9 +338,10 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
- Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", text_value as \"textValue\" from project_measures");
+ Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", text_value as \"textValue\" from project_measures");
assertThat(dto.get("snapshotId")).isEqualTo(11L);
- assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"4\" r=\"PROJECT_KEY:file:origin/master\"/><b s=\"6\" l=\"4\" r=\"PROJECT_KEY:file:origin/master\"/></g></duplications>");
+ assertThat(dto.get("textValue")).isEqualTo(
+ "<duplications><g><b s=\"1\" l=\"5\" r=\"PROJECT_KEY:file:origin/master\"/><b s=\"6\" l=\"5\" r=\"PROJECT_KEY:file:origin/master\"/></g></duplications>");
}
@Test
@@ -350,15 +357,16 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
.build());
BatchReport.Duplication duplication = BatchReport.Duplication.newBuilder()
- .setOriginBlock(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(2)
+ .setOriginPosition(Range.newBuilder()
.setStartLine(1)
.setEndLine(5)
.build())
- .addDuplicatedBy(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(3)
- .setStartLine(6)
- .setEndLine(10)
+ .addDuplicate(BatchReport.Duplicate.newBuilder()
+ .setOtherFileRef(3)
+ .setRange(Range.newBuilder()
+ .setStartLine(6)
+ .setEndLine(10)
+ .build())
.build())
.build();
writer.writeComponentDuplications(2, newArrayList(duplication));
@@ -367,9 +375,9 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
- Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", text_value as \"textValue\" from project_measures");
+ Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", text_value as \"textValue\" from project_measures");
assertThat(dto.get("snapshotId")).isEqualTo(11L);
- assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"4\" r=\"PROJECT_KEY:file\"/><b s=\"6\" l=\"4\" r=\"PROJECT_KEY:file2\"/></g></duplications>");
+ assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"5\" r=\"PROJECT_KEY:file\"/><b s=\"6\" l=\"5\" r=\"PROJECT_KEY:file2\"/></g></duplications>");
}
@Test
@@ -378,15 +386,16 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
BatchReportWriter writer = initReportWithProjectAndFile();
BatchReport.Duplication duplication = BatchReport.Duplication.newBuilder()
- .setOriginBlock(BatchReport.DuplicationBlock.newBuilder()
- .setOtherComponentRef(2)
+ .setOriginPosition(Range.newBuilder()
.setStartLine(1)
.setEndLine(5)
.build())
- .addDuplicatedBy(BatchReport.DuplicationBlock.newBuilder()
- .setComponentKey("PROJECT2_KEY:file2")
- .setStartLine(6)
- .setEndLine(10)
+ .addDuplicate(BatchReport.Duplicate.newBuilder()
+ .setOtherFileKey("PROJECT2_KEY:file2")
+ .setRange(Range.newBuilder()
+ .setStartLine(6)
+ .setEndLine(10)
+ .build())
.build())
.build();
writer.writeComponentDuplications(2, newArrayList(duplication));
@@ -395,9 +404,9 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
- Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", text_value as \"textValue\" from project_measures");
+ Map<String, Object> dto = dbTester.selectFirst("select snapshot_id as \"snapshotId\", text_value as \"textValue\" from project_measures");
assertThat(dto.get("snapshotId")).isEqualTo(11L);
- assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"4\" r=\"PROJECT_KEY:file\"/><b s=\"6\" l=\"4\" r=\"PROJECT2_KEY:file2\"/></g></duplications>");
+ assertThat(dto.get("textValue")).isEqualTo("<duplications><g><b s=\"1\" l=\"5\" r=\"PROJECT_KEY:file\"/><b s=\"6\" l=\"5\" r=\"PROJECT2_KEY:file2\"/></g></duplications>");
}
private BatchReportWriter initReportWithProjectAndFile() throws IOException {
@@ -423,7 +432,7 @@ public class PersistDuplicationMeasuresStepTest extends BaseStepTest {
return writer;
}
- private MetricDto saveDuplicationMetric(){
+ private MetricDto saveDuplicationMetric() {
MetricDto duplicationMetric = new MetricDto().setKey(CoreMetrics.DUPLICATIONS_DATA_KEY)
.setOptimizedBestValue(false)
.setDeleteHistoricalData(false)