aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/main/java/org/sonar/batch/components
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-02-08 17:16:37 +0100
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-02-08 17:26:23 +0100
commit9e32b6710276aa0b187b4ee388fcd9b99ded7262 (patch)
tree64c46c7bf4f4aa0a8877b5816374eec10eb163dd /sonar-batch/src/main/java/org/sonar/batch/components
parent8533722613d9498974d621ba0ebf143ffcecb6fb (diff)
downloadsonarqube-9e32b6710276aa0b187b4ee388fcd9b99ded7262.tar.gz
sonarqube-9e32b6710276aa0b187b4ee388fcd9b99ded7262.zip
SONAR-4009 For "previous_version", Sonar must look into "events" table
=> The behavior of "previous_version" option to define a differential view used to depend on the content of the snapshot.version column but not of the events table. This could give wrong results.
Diffstat (limited to 'sonar-batch/src/main/java/org/sonar/batch/components')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java34
1 files changed, 17 insertions, 17 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java
index b0b54947df1..ee378232bba 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java
@@ -21,11 +21,10 @@ package org.sonar.batch.components;
import org.sonar.api.BatchExtension;
import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.Event;
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 PastSnapshotFinderByPreviousVersion implements BatchExtension {
@@ -37,25 +36,26 @@ public class PastSnapshotFinderByPreviousVersion implements BatchExtension {
}
PastSnapshot findByPreviousVersion(Snapshot projectSnapshot) {
- String hql = "from " + Snapshot.class.getSimpleName() +
- " where version<>:version AND version IS NOT NULL AND resourceId=:resourceId AND status=:status AND qualifier<>:lib order by createdAt desc";
- List<Snapshot> snapshots = session.createQuery(hql)
- .setParameter("version", projectSnapshot.getVersion())
- .setParameter("resourceId", projectSnapshot.getResourceId())
- .setParameter("status", Snapshot.STATUS_PROCESSED)
- .setParameter("lib", Qualifiers.LIBRARY)
+ String currentVersion = projectSnapshot.getVersion();
+ Integer resourceId = projectSnapshot.getResourceId();
+
+ String hql = "from " + Event.class.getSimpleName() +
+ " where name<>:version AND category='Version' AND resourceId=:resourceId ORDER BY date DESC";
+
+ List<Event> events = session.createQuery(hql)
+ .setParameter("version", currentVersion)
+ .setParameter("resourceId", resourceId)
.setMaxResults(1)
.getResultList();
- PastSnapshot result;
- if (snapshots.isEmpty()) {
- result = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
- } else {
- Snapshot snapshot = snapshots.get(0);
- Date targetDate = snapshot.getCreatedAt();
- result = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, targetDate, snapshot).setModeParameter(snapshot.getVersion());
+ if (events.isEmpty()) {
+ return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
}
- return result;
+
+ Event previousVersionEvent = events.get(0);
+ Snapshot snapshot = session.getSingleResult(Snapshot.class, "id", previousVersionEvent.getSnapshot().getId());
+
+ return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, snapshot.getCreatedAt(), snapshot).setModeParameter(snapshot.getVersion());
}
}