diff options
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java | 27 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java | 4 | ||||
-rw-r--r-- | sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/shouldNotEnableSnapshotWhenNotLatest-result.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot-result.xml) | 0 | ||||
-rw-r--r-- | sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/shouldNotEnableSnapshotWhenNotLatest.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot.xml) | 0 |
4 files changed, 22 insertions, 9 deletions
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 8f3040d55b4..cc742bdc0d4 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 @@ -23,10 +23,12 @@ import org.slf4j.LoggerFactory; import org.sonar.api.BatchComponent; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.Snapshot; +import org.sonar.api.resources.Scopes; import org.sonar.batch.ServerMetadata; import org.sonar.batch.index.ResourcePersister; import javax.persistence.Query; +import java.util.List; public class UpdateStatusJob implements BatchComponent { @@ -43,17 +45,28 @@ public class UpdateStatusJob implements BatchComponent { } public void execute() { - Snapshot previousLastSnapshot = resourcePersister.getLastSnapshot(snapshot, false); - updateFlags(snapshot, previousLastSnapshot); + disablePreviousSnapshot(); + enableCurrentSnapshot(); } - private void updateFlags(Snapshot rootSnapshot, Snapshot previousLastSnapshot) { - if (previousLastSnapshot != null && previousLastSnapshot.getCreatedAt().before(rootSnapshot.getCreatedAt())) { - setFlags(previousLastSnapshot, false, null); + private void disablePreviousSnapshot() { + // disable on all modules + Query query = session.createQuery("FROM " + Snapshot.class.getSimpleName() + " WHERE (root_snapshot_id=:rootId OR id=:rootId) AND scope=:scope"); + query.setParameter("rootId", snapshot.getId()); + query.setParameter("scope", Scopes.PROJECT); + List<Snapshot> moduleSnapshots = query.getResultList(); + for (Snapshot moduleSnapshot : moduleSnapshots) { + Snapshot previousLastSnapshot = resourcePersister.getLastSnapshot(moduleSnapshot, true); + if (previousLastSnapshot != null) { + setFlags(previousLastSnapshot, false, null); + } } + } - boolean isLast = (previousLastSnapshot == null || previousLastSnapshot.getCreatedAt().before(rootSnapshot.getCreatedAt())); - setFlags(rootSnapshot, isLast, Snapshot.STATUS_PROCESSED); + private void enableCurrentSnapshot() { + Snapshot previousLastSnapshot = resourcePersister.getLastSnapshot(snapshot, false); + boolean isLast = (previousLastSnapshot == null || previousLastSnapshot.getCreatedAt().before(snapshot.getCreatedAt())); + setFlags(snapshot, isLast, Snapshot.STATUS_PROCESSED); LoggerFactory.getLogger(getClass()).info("ANALYSIS SUCCESSFUL, you can browse {}", server.getURL()); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java index e6680f5fb3b..320db8e9608 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java @@ -43,8 +43,8 @@ public class UpdateStatusJobTest extends AbstractDbUnitTestCase { } @Test - public void lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot() { - assertAnalysis(6, "lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot"); + public void shouldNotEnableSnapshotWhenNotLatest() { + assertAnalysis(6, "shouldNotEnableSnapshotWhenNotLatest"); } private void assertAnalysis(int snapshotId, String fixture) { diff --git a/sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/shouldNotEnableSnapshotWhenNotLatest-result.xml index ef665b1aa91..ef665b1aa91 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/shouldNotEnableSnapshotWhenNotLatest-result.xml 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/shouldNotEnableSnapshotWhenNotLatest.xml index 2315b5d8d6a..2315b5d8d6a 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/shouldNotEnableSnapshotWhenNotLatest.xml |