aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-core-plugin/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-12-15 14:22:10 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-12-17 13:14:49 +0100
commit789df9c9ba0ccdf72e5e5ab24de04b47798e4f72 (patch)
tree224d9625710131d51bc0f23cfbfbb2109b604112 /plugins/sonar-core-plugin/src
parent597cf003728da27dac4a51a624358263ff8e88f7 (diff)
downloadsonarqube-789df9c9ba0ccdf72e5e5ab24de04b47798e4f72.tar.gz
sonarqube-789df9c9ba0ccdf72e5e5ab24de04b47798e4f72.zip
SONAR-5945 Upload issues in analysis report
Diffstat (limited to 'plugins/sonar-core-plugin/src')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java12
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java11
2 files changed, 16 insertions, 7 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 4b8a0225162..17cee708dd0 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
@@ -30,6 +30,7 @@ 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 org.sonar.batch.index.ResourceCache;
import java.util.List;
@@ -37,24 +38,25 @@ import java.util.List;
public final class TimeMachineConfigurationPersister implements Decorator {
private final TimeMachineConfiguration timeMachineConfiguration;
- private Snapshot projectSnapshot;
+ private ResourceCache resourceCache;
private DatabaseSession session;
- public TimeMachineConfigurationPersister(TimeMachineConfiguration timeMachineConfiguration, Snapshot projectSnapshot, DatabaseSession session) {
+ public TimeMachineConfigurationPersister(TimeMachineConfiguration timeMachineConfiguration, ResourceCache resourceCache, DatabaseSession session) {
this.timeMachineConfiguration = timeMachineConfiguration;
- this.projectSnapshot = projectSnapshot;
+ this.resourceCache = resourceCache;
this.session = session;
}
@Override
public void decorate(Resource resource, DecoratorContext context) {
if (ResourceUtils.isProject(resource)) {
- persistConfiguration();
+ persistConfiguration(resource);
}
}
- void persistConfiguration() {
+ void persistConfiguration(Resource module) {
List<PastSnapshot> pastSnapshots = timeMachineConfiguration.getProjectPastSnapshots();
+ Snapshot projectSnapshot = resourceCache.get(module.getEffectiveKey()).snapshot();
for (PastSnapshot pastSnapshot : pastSnapshots) {
Snapshot snapshot = session.reattach(Snapshot.class, projectSnapshot.getId());
updatePeriodParams(snapshot, pastSnapshot);
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 a34e57b340a..4f9ac63c11f 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
@@ -21,9 +21,11 @@ package org.sonar.plugins.core.timemachine;
import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Project;
import org.sonar.api.utils.DateUtils;
import org.sonar.batch.components.PastSnapshot;
import org.sonar.batch.components.TimeMachineConfiguration;
+import org.sonar.batch.index.ResourceCache;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.util.Arrays;
@@ -45,8 +47,13 @@ public class TimeMachineConfigurationPersisterTest extends AbstractDbUnitTestCas
when(timeMachineConfiguration.getProjectPastSnapshots()).thenReturn(Arrays.asList(vs1, vs3));
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
- TimeMachineConfigurationPersister persister = new TimeMachineConfigurationPersister(timeMachineConfiguration, projectSnapshot, getSession());
- persister.persistConfiguration();
+ ResourceCache resourceCache = new ResourceCache();
+ Project project = new Project("foo");
+ resourceCache.add(project, projectSnapshot);
+
+ TimeMachineConfigurationPersister persister = new TimeMachineConfigurationPersister(timeMachineConfiguration, resourceCache, getSession());
+
+ persister.persistConfiguration(project);
checkTables("shouldSaveConfigurationInSnapshotsTable", "snapshots");
}