.transform(new LineIndexToChangeset(changesets)));
}
- private static Changeset convert(BatchReport.Changesets.Changeset changeset) {
- checkState(changeset.hasRevision(), "Changeset must have a revision");
- checkState(changeset.hasDate(), "Changeset must have a date");
- return Changeset.newChangesetBuilder()
- .setRevision(changeset.getRevision())
- .setAuthor(changeset.hasAuthor() ? changeset.getAuthor() : null)
- .setDate(changeset.getDate())
- .build();
- }
-
@Override
public Changeset getLatestChangeset() {
return this.delegate.getLatestChangeset();
private static class LineIndexToChangeset implements Function<Integer, Changeset> {
private final BatchReport.Changesets changesets;
- private final Map<Integer, Changeset> changeSetCache;
+ private final Map<Integer, Changeset> changesetCache;
public LineIndexToChangeset(BatchReport.Changesets changesets) {
this.changesets = changesets;
- changeSetCache = new HashMap<>(changesets.getChangesetCount());
+ changesetCache = new HashMap<>(changesets.getChangesetCount());
}
@Override
@Nonnull
public Changeset apply(@Nonnull Integer lineNumber) {
int changesetIndex = changesets.getChangesetIndexByLine(lineNumber - 1);
- if (changeSetCache.containsKey(changesetIndex)) {
- return changeSetCache.get(changesetIndex);
+ Changeset changeset = changesetCache.get(changesetIndex);
+ if (changeset != null) {
+ return changeset;
}
- Changeset res = convert(changesets.getChangeset(changesetIndex));
- changeSetCache.put(changesetIndex, res);
+ Changeset res = convert(changesets.getChangeset(changesetIndex), lineNumber);
+ changesetCache.put(changesetIndex, res);
return res;
}
+
+ private static Changeset convert(BatchReport.Changesets.Changeset changeset, int line) {
+ checkState(changeset.hasRevision(), "Changeset on line %s must have a revision", line);
+ checkState(changeset.hasDate(), "Changeset on line %s must have a date", line);
+ return Changeset.newChangesetBuilder()
+ .setRevision(changeset.getRevision())
+ .setAuthor(changeset.hasAuthor() ? changeset.getAuthor() : null)
+ .setDate(changeset.getDate())
+ .build();
+ }
}
/**
@Test
public void fail_with_ISE_when_changeset_has_no_revision() throws Exception {
thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Changeset must have a revision");
+ thrown.expectMessage("Changeset on line 1 must have a revision");
new ReportScmInfo(BatchReport.Changesets.newBuilder()
.setComponentRef(FILE_REF)
@Test
public void fail_with_ISE_when_changeset_has_no_date() throws Exception {
thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Changeset must have a date");
+ thrown.expectMessage("Changeset on line 1 must have a date");
new ReportScmInfo(BatchReport.Changesets.newBuilder()
.setComponentRef(FILE_REF)