aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2018-01-17 15:11:24 +0100
committerDuarte Meneses <duarte.meneses@sonarsource.com>2018-02-07 14:33:55 +0100
commit3ce06f145812421fb1ee6d00ddb613677ec3d1c0 (patch)
tree6b0af8a3b58008051cabbbfb726d6714e30dd245 /server/sonar-server
parent4d5a32120b9028622e8c0e5fb24814633634653a (diff)
downloadsonarqube-3ce06f145812421fb1ee6d00ddb613677ec3d1c0.tar.gz
sonarqube-3ce06f145812421fb1ee6d00ddb613677ec3d1c0.zip
SONAR-10257 Support lines without SCM info
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssigner.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculator.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoImpl.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/source/ScmLineReader.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewCoverageMeasuresStep.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java7
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStep.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculatorTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java49
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/scm/ChangesetTest.java3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoRepositoryRule.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/ScmLineReaderTest.java31
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStepTest.java52
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStepTest.java8
14 files changed, 144 insertions, 39 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssigner.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssigner.java
index 4a1f25d4465..d366cb11526 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssigner.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssigner.java
@@ -41,11 +41,7 @@ import static org.sonar.core.issue.IssueChangeContext.createScan;
/**
* Detect the SCM author and SQ assignee.
* <p/>
- * It relies on:
- * <ul>
- * <li>SCM information sent in the report for modified files</li>
- * <li>sources lines stored in database for non-modified files</li>
- * </ul>
+ * It relies on SCM information which comes from both the report and database.
*/
public class IssueAssigner extends IssueVisitor {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculator.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculator.java
index 4c3c173109c..473fe7054f9 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculator.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculator.java
@@ -157,7 +157,7 @@ public class IssueCreationDateCalculator extends IssueVisitor {
}
}
- return Optional.ofNullable(scmInfo.getLatestChangeset());
+ return Optional.of(scmInfo.getLatestChangeset());
}
private static void addLines(Set<Integer> involvedLines, TextRange range) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoImpl.java
index 97b5233f18e..ca116018d67 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoImpl.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.computation.task.projectanalysis.scm;
+import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
import java.util.stream.Collectors;
@@ -35,7 +36,7 @@ public class ScmInfoImpl implements ScmInfo {
public ScmInfoImpl(Map<Integer, Changeset> lineChangesets) {
checkState(!lineChangesets.isEmpty(), "A ScmInfo must have at least one Changeset and does not support any null one");
- this.lineChangesets = lineChangesets;
+ this.lineChangesets = Collections.unmodifiableMap(lineChangesets);
this.latestChangeset = computeLatestChangeset(lineChangesets);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/source/ScmLineReader.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/source/ScmLineReader.java
index e2a751615c3..b09edffc585 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/source/ScmLineReader.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/source/ScmLineReader.java
@@ -74,9 +74,9 @@ public class ScmLineReader implements LineReader {
latestChangeWithRevision = newChangeSet;
} else {
long newChangesetDate = newChangeSet.getDate();
- long latestChangeDate = latestChange.getDate();
+ long latestChangeDate = latestChangeWithRevision.getDate();
if (newChangesetDate > latestChangeDate) {
- latestChange = newChangeSet;
+ latestChangeWithRevision = newChangeSet;
}
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewCoverageMeasuresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewCoverageMeasuresStep.java
index 5e7b8d74bc7..1eede2525ee 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewCoverageMeasuresStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewCoverageMeasuresStep.java
@@ -273,7 +273,8 @@ public class NewCoverageMeasuresStep implements ComputationStep {
int conditions = (Integer) ObjectUtils.defaultIfNull(conditionsByLine.get(lineId), 0);
int coveredConditions = (Integer) ObjectUtils.defaultIfNull(coveredConditionsByLine.get(lineId), 0);
if (componentScm.hasChangesetForLine(lineId)) {
- analyze(context.getPeriod(), componentScm.getChangesetForLine(lineId).getDate(), hits, conditions, coveredConditions);
+ long date = componentScm.getChangesetForLine(lineId).getDate();
+ analyze(context.getPeriod(), date, hits, conditions, coveredConditions);
}
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java
index 94881754f28..ccd08059c46 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java
@@ -132,7 +132,7 @@ public class NewSizeMeasuresStep implements ComputationStep {
}
private void initNewDuplicated(Component component, ScmInfo scmInfo, Period period) {
- DuplicationCounters duplicationCounters = new DuplicationCounters(scmInfo, period);
+ DuplicationCounters duplicationCounters = new DuplicationCounters(scmInfo, period, scmInfo.getAllChangesets().size());
Iterable<Duplication> duplications = duplicationRepository.getDuplications(component);
for (Duplication duplication : duplications) {
duplicationCounters.addBlock(duplication.getOriginal());
@@ -157,15 +157,16 @@ public class NewSizeMeasuresStep implements ComputationStep {
private final Set<Integer> lineCounts;
private int blockCounts;
- private DuplicationCounters(ScmInfo scmInfo, Period period) {
+ private DuplicationCounters(ScmInfo scmInfo, Period period, int changesetSize) {
this.scmInfo = scmInfo;
this.period = period;
- this.lineCounts = new HashSet<>();
+ this.lineCounts = new HashSet<>(changesetSize);
}
void addBlock(TextBlock textBlock) {
Boolean[] newBlock = new Boolean[] {false};
IntStream.rangeClosed(textBlock.getStart(), textBlock.getEnd())
+ .filter(scmInfo::hasChangesetForLine)
.filter(line -> isLineInPeriod(line, period))
.forEach(line -> {
lineCounts.add(line);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStep.java
index 9279a10fe6f..a7c5d4cdcde 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStep.java
@@ -168,11 +168,11 @@ public class PersistFileSourcesStep implements ComputationStep {
}
@CheckForNull
- private String computeRevision(@Nullable Changeset latestChange) {
- if (latestChange == null) {
+ private String computeRevision(@Nullable Changeset latestChangeWithRevision) {
+ if (latestChangeWithRevision == null) {
return null;
}
- return latestChange.getRevision();
+ return latestChangeWithRevision.getRevision();
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculatorTest.java
index b4c98156d1f..226b3bbf3f6 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculatorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculatorTest.java
@@ -264,9 +264,7 @@ public class IssueCreationDateCalculatorTest {
withScmAt(3, 1300L);
withScmAt(4, 1400L);
withScmAt(5, 1500L);
- withScmAt(6, 1600L);
- withScmAt(7, 1700L);
- withScmAt(8, 1800L);
+ // some lines missing should be ok
withScmAt(9, 1900L);
run();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java
index c39cd3146db..c9564da5bd0 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java
@@ -23,7 +23,9 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Ordering;
import java.util.Arrays;
+import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import org.assertj.core.data.Offset;
import org.junit.Before;
import org.junit.Rule;
@@ -171,6 +173,19 @@ public class NewMaintainabilityMeasuresVisitorTest {
}
@Test
+ public void file_has_new_debt_ratio_if_only_has_some_scm_dates_which_are_after_snapshot_dates() {
+ setPeriod();
+ when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST);
+ setupOneFileAloneInAProjectWithPartialChangesets(50, Flag.SRC_FILE, Flag.WITH_NCLOC);
+ measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50));
+
+ underTest.visit(treeRootHolder.getRoot());
+
+ assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 83.33);
+ assertNewDebtRatioValues(ROOT_REF, 83.33);
+ }
+
+ @Test
public void new_debt_ratio_changes_with_language_cost() {
setPeriod();
when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST * 10);
@@ -367,8 +382,7 @@ public class NewMaintainabilityMeasuresVisitorTest {
builder(DIRECTORY, 111)
.addChildren(
builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 4)).build(),
- builder(FILE, 22_222).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 6)).build()
- )
+ builder(FILE, 22_222).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 6)).build())
.build())
.build())
.build());
@@ -439,6 +453,29 @@ public class NewMaintainabilityMeasuresVisitorTest {
}
}
+ private void setupOneFileAloneInAProjectWithPartialChangesets(int newDebt, Flag isUnitTest, Flag withNclocLines) {
+ checkArgument(isUnitTest == Flag.UT_FILE || isUnitTest == Flag.SRC_FILE);
+ checkArgument(withNclocLines == Flag.WITH_NCLOC || withNclocLines == Flag.NO_NCLOC || withNclocLines == Flag.MISSING_MEASURE_NCLOC);
+
+ treeRootHolder.setRoot(
+ builder(PROJECT, ROOT_REF)
+ .addChildren(
+ builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(isUnitTest == Flag.UT_FILE, LANGUAGE_1_KEY, 1)).build())
+ .build());
+
+ Measure newDebtMeasure = createNewDebtMeasure(newDebt);
+ measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure);
+ if (withNclocLines == Flag.WITH_NCLOC) {
+ // 4 lines file, only first one is not ncloc
+ measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
+ } else if (withNclocLines == Flag.NO_NCLOC) {
+ // 4 lines file, none of which is ncloc
+ measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNoNclocDataMeasure(4));
+ }
+ // 2 last lines are after PERIOD 2's snapshot date
+ scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesetsForLines(PERIOD_SNAPSHOT_DATE + 100, 3, 4));
+ }
+
private enum Flag {
UT_FILE, SRC_FILE, NO_CHANGESET, WITH_CHANGESET, WITH_NCLOC, NO_NCLOC, MISSING_MEASURE_NCLOC
}
@@ -482,6 +519,14 @@ public class NewMaintainabilityMeasuresVisitorTest {
}
/**
+ * Creates changesets for specific lines, which all have the same date {@code scmDate}.
+ */
+ private static Map<Integer, Changeset> createChangesetsForLines(long scmDate, int... lines) {
+ Changeset changetset = Changeset.newChangesetBuilder().setDate(scmDate).setRevision("rev-1").build();
+ return Arrays.stream(lines).boxed().collect(Collectors.toMap(l -> l, l -> changetset));
+ }
+
+ /**
* Creates a changeset of {@code lineCount} lines which have the date {@code scmDate} and {@code otherLineCount} lines which
* have the date {@code otherScmDate}.
*/
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/scm/ChangesetTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/scm/ChangesetTest.java
index 8d96ca4605b..997f9defd79 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/scm/ChangesetTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/scm/ChangesetTest.java
@@ -47,12 +47,11 @@ public class ChangesetTest {
public void create_changeset_with_minimum_fields() {
Changeset underTest = Changeset.newChangesetBuilder()
.setDate(123456789L)
- .setRevision("rev-1")
.build();
assertThat(underTest.getAuthor()).isNull();
assertThat(underTest.getDate()).isEqualTo(123456789L);
- assertThat(underTest.getRevision()).isEqualTo("rev-1");
+ assertThat(underTest.getRevision()).isNull();
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoRepositoryRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoRepositoryRule.java
index 516e780c50b..0c42e7bde71 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoRepositoryRule.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoRepositoryRule.java
@@ -50,4 +50,9 @@ public class ScmInfoRepositoryRule extends ExternalResource implements ScmInfoRe
scmInfoByFileRef.put(fileRef, new ScmInfoImpl(changeset));
return this;
}
+
+ public ScmInfoRepositoryRule setScmInfo(int fileRef, Map<Integer, Changeset> changesets) {
+ scmInfoByFileRef.put(fileRef, new ScmInfoImpl(changesets));
+ return this;
+ }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/ScmLineReaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/ScmLineReaderTest.java
index d2273474738..1abd95527f9 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/ScmLineReaderTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/ScmLineReaderTest.java
@@ -55,8 +55,7 @@ public class ScmLineReaderTest {
public void set_scm_with_minim_fields() {
ScmInfo scmInfo = new ScmInfoImpl(Collections.singletonMap(1,
Changeset.newChangesetBuilder()
- .setDate(123_456_789L)
- .setRevision("rev-1")
+ .setDate(123456789L)
.build()));
ScmLineReader lineScm = new ScmLineReader(scmInfo);
@@ -66,7 +65,8 @@ public class ScmLineReaderTest {
assertThat(lineBuilder.hasScmAuthor()).isFalse();
assertThat(lineBuilder.getScmDate()).isEqualTo(123456789L);
- assertThat(lineBuilder.getScmRevision()).isEqualTo("rev-1");
+ assertThat(lineBuilder.hasScmRevision()).isFalse();
+
}
@Test
@@ -74,31 +74,32 @@ public class ScmLineReaderTest {
long refDate = 123_456_789L;
Changeset changeset0 = Changeset.newChangesetBuilder().setDate(refDate - 636).setRevision("rev-1").build();
Changeset changeset1 = Changeset.newChangesetBuilder().setDate(refDate + 1).setRevision("rev-2").build();
- Changeset changeset2 = Changeset.newChangesetBuilder().setDate(refDate + 2).setRevision("rev-3").build();
+ Changeset changeset2 = Changeset.newChangesetBuilder().setDate(refDate + 2).build();
ScmInfo scmInfo = new ScmInfoImpl(setup8LinesChangeset(changeset0, changeset1, changeset2));
ScmLineReader lineScm = new ScmLineReader(scmInfo);
- // before any line is read, the latest change is null
+ // before any line is read, the latest changes are null
assertThat(lineScm.getLatestChange()).isNull();
+ assertThat(lineScm.getLatestChangeWithRevision()).isNull();
// read line 1, only one changeset => 0
- readLineAndAssertLatestChangeDate(lineScm, 1, changeset0);
+ readLineAndAssertLatestChanges(lineScm, 1, changeset0, changeset0);
// read line 2, latest changeset is 1
- readLineAndAssertLatestChangeDate(lineScm, 2, changeset1);
+ readLineAndAssertLatestChanges(lineScm, 2, changeset1, changeset1);
// read line 3, latest changeset is still 1
- readLineAndAssertLatestChangeDate(lineScm, 3, changeset1);
+ readLineAndAssertLatestChanges(lineScm, 3, changeset1, changeset1);
// read line 4, latest changeset is now 2
- readLineAndAssertLatestChangeDate(lineScm, 4, changeset2);
+ readLineAndAssertLatestChanges(lineScm, 4, changeset2, changeset1);
// read line 5 to 8, there will never be any changeset more recent than 2
- readLineAndAssertLatestChangeDate(lineScm, 5, changeset2);
- readLineAndAssertLatestChangeDate(lineScm, 6, changeset2);
- readLineAndAssertLatestChangeDate(lineScm, 7, changeset2);
- readLineAndAssertLatestChangeDate(lineScm, 8, changeset2);
+ readLineAndAssertLatestChanges(lineScm, 5, changeset2, changeset1);
+ readLineAndAssertLatestChanges(lineScm, 6, changeset2, changeset1);
+ readLineAndAssertLatestChanges(lineScm, 7, changeset2, changeset1);
+ readLineAndAssertLatestChanges(lineScm, 8, changeset2, changeset1);
}
private static Map<Integer, Changeset> setup8LinesChangeset(Changeset changeset0, Changeset changeset1, Changeset changeset2) {
@@ -113,10 +114,12 @@ public class ScmLineReaderTest {
.put(8, changeset0).build();
}
- private void readLineAndAssertLatestChangeDate(ScmLineReader lineScm, int line, Changeset expectedChangeset) {
+ private void readLineAndAssertLatestChanges(ScmLineReader lineScm, int line, Changeset expectedChangeset, Changeset expectedChangesetWithRevision) {
DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(line);
lineScm.read(lineBuilder);
assertThat(lineScm.getLatestChange()).isSameAs(expectedChangeset);
+ assertThat(lineScm.getLatestChangeWithRevision()).isSameAs(expectedChangesetWithRevision);
+
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStepTest.java
index 25e6bfa4b44..099ef428674 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStepTest.java
@@ -133,6 +133,24 @@ public class NewSizeMeasuresStepTest {
}
@Test
+ public void compute_new_lines_with_only_some_lines_having_changesets() {
+ setChangesetsForFirstThreeLines(FILE_1_REF, FILE_2_REF, FILE_4_REF);
+
+ underTest.execute();
+
+ assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_LINES_KEY, 2);
+ assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_LINES_KEY, 2);
+ assertNoRawMeasure(FILE_3_REF, NEW_LINES_KEY);
+ assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_LINES_KEY, 2);
+ assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_LINES_KEY, 4);
+ assertNoRawMeasure(DIRECTORY_2_REF, NEW_LINES_KEY);
+ assertRawMeasureValueOnPeriod(SUB_MODULE_1_REF, NEW_LINES_KEY, 4);
+ assertRawMeasureValueOnPeriod(SUB_MODULE_2_REF, NEW_LINES_KEY, 2);
+ assertRawMeasureValueOnPeriod(MODULE_REF, NEW_LINES_KEY, 6);
+ assertRawMeasureValueOnPeriod(ROOT_REF, NEW_LINES_KEY, 6);
+ }
+
+ @Test
public void does_not_compute_new_lines_when_no_changeset() {
underTest.execute();
@@ -217,6 +235,31 @@ public class NewSizeMeasuresStepTest {
assertRawMeasureValueOnPeriod(MODULE_REF, NEW_DUPLICATED_LINES_KEY, 22d);
assertRawMeasureValueOnPeriod(ROOT_REF, NEW_DUPLICATED_LINES_KEY, 22d);
}
+
+ @Test
+ public void compute_and_aggregate_duplicated_lines_when_only_some_lines_have_changesets() {
+ // 2 new duplicated lines in each, since only the first 2 lines are new
+ addDuplicatedBlock(FILE_1_REF, 2);
+ addDuplicatedBlock(FILE_3_REF, 10);
+ addDuplicatedBlock(FILE_4_REF, 12);
+ setChangesetsForFirstThreeLines(FILE_1_REF);
+ setChangesetsForFirstThreeLines(FILE_2_REF);
+ setChangesetsForFirstThreeLines(FILE_3_REF);
+ setChangesetsForFirstThreeLines(FILE_4_REF);
+
+ underTest.execute();
+
+ assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d);
+ assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_DUPLICATED_LINES_KEY, 0d);
+ assertRawMeasureValueOnPeriod(FILE_3_REF, NEW_DUPLICATED_LINES_KEY, 2d);
+ assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_DUPLICATED_LINES_KEY, 2d);
+ assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_DUPLICATED_LINES_KEY, 2d);
+ assertNoRawMeasure(DIRECTORY_2_REF, NEW_DUPLICATED_LINES_KEY);
+ assertRawMeasureValueOnPeriod(SUB_MODULE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d);
+ assertRawMeasureValueOnPeriod(SUB_MODULE_2_REF, NEW_DUPLICATED_LINES_KEY, 4d);
+ assertRawMeasureValueOnPeriod(MODULE_REF, NEW_DUPLICATED_LINES_KEY, 6d);
+ assertRawMeasureValueOnPeriod(ROOT_REF, NEW_DUPLICATED_LINES_KEY, 6d);
+ }
@Test
public void compute_and_aggregate_zero_duplicated_line_when_no_duplication() {
@@ -344,6 +387,15 @@ public class NewSizeMeasuresStepTest {
duplicationRepository.addDuplication(fileRef, original, duplicates);
}
+ private void setChangesetsForFirstThreeLines(int... componentRefs) {
+ Arrays.stream(componentRefs)
+ .forEach(componentRef -> scmInfoRepository.setScmInfo(componentRef,
+ Changeset.newChangesetBuilder().setDate(parseDate("2011-01-01").getTime()).setRevision("rev-1").build(),
+ Changeset.newChangesetBuilder().setDate(parseDate("2011-01-01").getTime()).setRevision("rev-1").build(),
+ // line 3 is older, part of no period
+ Changeset.newChangesetBuilder().setDate(parseDate("2007-01-15").getTime()).setRevision("rev-2").build()));
+ }
+
private void setChangesets(int... componentRefs) {
Arrays.stream(componentRefs)
.forEach(componentRef -> scmInfoRepository.setScmInfo(componentRef,
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStepTest.java
index fbe3fc3d105..8d5246ef961 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStepTest.java
@@ -190,7 +190,10 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
.setAuthor("john")
.setDate(123456789L)
.setRevision("rev-1")
- .build());
+ .build(),
+ Changeset.newChangesetBuilder()
+ .setDate(223456789L)
+ .build());
underTest.execute();
@@ -208,12 +211,13 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
assertThat(data.getLines(0).getScmRevision()).isEqualTo("rev-1");
assertThat(data.getLines(1).getScmAuthor()).isEmpty();
- assertThat(data.getLines(1).getScmDate()).isEqualTo(0);
+ assertThat(data.getLines(1).getScmDate()).isEqualTo(223456789L);
assertThat(data.getLines(1).getScmRevision()).isEmpty();
assertThat(data.getLines(2).getScmAuthor()).isEmpty();
assertThat(data.getLines(2).getScmDate()).isEqualTo(0);
assertThat(data.getLines(2).getScmRevision()).isEmpty();
+
}
@Test