aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-11-18 15:02:54 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-11-18 15:02:54 +0000
commit4bfd79e52cea465f226c78abb253c2073f4c1d4c (patch)
treed3812db183fbd869e2451148c32b2bd583f1112a /sonar-batch
parentf8ba14ececd0a5b60ec7112d4df3266f105541f5 (diff)
downloadsonarqube-4bfd79e52cea465f226c78abb253c2073f4c1d4c.tar.gz
sonarqube-4bfd79e52cea465f226c78abb253c2073f4c1d4c.zip
SONAR-1663 include the dbcleaner plugin + move all purges in this plugin
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/FinalizeSnapshotsJob.java31
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java15
2 files changed, 2 insertions, 44 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/FinalizeSnapshotsJob.java b/sonar-batch/src/main/java/org/sonar/batch/FinalizeSnapshotsJob.java
index 46bdb418441..722ad0cd7d8 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/FinalizeSnapshotsJob.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/FinalizeSnapshotsJob.java
@@ -19,29 +19,22 @@
*/
package org.sonar.batch;
-import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.Purge;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
-import org.sonar.api.utils.TimeProfiler;
-import org.sonar.core.purge.DefaultPurgeContext;
import javax.persistence.Query;
public class FinalizeSnapshotsJob implements CoreJob {
private DatabaseSession session;
- private Purge[] purges;
private ServerMetadata server;
private Snapshot snapshot;
- public FinalizeSnapshotsJob(ServerMetadata server, DatabaseSession session, Purge[] purges, Snapshot snapshot) {
+ public FinalizeSnapshotsJob(ServerMetadata server, DatabaseSession session, Snapshot snapshot) {
this.session = session;
- this.purges = purges;
this.server = server;
this.snapshot = snapshot;
}
@@ -50,7 +43,6 @@ public class FinalizeSnapshotsJob implements CoreJob {
if (shouldExecuteOn(project)) {
Snapshot previousLastSnapshot = getPreviousLastSnapshot(snapshot);
updateFlags(snapshot, previousLastSnapshot);
- purge(snapshot, previousLastSnapshot);
}
}
@@ -98,25 +90,4 @@ public class FinalizeSnapshotsJob implements CoreJob {
snapshot.setLast(last);
}
-
- private void purge(Snapshot currentSnapshot, Snapshot previousLastSnapshot) {
- final Logger logger = LoggerFactory.getLogger(FinalizeSnapshotsJob.class);
- TimeProfiler profiler = new TimeProfiler(logger).start("Database optimization");
- PurgeContext context = createPurgeContext(currentSnapshot, previousLastSnapshot);
- logger.debug("Snapshots to purge: " + context);
- for (Purge purge : purges) {
- logger.debug("Executing {}...", purge.getClass().getName());
- purge.purge(context);
- }
- profiler.stop();
- }
-
- private PurgeContext createPurgeContext(Snapshot currentSnapshot, Snapshot previousLastSnapshot) {
- DefaultPurgeContext context = new DefaultPurgeContext(currentSnapshot);
- if (previousLastSnapshot != null && previousLastSnapshot.getCreatedAt().before(currentSnapshot.getCreatedAt())) {
- context.setLastSnapshotId(previousLastSnapshot.getId());
- }
- return context;
- }
-
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java b/sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java
index 9158839ea1a..d16822861e4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java
@@ -19,50 +19,37 @@
*/
package org.sonar.batch;
-import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.batch.Purge;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
-import org.sonar.core.purge.DefaultPurgeContext;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import javax.persistence.Query;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
public class FinalizeSnapshotsJobTest extends AbstractDbUnitTestCase {
- private Purge purgeMock=null;
-
- @Before
- public void before() {
- purgeMock = mock(Purge.class);
- }
@Test
public void shouldUnflagPenultimateLastSnapshot() throws Exception {
assertAnalysis(11, "shouldUnflagPenultimateLastSnapshot");
- verify(purgeMock).purge(new DefaultPurgeContext(11, 1));
}
@Test
public void doNotFailIfNoPenultimateLast() throws Exception {
assertAnalysis(5, "doNotFailIfNoPenultimateLast");
- verify(purgeMock).purge(new DefaultPurgeContext(5, null));
}
@Test
public void lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot() {
assertAnalysis(6, "lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot");
- verify(purgeMock).purge(new DefaultPurgeContext(6, null));
}
private void assertAnalysis(int snapshotId, String fixture) {
setupData("sharedFixture", fixture);
- FinalizeSnapshotsJob sensor = new FinalizeSnapshotsJob(mock(ServerMetadata.class), getSession(), new Purge[]{purgeMock}, loadSnapshot(snapshotId));
+ FinalizeSnapshotsJob sensor = new FinalizeSnapshotsJob(mock(ServerMetadata.class), getSession(), loadSnapshot(snapshotId));
sensor.execute(new Project("key"), null);
getSession().stop();