aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-11-29 21:01:04 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-11-29 21:01:04 +0000
commitcff65d9bbd2e9ed8542695daed8be62bc3026916 (patch)
tree8ca540b3e598ed87c30a0a4327e97e2a8d99a22c /sonar-batch
parent83b138bebbbf508cb5d913494daef67826fde583 (diff)
downloadsonarqube-cff65d9bbd2e9ed8542695daed8be62bc3026916.tar.gz
sonarqube-cff65d9bbd2e9ed8542695daed8be62bc3026916.zip
SONAR-1450 add the parameter "boolean checkOlder" to ResourcePersister#getLastSnapshot()
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/BatchPluginRepository.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java13
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java2
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot.xml2
7 files changed, 22 insertions, 14 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/BatchPluginRepository.java b/sonar-batch/src/main/java/org/sonar/batch/BatchPluginRepository.java
index f4ef2689516..63e3a957e05 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/BatchPluginRepository.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/BatchPluginRepository.java
@@ -19,10 +19,7 @@
*/
package org.sonar.batch;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.List;
-
+import com.google.common.collect.Lists;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
@@ -42,7 +39,9 @@ import org.sonar.core.plugin.JpaPlugin;
import org.sonar.core.plugin.JpaPluginDao;
import org.sonar.core.plugin.JpaPluginFile;
-import com.google.common.collect.Lists;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
public class BatchPluginRepository extends AbstractPluginRepository {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
index 05f5ef18803..fb626dc498a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
@@ -168,11 +168,16 @@ public final class DefaultResourcePersister implements ResourcePersister {
return snapshot;
}
- public Snapshot getPreviousLastSnapshot(Snapshot snapshot) {
- Query query = session.createQuery(
- "SELECT s FROM " + Snapshot.class.getSimpleName() + " s " +
- "WHERE s.last=true AND s.resourceId=:resourceId");
+ public Snapshot getLastSnapshot(Snapshot snapshot, boolean onlyOlder) {
+ String hql = "SELECT s FROM " + Snapshot.class.getSimpleName() + " s WHERE s.last=true AND s.resourceId=:resourceId";
+ if (onlyOlder) {
+ hql += " AND s.createdAt<:date";
+ }
+ Query query = session.createQuery(hql);
query.setParameter("resourceId", snapshot.getResourceId());
+ if (onlyOlder) {
+ query.setParameter("date", snapshot.getCreatedAt());
+ }
return session.getSingleResult(query, null);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java
index 6a332562cd3..644c3261b21 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java
@@ -30,7 +30,11 @@ public interface ResourcePersister {
Snapshot saveResource(Project project, Resource resource);
- Snapshot getPreviousLastSnapshot(Snapshot snapshot);
+ /**
+ * The current snapshot which is flagged as "last"
+ * @param onlyOlder true if the result must be anterior to the snapshot parameter
+ */
+ Snapshot getLastSnapshot(Snapshot snapshot, boolean onlyOlder);
void clear();
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java
index 934aaadb7bd..ef085b35680 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java
@@ -45,7 +45,7 @@ public final class ViolationPersister {
public List<RuleFailureModel> getPreviousViolations(Resource resource) {
Snapshot snapshot = resourcePersister.getSnapshot(resource);
- Snapshot previousLastSnapshot = resourcePersister.getPreviousLastSnapshot(snapshot);
+ Snapshot previousLastSnapshot = resourcePersister.getLastSnapshot(snapshot, true);
if (previousLastSnapshot == null) {
return Collections.emptyList();
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
index 80c3368816b..5c04142aadc 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
@@ -43,7 +43,7 @@ public class UpdateStatusJob implements BatchComponent {
}
public void execute() {
- Snapshot previousLastSnapshot = resourcePersister.getPreviousLastSnapshot(snapshot);
+ Snapshot previousLastSnapshot = resourcePersister.getLastSnapshot(snapshot, false);
updateFlags(snapshot, previousLastSnapshot);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java
index f4b3164345f..d4e60a18baf 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java
@@ -54,7 +54,7 @@ public class ViolationPersisterTest extends AbstractDbUnitTestCase {
Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
ResourcePersister resourcePersister = mock(ResourcePersister.class);
when(resourcePersister.saveResource((Project) anyObject(), eq(javaFile))).thenReturn(snapshot);
- when(resourcePersister.getPreviousLastSnapshot(snapshot)).thenReturn(snapshot);
+ when(resourcePersister.getLastSnapshot(snapshot, true)).thenReturn(snapshot);
when(resourcePersister.getSnapshot(javaFile)).thenReturn(snapshot);
violationPersister = new ViolationPersister(getSession(), resourcePersister, new DefaultRuleFinder(getSessionFactory()));
}
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot.xml b/sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot.xml
index 523a66915f4..94f589a471f 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot.xml
@@ -27,7 +27,7 @@
path="[null]"/>
- <!-- the snapshot to process -->
+ <!-- the snapshot to process : before last snapshot -->
<snapshots depth="[null]" id="6" scope="PRJ" qualifier="TRK" created_at="2005-10-01 00:00:00.00" version="[null]"
project_id="1"
parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="[null]"