diff options
Diffstat (limited to 'sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java index 9bf15e1414c..ed353e975d7 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java @@ -24,6 +24,7 @@ import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Qualifiers; +import java.util.Date; import java.util.List; public class PastSnapshotFinderByVersion implements BatchExtension { @@ -36,6 +37,9 @@ public class PastSnapshotFinderByVersion implements BatchExtension { this.session = session; } + /** + * See comments in {@link PastSnapshotFinderByPreviousAnalysis#findByPreviousAnalysis(Snapshot)} + */ PastSnapshot findByVersion(Snapshot projectSnapshot, String version) { String hql = "from " + Snapshot.class.getSimpleName() + " where version=:version AND resourceId=:resourceId AND status=:status AND qualifier<>:lib order by createdAt desc"; List<Snapshot> snapshots = session.createQuery(hql) @@ -46,11 +50,16 @@ public class PastSnapshotFinderByVersion implements BatchExtension { .setMaxResults(1) .getResultList(); + Snapshot snapshot; + Date targetDate; if (snapshots.isEmpty()) { - return null; + snapshot = null; + targetDate = new Date(projectSnapshot.getCreatedAt().getTime() - 1000 * 60); + } else { + snapshot = snapshots.get(0); + targetDate = snapshot.getCreatedAt(); } - Snapshot snapshot = snapshots.get(0); - return new PastSnapshot(MODE, snapshot.getCreatedAt(), snapshot).setModeParameter(snapshot.getVersion()); + return new PastSnapshot(MODE, targetDate, snapshot).setModeParameter(version); } } |