]> source.dussan.org Git - sonarqube.git/commitdiff
merge 2.5-RC2: save SNAPSHOTS.VARIATION_x columns on views
authorsimonbrandhof <simon.brandhof@gmail.com>
Mon, 10 Jan 2011 15:23:06 +0000 (16:23 +0100)
committersimonbrandhof <simon.brandhof@gmail.com>
Mon, 10 Jan 2011 15:23:06 +0000 (16:23 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java

index 4e1bba5d7c327c6130c2c21e7be7d856c3996fe4..5d2e923e70a48ec13f0aff30bb474c454b4ff4e3 100644 (file)
  */
 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<PastSnapshot> 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;
+  }
 }
index 6c0477004f51ae4f2c5f5dc173b99adb288b841b..20bf7ddcdf2674bd969d9db46c76f22830df36ff 100644 (file)
@@ -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");
   }