@@ -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) |
@@ -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; |
@@ -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); | |||
} |
@@ -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; |