*/
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;
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());
}
session.commit();
}
+
+ public boolean shouldExecuteOnProject(Project project) {
+ return true;
+ }
}
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
TimeMachineConfigurationPersister persister = new TimeMachineConfigurationPersister(conf, projectSnapshot, getSession());
- persister.start();
+ persister.persistConfiguration();
checkTables("shouldSaveConfigurationInSnapshotsTable", "snapshots");
}