diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-09-23 10:31:32 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-09-23 10:31:42 +0200 |
commit | c2d669ea9edd761618a9c4ae930ffdf47cc3895e (patch) | |
tree | 0998018980eb19c4a99d19b6ac50d4d95410ff25 /sonar-batch | |
parent | ec08fec5ef1c71578d86ca3e446a7573d43c5dc6 (diff) | |
download | sonarqube-c2d669ea9edd761618a9c4ae930ffdf47cc3895e.tar.gz sonarqube-c2d669ea9edd761618a9c4ae930ffdf47cc3895e.zip |
SONAR-4699 Period by date should return null when no snapshot found
Diffstat (limited to 'sonar-batch')
4 files changed, 33 insertions, 2 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java index 0d685dae152..0af30a75648 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java @@ -26,6 +26,8 @@ import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Qualifiers; import org.sonar.api.utils.DateUtils; +import javax.annotation.Nullable; + import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @@ -47,7 +49,7 @@ public class PastSnapshotFinderByDate implements BatchExtension { return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DATE, date, snapshot).setModeParameter(format.format(date)); } - + @Nullable private Snapshot findSnapshot(Snapshot projectSnapshot, Date date) { String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt>=:date AND resourceId=:resourceId AND status=:status AND qualifier<>:lib order by createdAt asc"; List<Snapshot> snapshots = session.createQuery(hql) diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java index 13afc476278..acba9bf0b23 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java @@ -26,6 +26,8 @@ import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Qualifiers; +import javax.annotation.Nullable; + import java.util.Date; import java.util.List; @@ -51,11 +53,13 @@ public class PastSnapshotFinderByDays implements BatchExtension { return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, targetDate, snapshot).setModeParameter(String.valueOf(days)); } + @Nullable static Snapshot getNearestToTarget(List<Snapshot> snapshots, Date currentDate, int distanceInDays) { Date targetDate = DateUtils.addDays(currentDate, -distanceInDays); return getNearestToTarget(snapshots, targetDate); } + @Nullable static Snapshot getNearestToTarget(List<Snapshot> snapshots, Date targetDate) { long bestDistance = Long.MAX_VALUE; Snapshot nearest = null; diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java index 02c0264c946..89d83f939ea 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java @@ -31,6 +31,7 @@ import org.sonar.api.resources.Project; import org.sonar.api.resources.Qualifiers; import javax.persistence.Query; + import java.util.Date; import java.util.List; @@ -68,7 +69,8 @@ public class TimeMachineConfiguration implements BatchExtension { if (projectSnapshot != null) { for (int index = 1; index <= NUMBER_OF_VARIATION_SNAPSHOTS; index++) { PastSnapshot pastSnapshot = pastSnapshotFinder.find(projectSnapshot, rootQualifier, settings, index); - if (pastSnapshot != null) { + // SONAR-4700 Add a past snapshot only if it exists + if (pastSnapshot != null && pastSnapshot.getProjectSnapshot() != null) { log(pastSnapshot); projectPastSnapshots.add(pastSnapshot); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/components/package-info.java new file mode 100644 index 00000000000..371aa8e6bc2 --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/components/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +@ParametersAreNonnullByDefault +package org.sonar.batch.components; + +import javax.annotation.ParametersAreNonnullByDefault; |