summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/source/SourceDataPersister.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/source/SourceDataPersisterTest.java14
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/HtmlSourceDecorator.java17
3 files changed, 25 insertions, 12 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/source/SourceDataPersister.java b/sonar-batch/src/main/java/org/sonar/batch/scan/source/SourceDataPersister.java
index f301afbaed3..3e601200181 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/source/SourceDataPersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/source/SourceDataPersister.java
@@ -50,16 +50,16 @@ public class SourceDataPersister implements ScanPersister {
private void persistDataCache(String dataType, Map<String, String> sourceDataByComponent) {
- for (Map.Entry<String, String> componentRules : sourceDataByComponent.entrySet()) {
+ for (Map.Entry<String, String> componentData : sourceDataByComponent.entrySet()) {
- Snapshot snapshotForComponent = snapshots.get(componentRules.getKey());
+ Snapshot snapshotForComponent = snapshots.get(componentData.getKey());
SnapshotDataDto snapshotDataDto = new SnapshotDataDto();
if(snapshotForComponent != null) {
snapshotDataDto.setSnapshotId(snapshotForComponent.getId());
snapshotDataDto.setResourceId(snapshotForComponent.getResourceId());
snapshotDataDto.setDataType(dataType);
- snapshotDataDto.setData(sourceDataByComponent.get(componentRules.getValue()));
+ snapshotDataDto.setData(componentData.getValue());
snapshotDataDao.insert(snapshotDataDto);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/source/SourceDataPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/source/SourceDataPersisterTest.java
index f3c17adc614..c28ceb6fc7b 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/source/SourceDataPersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/source/SourceDataPersisterTest.java
@@ -49,16 +49,20 @@ public class SourceDataPersisterTest {
@Test
public void should_persist_source_cache_data() throws Exception {
+ final String componentKey = "component1";
+ final String dataType = "myDataType";
+ final String data = "source data for component 1";
+
Snapshot snapshotComponent1 = mock(Snapshot.class);
when(snapshotComponent1.getId()).thenReturn(1);
when(snapshotComponent1.getResourceId()).thenReturn(1);
Map<String, String> sourceData = Maps.newHashMap();
- sourceData.put("component1", "source data for component 1");
+ sourceData.put(componentKey, data);
when(sourceDataCache.getSourceDataByComponent()).thenReturn(sourceData);
- when(sourceDataCache.getDataType()).thenReturn("myDataType");
- when(snapshots.get("component1")).thenReturn(snapshotComponent1);
+ when(sourceDataCache.getDataType()).thenReturn(dataType);
+ when(snapshots.get(componentKey)).thenReturn(snapshotComponent1);
SourceDataPersister persister = new SourceDataPersister(snapshotDataDao, new SourceDataCache[]{sourceDataCache}, snapshots);
persister.persist();
@@ -67,7 +71,9 @@ public class SourceDataPersisterTest {
@Override
public boolean matches(Object o) {
SnapshotDataDto insertedData = (SnapshotDataDto) o;
- return insertedData.getSnapshotId() == 1 && insertedData.getDataType() == "myDataType";
+ return insertedData.getSnapshotId() == 1
+ && dataType.equals(insertedData.getDataType())
+ && data.equals(insertedData.getData());
}
}));
}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/HtmlSourceDecorator.java b/sonar-core/src/main/java/org/sonar/core/source/HtmlSourceDecorator.java
index 4fb4925a6f0..e8772ee357c 100644
--- a/sonar-core/src/main/java/org/sonar/core/source/HtmlSourceDecorator.java
+++ b/sonar-core/src/main/java/org/sonar/core/source/HtmlSourceDecorator.java
@@ -20,6 +20,7 @@
package org.sonar.core.source;
+import com.google.common.base.Strings;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.source.jdbc.SnapshotDataDao;
import org.sonar.core.source.jdbc.SnapshotDataDto;
@@ -48,11 +49,7 @@ public class HtmlSourceDecorator {
if (snapshotSource != null && snapshotDataEntries != null) {
DecorationDataHolder decorationDataHolder = new DecorationDataHolder();
for (SnapshotDataDto snapshotDataEntry : snapshotDataEntries) {
- if (snapshotDataEntry.isSyntaxHighlightingData()) {
- decorationDataHolder.loadSyntaxHighlightingData(snapshotDataEntry.getData());
- } else if (snapshotDataEntry.isSymbolData()) {
- decorationDataHolder.loadSymbolReferences(snapshotDataEntry.getData());
- }
+ loadSnapshotData(decorationDataHolder, snapshotDataEntry);
}
HtmlTextDecorator textDecorator = new HtmlTextDecorator();
@@ -60,4 +57,14 @@ public class HtmlSourceDecorator {
}
return null;
}
+
+ private void loadSnapshotData(DecorationDataHolder decorationDataHolder, SnapshotDataDto snapshotDataEntry) {
+ if(!Strings.isNullOrEmpty(snapshotDataEntry.getData())) {
+ if (snapshotDataEntry.isSyntaxHighlightingData()) {
+ decorationDataHolder.loadSyntaxHighlightingData(snapshotDataEntry.getData());
+ } else if (snapshotDataEntry.isSymbolData()) {
+ decorationDataHolder.loadSymbolReferences(snapshotDataEntry.getData());
+ }
+ }
+ }
}