aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>2013-04-16 14:56:11 +0200
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>2013-04-16 14:56:11 +0200
commitbd54127720ea1254ea838c8fdb8cddabecc67002 (patch)
treeff8435eb273dae57fd321a6e88537eb6032087f8
parente4e691565a645095c089a8268b12329b9433bdb4 (diff)
downloadsonarqube-bd54127720ea1254ea838c8fdb8cddabecc67002.tar.gz
sonarqube-bd54127720ea1254ea838c8fdb8cddabecc67002.zip
SONAR-3893 Symbol data deserialization
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/source/SymbolDataCache.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/source/SymbolDataPersister.java30
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/source/SyntaxHighlightingCache.java6
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/DecorationDataHolder.java (renamed from sonar-core/src/main/java/org/sonar/core/source/HighlightingContext.java)39
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/HtmlTextDecorator.java (renamed from sonar-core/src/main/java/org/sonar/core/source/HtmlTextWrapper.java)10
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/SourceDecorator.java (renamed from sonar-core/src/main/java/org/sonar/core/source/SyntaxHighlighter.java)27
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataDao.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataDto.java11
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataMapper.java4
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/source/jdbc/SnapshotDataMapper.xml7
-rw-r--r--sonar-core/src/test/java/org/sonar/core/source/DecorationDataHolderTest.java (renamed from sonar-core/src/test/java/org/sonar/core/source/HighlightingContextTest.java)33
-rw-r--r--sonar-core/src/test/java/org/sonar/core/source/HtmlTextDecoratorTest.java (renamed from sonar-core/src/test/java/org/sonar/core/source/HtmlTextWrapperTest.java)69
-rw-r--r--sonar-core/src/test/java/org/sonar/core/source/SourceDecoratorTest.java (renamed from sonar-core/src/test/java/org/sonar/core/source/SyntaxHighlighterTest.java)6
-rw-r--r--sonar-core/src/test/java/org/sonar/core/source/jdbc/SnapshotDataDaoTest.java14
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/source/SourceDecoratorTest/shared.xml (renamed from sonar-core/src/test/resources/org/sonar/core/source/SyntaxHighlighterTest/shared.xml)0
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/source/jdbc/SnapshotDataDaoTest/shared.xml3
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java4
19 files changed, 160 insertions, 119 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
index 4970de6ce97..2180eb20b4e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
@@ -56,6 +56,7 @@ import org.sonar.batch.scan.filesystem.ExclusionFilters;
import org.sonar.batch.scan.filesystem.FileSystemLogger;
import org.sonar.batch.scan.filesystem.LanguageFilters;
import org.sonar.batch.scan.filesystem.ModuleFileSystemProvider;
+import org.sonar.batch.scan.source.SymbolPerspectiveBuilder;
import org.sonar.core.component.ScanPerspectives;
import org.sonar.batch.scan.source.HighlightableBuilder;
@@ -124,6 +125,7 @@ public class ModuleScanContainer extends ComponentContainer {
IssuableFactory.class,
HighlightableBuilder.class,
+ SymbolPerspectiveBuilder.class,
ScanPerspectives.class
);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/source/SymbolDataCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan/source/SymbolDataCache.java
index 7d8607a5dfe..0608659645d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/source/SymbolDataCache.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/source/SymbolDataCache.java
@@ -20,12 +20,12 @@
package org.sonar.batch.scan.source;
-public class SymbolDataCache extends SourceDataCache {
+import org.sonar.core.source.jdbc.SnapshotDataDto;
- public static final String DATA_TYPE = "symbol";
+public class SymbolDataCache extends SourceDataCache {
@Override
public String getDataType() {
- return DATA_TYPE;
+ return SnapshotDataDto.SYMBOL;
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/source/SymbolDataPersister.java b/sonar-batch/src/main/java/org/sonar/batch/scan/source/SymbolDataPersister.java
deleted file mode 100644
index 1bbbe1826fd..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/source/SymbolDataPersister.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package org.sonar.batch.scan.source;
-
-import org.sonar.batch.index.ScanPersister;
-
-public class SymbolDataPersister implements ScanPersister {
- @Override
- public void persist() {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/source/SyntaxHighlightingCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan/source/SyntaxHighlightingCache.java
index 6783c816cc4..aa56cdb51a2 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/source/SyntaxHighlightingCache.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/source/SyntaxHighlightingCache.java
@@ -20,12 +20,12 @@
package org.sonar.batch.scan.source;
-public class SyntaxHighlightingCache extends SourceDataCache {
+import org.sonar.core.source.jdbc.SnapshotDataDto;
- public static final String DATA_TYPE = "highlight_syntax";
+public class SyntaxHighlightingCache extends SourceDataCache {
@Override
public String getDataType() {
- return DATA_TYPE;
+ return SnapshotDataDto.HIGHLIGHT_SYNTAX;
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/HighlightingContext.java b/sonar-core/src/main/java/org/sonar/core/source/DecorationDataHolder.java
index ea0a54d8e09..cf3f8e6bfc5 100644
--- a/sonar-core/src/main/java/org/sonar/core/source/HighlightingContext.java
+++ b/sonar-core/src/main/java/org/sonar/core/source/DecorationDataHolder.java
@@ -24,32 +24,42 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
+import java.util.Arrays;
import java.util.List;
-public class HighlightingContext {
+public class DecorationDataHolder {
- private static final String RULE_SEPARATOR = ";";
+ private static final String ENTITY_SEPARATOR = ";";
private static final String FIELD_SEPARATOR = ",";
+ private static final String SYMBOL_PREFIX = "symbol.";
private final Multimap<Integer, String> lowerBoundsDefinitions;
private final List<Integer> upperBoundsDefinitions;
- private HighlightingContext() {
+ public DecorationDataHolder() {
lowerBoundsDefinitions = TreeMultimap.create();
upperBoundsDefinitions = Lists.newArrayList();
}
- public static HighlightingContext buildFrom(String serializedRules) {
-
- HighlightingContext context = new HighlightingContext();
+ public void loadSymbolReferences(String symbolsReferences) {
+ String[] symbols = symbolsReferences.split(ENTITY_SEPARATOR);
+ for (int i = 0; i < symbols.length; i++) {
+ String[] symbolFields = symbols[i].split(FIELD_SEPARATOR);
+ int declarationStartOffset = Integer.parseInt(symbolFields[0]);
+ int declarationEndOffset = Integer.parseInt(symbolFields[1]);
+ int symbolLength = declarationEndOffset - declarationStartOffset;
+ String[] symbolOccurrences = Arrays.copyOfRange(symbolFields, 2, symbolFields.length);
+ loadSymbolOccurrences(declarationStartOffset, symbolLength, symbolOccurrences);
+ }
+ }
- String[] rules = serializedRules.split(RULE_SEPARATOR);
+ public void loadSyntaxHighlightingData(String syntaxHighlightingRules) {
+ String[] rules = syntaxHighlightingRules.split(ENTITY_SEPARATOR);
for (int i = 0; i < rules.length; i++) {
String[] ruleFields = rules[i].split(FIELD_SEPARATOR);
- context.lowerBoundsDefinitions.put(Integer.parseInt(ruleFields[0]), ruleFields[2]);
- context.upperBoundsDefinitions.add(Integer.parseInt(ruleFields[1]));
+ lowerBoundsDefinitions.put(Integer.parseInt(ruleFields[0]), ruleFields[2]);
+ upperBoundsDefinitions.add(Integer.parseInt(ruleFields[1]));
}
- return context;
}
public Multimap<Integer, String> getLowerBoundsDefinitions() {
@@ -59,4 +69,13 @@ public class HighlightingContext {
public List<Integer> getUpperBoundsDefinitions() {
return upperBoundsDefinitions;
}
+
+ private void loadSymbolOccurrences(int declarationStartOffset, int symbolLength, String[] symbolOccurrences) {
+ for (int i = 0; i < symbolOccurrences.length; i++) {
+ int occurrenceStartOffset = Integer.parseInt(symbolOccurrences[i]);
+ int occurrenceEndOffset = occurrenceStartOffset + symbolLength;
+ lowerBoundsDefinitions.put(occurrenceStartOffset, SYMBOL_PREFIX + declarationStartOffset);
+ upperBoundsDefinitions.add(occurrenceEndOffset);
+ }
+ }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/HtmlTextWrapper.java b/sonar-core/src/main/java/org/sonar/core/source/HtmlTextDecorator.java
index 27be01d67e6..af6539bc991 100644
--- a/sonar-core/src/main/java/org/sonar/core/source/HtmlTextWrapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/source/HtmlTextDecorator.java
@@ -36,7 +36,7 @@ import static org.sonar.core.source.CharactersReader.END_OF_STREAM;
/**
* @since 3.6
*/
-public class HtmlTextWrapper {
+public class HtmlTextDecorator {
public static final char CR_END_OF_LINE = '\r';
public static final char LF_END_OF_LINE = '\n';
@@ -47,7 +47,7 @@ public class HtmlTextWrapper {
public static final String ENCODED_HTML_CLOSING = "&gt;";
public static final String ENCODED_AMPERSAND = "&amp;";
- public List<String> wrapTextWithHtml(String text, HighlightingContext context) {
+ public List<String> decorateTextWithHtml(String text, DecorationDataHolder context) {
StringBuilder currentHtmlLine = new StringBuilder();
List<String> decoratedHtmlLines = Lists.newArrayList();
@@ -92,7 +92,7 @@ public class HtmlTextWrapper {
} catch (IOException exception) {
String errorMsg = "An exception occurred while highlighting the syntax of one of the project's files";
- LoggerFactory.getLogger(HtmlTextWrapper.class).error(errorMsg);
+ LoggerFactory.getLogger(HtmlTextDecorator.class).error(errorMsg);
throw new IllegalStateException(errorMsg, exception);
} finally {
Closeables.closeQuietly(stringBuffer);
@@ -119,11 +119,11 @@ public class HtmlTextWrapper {
return charsReader.getCurrentValue() != CR_END_OF_LINE && charsReader.getCurrentValue() != LF_END_OF_LINE;
}
- private int getNumberOfTagsToClose(int currentIndex, HighlightingContext context) {
+ private int getNumberOfTagsToClose(int currentIndex, DecorationDataHolder context) {
return Collections.frequency(context.getUpperBoundsDefinitions(), currentIndex);
}
- private Collection<String> getTagsToOpen(int currentIndex, HighlightingContext context) {
+ private Collection<String> getTagsToOpen(int currentIndex, DecorationDataHolder context) {
return context.getLowerBoundsDefinitions().get(currentIndex);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/SyntaxHighlighter.java b/sonar-core/src/main/java/org/sonar/core/source/SourceDecorator.java
index c9beafd8a94..b70dbea67c4 100644
--- a/sonar-core/src/main/java/org/sonar/core/source/SyntaxHighlighter.java
+++ b/sonar-core/src/main/java/org/sonar/core/source/SourceDecorator.java
@@ -22,6 +22,7 @@ package org.sonar.core.source;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.source.jdbc.SnapshotDataDao;
+import org.sonar.core.source.jdbc.SnapshotDataDto;
import org.sonar.core.source.jdbc.SnapshotSourceDao;
import java.util.Collection;
@@ -29,25 +30,33 @@ import java.util.Collection;
/**
* @since 3.6
*/
-public class SyntaxHighlighter {
+public class SourceDecorator {
private final SnapshotSourceDao snapshotSourceDao;
private final SnapshotDataDao snapshotDataDao;
- public SyntaxHighlighter(MyBatis myBatis) {
+ public SourceDecorator(MyBatis myBatis) {
snapshotSourceDao = new SnapshotSourceDao(myBatis);
snapshotDataDao = new SnapshotDataDao(myBatis);
}
- public Collection<String> getHighlightedSourceAsHtml(long snapshotId) {
+ public Collection<String> getDecoratedSourceAsHtml(long snapshotId) {
String snapshotSource = snapshotSourceDao.selectSnapshotSource(snapshotId);
- String highlightingRules = snapshotDataDao.selectSnapshotData(snapshotId);
-
- if(snapshotSource != null && highlightingRules != null) {
- HighlightingContext highlightingContext = HighlightingContext.buildFrom(highlightingRules);
- HtmlTextWrapper textWrapper = new HtmlTextWrapper();
- return textWrapper.wrapTextWithHtml(snapshotSource, highlightingContext);
+ Collection<SnapshotDataDto> snapshotDataEntries = snapshotDataDao.selectSnapshotData(snapshotId);
+
+ 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());
+ }
+ }
+
+ HtmlTextDecorator textDecorator = new HtmlTextDecorator();
+ return textDecorator.decorateTextWithHtml(snapshotSource, decorationDataHolder);
}
return null;
}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataDao.java b/sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataDao.java
index 0961b1d95e4..d2384384008 100644
--- a/sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataDao.java
@@ -25,6 +25,8 @@ import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
import org.sonar.core.persistence.MyBatis;
+import java.util.Collection;
+
/**
* @since 3.6
*/
@@ -36,7 +38,7 @@ public class SnapshotDataDao implements BatchComponent, ServerComponent {
this.mybatis = mybatis;
}
- public String selectSnapshotData(long snapshotId) {
+ public Collection<SnapshotDataDto> selectSnapshotData(long snapshotId) {
SqlSession session = mybatis.openSession();
diff --git a/sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataDto.java b/sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataDto.java
index 847ac49e1b5..398443ea7c5 100644
--- a/sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataDto.java
@@ -25,6 +25,9 @@ package org.sonar.core.source.jdbc;
*/
public class SnapshotDataDto {
+ public static final String HIGHLIGHT_SYNTAX = "highlight_syntax";
+ public static final String SYMBOL = "symbol";
+
private long id;
private long snapshotId;
private long resourceId;
@@ -70,4 +73,12 @@ public class SnapshotDataDto {
public void setDataType(String dataType) {
this.dataType = dataType;
}
+
+ public boolean isSyntaxHighlightingData() {
+ return HIGHLIGHT_SYNTAX.equals(dataType);
+ }
+
+ public boolean isSymbolData() {
+ return SYMBOL.equals(dataType);
+ }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataMapper.java b/sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataMapper.java
index 8ca60f0a17f..0ebd4e140af 100644
--- a/sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataMapper.java
@@ -22,6 +22,8 @@ package org.sonar.core.source.jdbc;
import org.apache.ibatis.annotations.Param;
+import java.util.Collection;
+
/**
* @since 3.6
*/
@@ -29,5 +31,5 @@ public interface SnapshotDataMapper {
void insert(SnapshotDataDto snapshotData);
- String selectSnapshotData(@Param("sid") long snapshotId);
+ Collection<SnapshotDataDto> selectSnapshotData(@Param("sid") long snapshotId);
}
diff --git a/sonar-core/src/main/resources/org/sonar/core/source/jdbc/SnapshotDataMapper.xml b/sonar-core/src/main/resources/org/sonar/core/source/jdbc/SnapshotDataMapper.xml
index 884cf5f5c64..654e79e13d5 100644
--- a/sonar-core/src/main/resources/org/sonar/core/source/jdbc/SnapshotDataMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/source/jdbc/SnapshotDataMapper.xml
@@ -3,8 +3,11 @@
<mapper namespace="org.sonar.core.source.jdbc.SnapshotDataMapper">
- <select id="selectSnapshotData" parameterType="map" resultType="string">
- SELECT data
+ <select id="selectSnapshotData" parameterType="long" resultType="SnapshotData">
+ SELECT
+ snapshot_id as "snapshotId",
+ data,
+ data_type as "dataType"
FROM snapshot_data
WHERE snapshot_id = #{sid}
</select>
diff --git a/sonar-core/src/test/java/org/sonar/core/source/HighlightingContextTest.java b/sonar-core/src/test/java/org/sonar/core/source/DecorationDataHolderTest.java
index f65192bcbba..ec2b7d8da46 100644
--- a/sonar-core/src/test/java/org/sonar/core/source/HighlightingContextTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/source/DecorationDataHolderTest.java
@@ -28,33 +28,40 @@ import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
-public class HighlightingContextTest {
+public class DecorationDataHolderTest {
- private static final String SAMPLE_RULES = "0,8,k;0,52,cppd;54,67,a;69,75,k;106,130,cppd;114,130,k;";
- private HighlightingContext highlightingContext;
+ private static final String SAMPLE_SYNTAX_HIGHLIGHTING_RULES = "0,8,k;0,52,cppd;54,67,a;69,75,k;106,130,cppd;114,130,k;";
+ private static final String SAMPLE_SYMBOLS_REFERENCES = "80,85,80,90,140;";
+
+ private DecorationDataHolder decorationDataHolder;
@Before
public void setUpHighlightingContext() {
- highlightingContext = HighlightingContext.buildFrom(SAMPLE_RULES);
+ decorationDataHolder = new DecorationDataHolder();
+ decorationDataHolder.loadSyntaxHighlightingData(SAMPLE_SYNTAX_HIGHLIGHTING_RULES);
+ decorationDataHolder.loadSymbolReferences(SAMPLE_SYMBOLS_REFERENCES);
}
@Test
public void should_extract_lower_bounds_from_serialized_rules() throws Exception {
- Multimap<Integer, String> lowerBoundsDefinitions = highlightingContext.getLowerBoundsDefinitions();
+ Multimap<Integer, String> lowerBoundsDefinitions = decorationDataHolder.getLowerBoundsDefinitions();
- assertThat(lowerBoundsDefinitions.containsEntry(0, "k"));
- assertThat(lowerBoundsDefinitions.containsEntry(0, "cppd"));
- assertThat(lowerBoundsDefinitions.containsEntry(54, "a"));
- assertThat(lowerBoundsDefinitions.containsEntry(69, "k"));
- assertThat(lowerBoundsDefinitions.containsEntry(106, "cppd"));
- assertThat(lowerBoundsDefinitions.containsEntry(114, "k"));
+ assertThat(lowerBoundsDefinitions.containsEntry(0, "k"));
+ assertThat(lowerBoundsDefinitions.containsEntry(0, "cppd"));
+ assertThat(lowerBoundsDefinitions.containsEntry(54, "a"));
+ assertThat(lowerBoundsDefinitions.containsEntry(69, "k"));
+ assertThat(lowerBoundsDefinitions.containsEntry(80, "symbol.80"));
+ assertThat(lowerBoundsDefinitions.containsEntry(90, "symbol.90"));
+ assertThat(lowerBoundsDefinitions.containsEntry(106, "cppd"));
+ assertThat(lowerBoundsDefinitions.containsEntry(114, "k"));
+ assertThat(lowerBoundsDefinitions.containsEntry(140, "symbol.140"));
}
@Test
public void should_extract_upper_bounds_from_serialized_rules() throws Exception {
- List<Integer> upperBoundsDefinition = highlightingContext.getUpperBoundsDefinitions();
- assertThat(upperBoundsDefinition).containsExactly(8, 52, 67, 75, 130, 130);
+ List<Integer> upperBoundsDefinition = decorationDataHolder.getUpperBoundsDefinitions();
+ assertThat(upperBoundsDefinition).containsExactly(8, 52, 67, 75, 130, 130, 85, 95, 145);
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/source/HtmlTextWrapperTest.java b/sonar-core/src/test/java/org/sonar/core/source/HtmlTextDecoratorTest.java
index 140132cf835..3ee597619ac 100644
--- a/sonar-core/src/test/java/org/sonar/core/source/HtmlTextWrapperTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/source/HtmlTextDecoratorTest.java
@@ -25,20 +25,21 @@ import org.junit.Test;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
-import static org.sonar.core.source.HtmlTextWrapper.CR_END_OF_LINE;
-import static org.sonar.core.source.HtmlTextWrapper.LF_END_OF_LINE;
+import static org.sonar.core.source.HtmlTextDecorator.CR_END_OF_LINE;
+import static org.sonar.core.source.HtmlTextDecorator.LF_END_OF_LINE;
-public class HtmlTextWrapperTest {
+public class HtmlTextDecoratorTest {
@Test
public void should_decorate_simple_character_range() throws Exception {
String packageDeclaration = "package org.sonar.core.source;";
- HighlightingContext context = HighlightingContext.buildFrom("0,7,k;");
+ DecorationDataHolder decorationData = new DecorationDataHolder();
+ decorationData.loadSyntaxHighlightingData("0,7,k;");
- HtmlTextWrapper htmlTextWrapper = new HtmlTextWrapper();
- List<String> htmlOutput = htmlTextWrapper.wrapTextWithHtml(packageDeclaration, context);
+ HtmlTextDecorator htmlTextDecorator = new HtmlTextDecorator();
+ List<String> htmlOutput = htmlTextDecorator.decorateTextWithHtml(packageDeclaration, decorationData);
assertThat(htmlOutput).containsOnly("<span class=\"k\">package</span> org.sonar.core.source;");
}
@@ -54,10 +55,11 @@ public class HtmlTextWrapperTest {
+ secondCommentLine + LF_END_OF_LINE
+ thirdCommentLine + LF_END_OF_LINE;
- HighlightingContext context = HighlightingContext.buildFrom("0,14,cppd;");
+ DecorationDataHolder decorationData = new DecorationDataHolder();
+ decorationData.loadSyntaxHighlightingData("0,14,cppd;");
- HtmlTextWrapper htmlTextWrapper = new HtmlTextWrapper();
- List<String> htmlOutput = htmlTextWrapper.wrapTextWithHtml(blockComment, context);
+ HtmlTextDecorator htmlTextDecorator = new HtmlTextDecorator();
+ List<String> htmlOutput = htmlTextDecorator.decorateTextWithHtml(blockComment, decorationData);
assertThat(htmlOutput).containsExactly(
"<span class=\"cppd\">" + firstCommentLine + "</span>",
@@ -71,10 +73,11 @@ public class HtmlTextWrapperTest {
String classDeclaration = "public class MyClass implements MyInterface {\n";
- HighlightingContext context = HighlightingContext.buildFrom("0,6,k;7,12,k;21,31,k;");
+ DecorationDataHolder decorationData = new DecorationDataHolder();
+ decorationData.loadSyntaxHighlightingData("0,6,k;7,12,k;21,31,k;");
- HtmlTextWrapper htmlTextWrapper = new HtmlTextWrapper();
- List<String> htmlOutput = htmlTextWrapper.wrapTextWithHtml(classDeclaration, context);
+ HtmlTextDecorator htmlTextDecorator = new HtmlTextDecorator();
+ List<String> htmlOutput = htmlTextDecorator.decorateTextWithHtml(classDeclaration, decorationData);
assertThat(htmlOutput).containsOnly(
"<span class=\"k\">public</span> " +
@@ -94,10 +97,11 @@ public class HtmlTextWrapperTest {
" * @throws IllegalArgumentException if no formula is associated to the metric" + LF_END_OF_LINE +
" */" + LF_END_OF_LINE;
- HighlightingContext context = HighlightingContext.buildFrom("0,184,cppd;47,53,k;");
+ DecorationDataHolder decorationData = new DecorationDataHolder();
+ decorationData.loadSyntaxHighlightingData("0,184,cppd;47,53,k;");
- HtmlTextWrapper htmlTextWrapper = new HtmlTextWrapper();
- List<String> htmlOutput = htmlTextWrapper.wrapTextWithHtml(javaDocSample, context);
+ HtmlTextDecorator htmlTextDecorator = new HtmlTextDecorator();
+ List<String> htmlOutput = htmlTextDecorator.decorateTextWithHtml(javaDocSample, decorationData);
assertThat(htmlOutput).containsExactly(
"<span class=\"cppd\">/**</span>",
@@ -122,10 +126,11 @@ public class HtmlTextWrapperTest {
" return metric;" + CR_END_OF_LINE + LF_END_OF_LINE +
"}" + CR_END_OF_LINE + LF_END_OF_LINE;
- HighlightingContext context = HighlightingContext.buildFrom("0,52,cppd;54,67,a;69,75,k;106,112,k;");
+ DecorationDataHolder decorationData = new DecorationDataHolder();
+ decorationData.loadSyntaxHighlightingData("0,52,cppd;54,67,a;69,75,k;106,112,k;");
- HtmlTextWrapper htmlTextWrapper = new HtmlTextWrapper();
- List<String> htmlOutput = htmlTextWrapper.wrapTextWithHtml(crlfCodeSample, context);
+ HtmlTextDecorator htmlTextDecorator = new HtmlTextDecorator();
+ List<String> htmlOutput = htmlTextDecorator.decorateTextWithHtml(crlfCodeSample, decorationData);
assertThat(htmlOutput).containsExactly(
"<span class=\"cppd\">/**</span>",
@@ -149,10 +154,11 @@ public class HtmlTextWrapperTest {
"public class HelloWorld {" + LF_END_OF_LINE +
"}";
- HighlightingContext context = HighlightingContext.buildFrom("0,16,cppd;18,25,k;25,31,k;");
+ DecorationDataHolder decorationData = new DecorationDataHolder();
+ decorationData.loadSyntaxHighlightingData("0,16,cppd;18,25,k;25,31,k;");
- HtmlTextWrapper htmlTextWrapper = new HtmlTextWrapper();
- List<String> htmlOutput = htmlTextWrapper.wrapTextWithHtml(classDeclarationSample, context);
+ HtmlTextDecorator htmlTextDecorator = new HtmlTextDecorator();
+ List<String> htmlOutput = htmlTextDecorator.decorateTextWithHtml(classDeclarationSample, decorationData);
assertThat(htmlOutput).containsExactly(
"<span class=\"cppd\">/*</span>",
@@ -181,10 +187,11 @@ public class HtmlTextWrapperTest {
" */\n";
- HighlightingContext context = HighlightingContext.buildFrom("0,453,cppd;");
+ DecorationDataHolder decorationData = new DecorationDataHolder();
+ decorationData.loadSyntaxHighlightingData("0,453,cppd;");
- HtmlTextWrapper htmlTextWrapper = new HtmlTextWrapper();
- List<String> htmlOutput = htmlTextWrapper.wrapTextWithHtml(javadocWithHtml, context);
+ HtmlTextDecorator htmlTextDecorator = new HtmlTextDecorator();
+ List<String> htmlOutput = htmlTextDecorator.decorateTextWithHtml(javadocWithHtml, decorationData);
assertThat(htmlOutput).containsExactly(
"<span class=\"cppd\">/**</span>",
@@ -213,10 +220,11 @@ public class HtmlTextWrapperTest {
" * @since 2.13\n" +
" */\n";
- HighlightingContext context = HighlightingContext.buildFrom("0,220,cppd;");
+ DecorationDataHolder decorationData = new DecorationDataHolder();
+ decorationData.loadSyntaxHighlightingData("0,220,cppd;");
- HtmlTextWrapper htmlTextWrapper = new HtmlTextWrapper();
- List<String> htmlOutput = htmlTextWrapper.wrapTextWithHtml(javadocWithAmpersandChar, context);
+ HtmlTextDecorator htmlTextDecorator = new HtmlTextDecorator();
+ List<String> htmlOutput = htmlTextDecorator.decorateTextWithHtml(javadocWithAmpersandChar, decorationData);
assertThat(htmlOutput).containsExactly(
"<span class=\"cppd\">/**</span>",
@@ -241,10 +249,11 @@ public class HtmlTextWrapperTest {
" return metric;" + CR_END_OF_LINE +
"}" + CR_END_OF_LINE;
- HighlightingContext context = HighlightingContext.buildFrom("0,50,cppd;51,64,a;65,71,k;101,107,k;");
+ DecorationDataHolder decorationData = new DecorationDataHolder();
+ decorationData.loadSyntaxHighlightingData("0,50,cppd;51,64,a;65,71,k;101,107,k;");
- HtmlTextWrapper htmlTextWrapper = new HtmlTextWrapper();
- List<String> htmlOutput = htmlTextWrapper.wrapTextWithHtml(crCodeSample, context);
+ HtmlTextDecorator htmlTextDecorator = new HtmlTextDecorator();
+ List<String> htmlOutput = htmlTextDecorator.decorateTextWithHtml(crCodeSample, decorationData);
assertThat(htmlOutput).containsExactly(
"<span class=\"cppd\">/**</span>",
diff --git a/sonar-core/src/test/java/org/sonar/core/source/SyntaxHighlighterTest.java b/sonar-core/src/test/java/org/sonar/core/source/SourceDecoratorTest.java
index 0b6fe434d40..34cc50d8442 100644
--- a/sonar-core/src/test/java/org/sonar/core/source/SyntaxHighlighterTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/source/SourceDecoratorTest.java
@@ -28,7 +28,7 @@ import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
-public class SyntaxHighlighterTest extends AbstractDaoTestCase {
+public class SourceDecoratorTest extends AbstractDaoTestCase {
@Before
public void setUpDatasets() {
@@ -38,9 +38,9 @@ public class SyntaxHighlighterTest extends AbstractDaoTestCase {
@Test
public void should_highlight_source_with_html() throws Exception {
- SyntaxHighlighter highlighter = new SyntaxHighlighter(getMyBatis());
+ SourceDecorator highlighter = new SourceDecorator(getMyBatis());
- List<String> highlightedSource = (List<String>)highlighter.getHighlightedSourceAsHtml(11L);
+ List<String> highlightedSource = (List<String>)highlighter.getDecoratedSourceAsHtml(11L);
assertThat(highlightedSource).containsExactly(
"<span class=\"cppd\">/*</span>",
diff --git a/sonar-core/src/test/java/org/sonar/core/source/jdbc/SnapshotDataDaoTest.java b/sonar-core/src/test/java/org/sonar/core/source/jdbc/SnapshotDataDaoTest.java
index 1ced69e83eb..0c6eee023c1 100644
--- a/sonar-core/src/test/java/org/sonar/core/source/jdbc/SnapshotDataDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/source/jdbc/SnapshotDataDaoTest.java
@@ -24,6 +24,8 @@ import org.junit.Before;
import org.junit.Test;
import org.sonar.core.persistence.AbstractDaoTestCase;
+import java.util.Collection;
+
import static org.fest.assertions.Assertions.assertThat;
public class SnapshotDataDaoTest extends AbstractDaoTestCase {
@@ -39,9 +41,11 @@ public class SnapshotDataDaoTest extends AbstractDaoTestCase {
@Test
public void should_retrieve_snapshot_data_by_snapshot_id() throws Exception {
- String data = dao.selectSnapshotData(10L);
+ Collection<SnapshotDataDto> data = dao.selectSnapshotData(10L);
- assertThat(data).isEqualTo("0,10,k");
+ assertThat(data).onProperty("snapshotId").containsOnly(10L, 10L);
+ assertThat(data).onProperty("dataType").containsOnly("highlight_syntax", "symbol");
+ assertThat(data).onProperty("data").containsOnly("0,10,k;", "20,25,20,35,45;");
}
@Test
@@ -58,8 +62,10 @@ public class SnapshotDataDaoTest extends AbstractDaoTestCase {
dao.insert(dto);
- String serializedData = dao.selectSnapshotData(11L);
+ Collection<SnapshotDataDto> serializedData = dao.selectSnapshotData(11L);
- assertThat(serializedData).isEqualTo(data);
+ assertThat(serializedData).onProperty("snapshotId").containsOnly(11L);
+ assertThat(serializedData).onProperty("dataType").containsOnly(dataType);
+ assertThat(serializedData).onProperty("data").containsOnly(data);
}
}
diff --git a/sonar-core/src/test/resources/org/sonar/core/source/SyntaxHighlighterTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/source/SourceDecoratorTest/shared.xml
index 086fd88f9e4..086fd88f9e4 100644
--- a/sonar-core/src/test/resources/org/sonar/core/source/SyntaxHighlighterTest/shared.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/source/SourceDecoratorTest/shared.xml
diff --git a/sonar-core/src/test/resources/org/sonar/core/source/jdbc/SnapshotDataDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/source/jdbc/SnapshotDataDaoTest/shared.xml
index 601565dba2c..4c56793e9eb 100644
--- a/sonar-core/src/test/resources/org/sonar/core/source/jdbc/SnapshotDataDaoTest/shared.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/source/jdbc/SnapshotDataDaoTest/shared.xml
@@ -5,6 +5,7 @@
<snapshots id="10" project_id="1" islast="[false]" />
<snapshots id="11" project_id="1" islast="[true]" />
- <snapshot_data id="101" resource_id="1" snapshot_id="10" data="0,10,k" data_type="highlight_syntax" />
+ <snapshot_data id="101" resource_id="1" snapshot_id="10" data="0,10,k;" data_type="highlight_syntax" />
+ <snapshot_data id="102" resource_id="1" snapshot_id="10" data="20,25,20,35,45;" data_type="symbol" />
</dataset> \ No newline at end of file
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index 8928ec685a8..727c65eeb49 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -57,7 +57,7 @@ import org.sonar.core.persistence.SemaphoresImpl;
import org.sonar.core.qualitymodel.DefaultModelFinder;
import org.sonar.core.resource.DefaultResourcePermissions;
import org.sonar.core.rule.DefaultRuleFinder;
-import org.sonar.core.source.SyntaxHighlighter;
+import org.sonar.core.source.SourceDecorator;
import org.sonar.core.test.TestPlanPerspectiveLoader;
import org.sonar.core.test.TestablePerspectiveLoader;
import org.sonar.core.timemachine.Periods;
@@ -274,7 +274,7 @@ public final class Platform {
servicesContainer.addSingleton(TestablePerspectiveLoader.class);
servicesContainer.addSingleton(TestPlanPerspectiveLoader.class);
servicesContainer.addSingleton(SnapshotPerspectives.class);
- servicesContainer.addSingleton(SyntaxHighlighter.class);
+ servicesContainer.addSingleton(SourceDecorator.class);
ServerExtensionInstaller extensionRegistrar = servicesContainer.getComponentByType(ServerExtensionInstaller.class);
extensionRegistrar.registerExtensions(servicesContainer);
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
index c2f3c667490..934320ab8bf 100644
--- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
+++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
@@ -56,7 +56,7 @@ import org.sonar.core.persistence.DryRunDatabaseFactory;
import org.sonar.core.purge.PurgeDao;
import org.sonar.core.resource.ResourceIndexerDao;
import org.sonar.core.resource.ResourceKeyUpdaterDao;
-import org.sonar.core.source.SyntaxHighlighter;
+import org.sonar.core.source.SourceDecorator;
import org.sonar.core.timemachine.Periods;
import org.sonar.core.workflow.WorkflowEngine;
import org.sonar.markdown.Markdown;
@@ -561,7 +561,7 @@ public final class JRubyFacade {
}
public Collection<String> getHighlightedSourceLines(long snapshotId) {
- return get(SyntaxHighlighter.class).getHighlightedSourceAsHtml(snapshotId);
+ return get(SourceDecorator.class).getDecoratedSourceAsHtml(snapshotId);
}
// public IssueFilter getIssueFilter() {