From 64438bb95377cb144b538dc134e6db33ba4e615d Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Mon, 10 Jan 2011 16:23:06 +0100 Subject: [PATCH] merge 2.5-RC2: save SNAPSHOTS.VARIATION_x columns on views --- .../TimeMachineConfigurationPersister.java | 20 ++++++++++++++++--- ...TimeMachineConfigurationPersisterTest.java | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java index 4e1bba5d7c3..5d2e923e70a 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java @@ -19,15 +19,19 @@ */ package org.sonar.plugins.core.timemachine; -import org.sonar.api.BatchExtension; +import org.sonar.api.batch.Decorator; +import org.sonar.api.batch.DecoratorContext; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.Snapshot; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; +import org.sonar.api.resources.ResourceUtils; import org.sonar.batch.components.PastSnapshot; import org.sonar.batch.components.TimeMachineConfiguration; import java.util.List; -public final class TimeMachineConfigurationPersister implements BatchExtension { +public final class TimeMachineConfigurationPersister implements Decorator { private TimeMachineConfiguration configuration; private Snapshot projectSnapshot; @@ -39,7 +43,13 @@ public final class TimeMachineConfigurationPersister implements BatchExtension { this.session = session; } - public void start() { + public void decorate(Resource resource, DecoratorContext context) { + if (ResourceUtils.isProject(resource)) { + persistConfiguration(); + } + } + + void persistConfiguration() { List pastSnapshots = configuration.getProjectPastSnapshots(); for (PastSnapshot pastSnapshot : pastSnapshots) { projectSnapshot = session.reattach(Snapshot.class, projectSnapshot.getId()); @@ -50,4 +60,8 @@ public final class TimeMachineConfigurationPersister implements BatchExtension { } session.commit(); } + + public boolean shouldExecuteOnProject(Project project) { + return true; + } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java index 6c0477004f5..20bf7ddcdf2 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java @@ -48,7 +48,7 @@ public class TimeMachineConfigurationPersisterTest extends AbstractDbUnitTestCas Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1000); TimeMachineConfigurationPersister persister = new TimeMachineConfigurationPersister(conf, projectSnapshot, getSession()); - persister.start(); + persister.persistConfiguration(); checkTables("shouldSaveConfigurationInSnapshotsTable", "snapshots"); } -- 2.39.5