diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-12-09 11:51:24 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-12-09 17:23:56 +0100 |
commit | 02dbaef58e3ef830faec084461bb8295a11a6769 (patch) | |
tree | 77a6695eda04cc06bb39cbe9651a1b8cacd199ed /sonar-batch | |
parent | a789f25232f010dfcbbed6f5133f156435b6199c (diff) | |
download | sonarqube-02dbaef58e3ef830faec084461bb8295a11a6769.tar.gz sonarqube-02dbaef58e3ef830faec084461bb8295a11a6769.zip |
SONAR-6887 Improve message when missing revision or date on blame
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java | 16 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/scm/DefaultBlameOutputTest.java | 14 |
2 files changed, 15 insertions, 15 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java index 24e1783e97b..00a4029330f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java @@ -70,10 +70,10 @@ class DefaultBlameOutput implements BlameOutput { public synchronized void blameResult(InputFile file, List<BlameLine> lines) { Preconditions.checkNotNull(file); Preconditions.checkNotNull(lines); - Preconditions.checkArgument(allFilesToBlame.contains(file), "It was not expected to blame file " + file.relativePath()); + Preconditions.checkArgument(allFilesToBlame.contains(file), "It was not expected to blame file %s", file.relativePath()); if (lines.size() != file.lines()) { - LOG.debug("Ignoring blame result since provider returned " + lines.size() + " blame lines but file " + file.relativePath() + " has " + file.lines() + " lines"); + LOG.debug("Ignoring blame result since provider returned {} blame lines but file {} has {} lines", lines.size(), file.relativePath(), file.lines()); return; } @@ -82,8 +82,9 @@ class DefaultBlameOutput implements BlameOutput { scmBuilder.setComponentRef(batchComponent.batchId()); Map<String, Integer> changesetsIdByRevision = new HashMap<>(); + int lineId = 1; for (BlameLine line : lines) { - validateLine(line); + validateLine(line, lineId, file); Integer changesetId = changesetsIdByRevision.get(line.revision()); if (changesetId == null) { addChangeset(scmBuilder, line); @@ -91,6 +92,7 @@ class DefaultBlameOutput implements BlameOutput { changesetsIdByRevision.put(line.revision(), changesetId); } scmBuilder.addChangesetIndexByLine(changesetId); + lineId++; } writer.writeComponentChangesets(scmBuilder.build()); allFilesToBlame.remove(file); @@ -98,9 +100,9 @@ class DefaultBlameOutput implements BlameOutput { progressReport.message(count + "/" + total + " files analyzed"); } - private static void validateLine(BlameLine line) { - Preconditions.checkNotNull(line.revision(), "Blame revision cannot be null"); - Preconditions.checkNotNull(line.date(), "Blame date cannot be null"); + private static void validateLine(BlameLine line, int lineId, InputFile file) { + Preconditions.checkArgument(StringUtils.isNotBlank(line.revision()), "Blame revision is blank for file %s at line %s", file.relativePath(), lineId); + Preconditions.checkArgument(line.date() != null, "Blame date is null for file %s at line %s", file.relativePath(), lineId); } private static void addChangeset(Builder scmBuilder, BlameLine line) { @@ -131,7 +133,7 @@ class DefaultBlameOutput implements BlameOutput { private static String removeNonAsciiCharacters(String inputString) { return NON_ASCII_CHARS.matcher(inputString).replaceAll("_"); } - + public void finish() { progressReport.stop(count + "/" + total + " files analyzed"); if (!allFilesToBlame.isEmpty()) { diff --git a/sonar-batch/src/test/java/org/sonar/batch/scm/DefaultBlameOutputTest.java b/sonar-batch/src/test/java/org/sonar/batch/scm/DefaultBlameOutputTest.java index e7f00149111..3060951b4e9 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scm/DefaultBlameOutputTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scm/DefaultBlameOutputTest.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.scm; +import java.util.Arrays; +import java.util.Date; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -30,11 +32,7 @@ import org.sonar.api.batch.scm.BlameLine; import org.sonar.batch.index.BatchComponent; import org.sonar.batch.index.BatchComponentCache; -import java.util.Arrays; -import java.util.Date; - import static org.mockito.Matchers.any; - import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -75,8 +73,8 @@ public class DefaultBlameOutputTest { public void shouldFailIfNullDate() { InputFile file = new DefaultInputFile("foo", "src/main/java/Foo.java").setLines(1); - thrown.expect(NullPointerException.class); - thrown.expectMessage("Blame date cannot be null"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Blame date is null for file src/main/java/Foo.java at line 1"); new DefaultBlameOutput(null, componentCache, Arrays.<InputFile>asList(file)) .blameResult(file, Arrays.asList(new BlameLine().revision("1").author("guy"))); @@ -86,8 +84,8 @@ public class DefaultBlameOutputTest { public void shouldFailIfNullRevision() { InputFile file = new DefaultInputFile("foo", "src/main/java/Foo.java").setLines(1); - thrown.expect(NullPointerException.class); - thrown.expectMessage("Blame revision cannot be null"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Blame revision is blank for file src/main/java/Foo.java at line 1"); new DefaultBlameOutput(null, componentCache, Arrays.<InputFile>asList(file)) .blameResult(file, Arrays.asList(new BlameLine().date(new Date()).author("guy"))); |