aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-10-21 12:24:57 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-10-21 18:45:43 +0200
commit1fabcdaf19701087c36d5e1dd0b06e1575cfb10b (patch)
treed409a7f323b7493ebed50793d7f1954ba090e99a /server
parentc69b3c6c5c3cfe819dd2f3eb4b3c23254647c2f8 (diff)
downloadsonarqube-1fabcdaf19701087c36d5e1dd0b06e1575cfb10b.tar.gz
sonarqube-1fabcdaf19701087c36d5e1dd0b06e1575cfb10b.zip
SONAR-6318 Display component key in warning generated when symbols/highlighting are inconsistent
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/source/HighlightingLineReader.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/source/SymbolsLineReader.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/source/HighlightingLineReaderTest.java17
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/source/SymbolsLineReaderTest.java17
5 files changed, 47 insertions, 9 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/source/HighlightingLineReader.java b/server/sonar-server/src/main/java/org/sonar/server/computation/source/HighlightingLineReader.java
index 60dc74a1cc1..c7dc4504191 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/source/HighlightingLineReader.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/source/HighlightingLineReader.java
@@ -30,9 +30,11 @@ import org.sonar.api.utils.log.Loggers;
import org.sonar.batch.protocol.Constants;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.db.protobuf.DbFileSources;
+import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.source.RangeOffsetConverter.RangeOffsetConverterException;
import static com.google.common.collect.Lists.newArrayList;
+import static java.lang.String.format;
import static org.sonar.server.computation.source.RangeOffsetConverter.OFFSET_SEPARATOR;
import static org.sonar.server.computation.source.RangeOffsetConverter.SYMBOLS_SEPARATOR;
@@ -54,13 +56,15 @@ public class HighlightingLineReader implements LineReader {
.put(Constants.HighlightingType.PREPROCESS_DIRECTIVE, "p")
.build();
+ private final Component file;
private final Iterator<BatchReport.SyntaxHighlighting> lineHighlightingIterator;
private final RangeOffsetConverter rangeOffsetConverter;
private final List<BatchReport.SyntaxHighlighting> highlightingList;
private BatchReport.SyntaxHighlighting currentItem;
- public HighlightingLineReader(Iterator<BatchReport.SyntaxHighlighting> lineHighlightingIterator, RangeOffsetConverter rangeOffsetConverter) {
+ public HighlightingLineReader(Component file, Iterator<BatchReport.SyntaxHighlighting> lineHighlightingIterator, RangeOffsetConverter rangeOffsetConverter) {
+ this.file = file;
this.lineHighlightingIterator = lineHighlightingIterator;
this.rangeOffsetConverter = rangeOffsetConverter;
this.highlightingList = newArrayList();
@@ -75,7 +79,7 @@ public class HighlightingLineReader implements LineReader {
processHighlightings(lineBuilder);
} catch (RangeOffsetConverterException e) {
isHighlightingValid = false;
- LOG.warn("Inconsistency detected in Highlighting data. Highlighting will be ignored", e);
+ LOG.warn(format("Inconsistency detected in Highlighting data. Highlighting will be ignored for file '%s'", file.getKey()), e);
}
}
@@ -120,7 +124,7 @@ public class HighlightingLineReader implements LineReader {
if (cssClass != null) {
return cssClass;
} else {
- throw new IllegalArgumentException(String.format("Unknown type %s ", type.toString()));
+ throw new IllegalArgumentException(format("Unknown type %s ", type.toString()));
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/source/SymbolsLineReader.java b/server/sonar-server/src/main/java/org/sonar/server/computation/source/SymbolsLineReader.java
index 78ae951f56e..84eb0ca85c6 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/source/SymbolsLineReader.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/source/SymbolsLineReader.java
@@ -35,7 +35,9 @@ import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.db.protobuf.DbFileSources;
+import org.sonar.server.computation.component.Component;
+import static java.lang.String.format;
import static org.sonar.server.computation.source.RangeOffsetConverter.OFFSET_SEPARATOR;
import static org.sonar.server.computation.source.RangeOffsetConverter.SYMBOLS_SEPARATOR;
@@ -43,13 +45,15 @@ public class SymbolsLineReader implements LineReader {
private static final Logger LOG = Loggers.get(HighlightingLineReader.class);
+ private final Component file;
private final RangeOffsetConverter rangeOffsetConverter;
private final List<BatchReport.Symbol> symbols;
private final Map<BatchReport.Symbol, Integer> idsBySymbol;
private boolean areSymbolsValid = true;
- public SymbolsLineReader(Iterator<BatchReport.Symbol> symbols, RangeOffsetConverter rangeOffsetConverter) {
+ public SymbolsLineReader(Component file, Iterator<BatchReport.Symbol> symbols, RangeOffsetConverter rangeOffsetConverter) {
+ this.file = file;
this.rangeOffsetConverter = rangeOffsetConverter;
this.symbols = Lists.newArrayList(symbols);
// Sort symbols to have deterministic results and avoid false variation that would lead to an unnecessary update of the source files
@@ -68,7 +72,7 @@ public class SymbolsLineReader implements LineReader {
processSymbols(lineBuilder);
} catch (RangeOffsetConverter.RangeOffsetConverterException e) {
areSymbolsValid = false;
- LOG.warn("Inconsistency detected in Symbols data. Symbols will be ignored", e);
+ LOG.warn(format("Inconsistency detected in Symbols data. Symbols will be ignored for file '%s'", file.getKey()), e);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
index 93865e41336..bd3a57c1338 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
@@ -219,11 +219,11 @@ public class PersistFileSourcesStep implements ComputationStep {
RangeOffsetConverter rangeOffsetConverter = new RangeOffsetConverter();
CloseableIterator<BatchReport.SyntaxHighlighting> highlightingIt = reportReader.readComponentSyntaxHighlighting(componentRef);
closeables.add(highlightingIt);
- readers.add(new HighlightingLineReader(highlightingIt, rangeOffsetConverter));
+ readers.add(new HighlightingLineReader(component, highlightingIt, rangeOffsetConverter));
CloseableIterator<BatchReport.Symbol> symbolsIt = reportReader.readComponentSymbols(componentRef);
closeables.add(symbolsIt);
- readers.add(new SymbolsLineReader(symbolsIt, rangeOffsetConverter));
+ readers.add(new SymbolsLineReader(component, symbolsIt, rangeOffsetConverter));
CloseableIterator<BatchReport.Duplication> duplicationsIt = reportReader.readComponentDuplications(componentRef);
closeables.add(duplicationsIt);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/source/HighlightingLineReaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/source/HighlightingLineReaderTest.java
index 2f5485f0a8d..6ffd8833c62 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/source/HighlightingLineReaderTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/source/HighlightingLineReaderTest.java
@@ -32,6 +32,7 @@ import org.sonar.batch.protocol.Constants;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReport.TextRange;
import org.sonar.db.protobuf.DbFileSources;
+import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.source.RangeOffsetConverter.RangeOffsetConverterException;
import static com.google.common.collect.ImmutableMap.of;
@@ -45,12 +46,15 @@ import static org.sonar.batch.protocol.Constants.HighlightingType.COMMENT;
import static org.sonar.batch.protocol.Constants.HighlightingType.CONSTANT;
import static org.sonar.batch.protocol.Constants.HighlightingType.HIGHLIGHTING_STRING;
import static org.sonar.db.protobuf.DbFileSources.Data.newBuilder;
+import static org.sonar.server.computation.component.ReportComponent.builder;
public class HighlightingLineReaderTest {
@Rule
public LogTester logTester = new LogTester();
+ static final Component FILE = builder(Component.Type.FILE, 1).setUuid("FILE_UUID").setKey("FILE_KEY").build();
+
static final int DEFAULT_LINE_LENGTH = 5;
static final int LINE_1 = 1;
@@ -227,6 +231,17 @@ public class HighlightingLineReaderTest {
assertThat(logTester.logs(WARN)).isNotEmpty();
}
+ @Test
+ public void display_file_key_in_warning_when_range_offset_converter_throw_RangeOffsetConverterException() {
+ TextRange textRange1 = newTextRange(LINE_1, LINE_1);
+ doThrow(RangeOffsetConverterException.class).when(rangeOffsetConverter).offsetToString(textRange1, LINE_1, DEFAULT_LINE_LENGTH);
+ HighlightingLineReader highlightingLineReader = newReader(of(textRange1, ANNOTATION));
+
+ highlightingLineReader.read(line1);
+
+ assertThat(logTester.logs(WARN)).containsOnly("Inconsistency detected in Highlighting data. Highlighting will be ignored for file 'FILE_KEY'");
+ }
+
private HighlightingLineReader newReader(Map<TextRange, Constants.HighlightingType> textRangeByType) {
List<BatchReport.SyntaxHighlighting> syntaxHighlightingList = new ArrayList<>();
for (Map.Entry<TextRange, Constants.HighlightingType> entry : textRangeByType.entrySet()) {
@@ -235,7 +250,7 @@ public class HighlightingLineReaderTest {
.setType(entry.getValue())
.build());
}
- return new HighlightingLineReader(syntaxHighlightingList.iterator(), rangeOffsetConverter);
+ return new HighlightingLineReader(FILE, syntaxHighlightingList.iterator(), rangeOffsetConverter);
}
private static TextRange newTextRange(int startLine, int enLine) {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/source/SymbolsLineReaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/source/SymbolsLineReaderTest.java
index d98c2ed6b21..8a589ce5e92 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/source/SymbolsLineReaderTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/source/SymbolsLineReaderTest.java
@@ -27,18 +27,22 @@ import org.sonar.api.utils.log.LogTester;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReport.TextRange;
import org.sonar.db.protobuf.DbFileSources;
+import org.sonar.server.computation.component.Component;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.api.utils.log.LoggerLevel.WARN;
+import static org.sonar.server.computation.component.ReportComponent.builder;
public class SymbolsLineReaderTest {
@Rule
public LogTester logTester = new LogTester();
+ static final Component FILE = builder(Component.Type.FILE, 1).setUuid("FILE_UUID").setKey("FILE_KEY").build();
+
static final int DEFAULT_LINE_LENGTH = 5;
static final int LINE_1 = 1;
@@ -285,6 +289,17 @@ public class SymbolsLineReaderTest {
assertThat(logTester.logs(WARN)).isNotEmpty();
}
+ @Test
+ public void display_file_key_in_warning_when_range_offset_converter_throw_RangeOffsetConverterException() {
+ TextRange declaration = newTextRange(LINE_1, LINE_1, OFFSET_1, OFFSET_3);
+ doThrow(RangeOffsetConverter.RangeOffsetConverterException.class).when(rangeOffsetConverter).offsetToString(declaration, LINE_1, DEFAULT_LINE_LENGTH);
+ SymbolsLineReader symbolsLineReader = newReader(newSymbol(declaration, newSingleLineTextRangeWithExpectedLabel(LINE_2, OFFSET_1, OFFSET_3, RANGE_LABEL_2)));
+
+ symbolsLineReader.read(line1);
+
+ assertThat(logTester.logs(WARN)).containsOnly("Inconsistency detected in Symbols data. Symbols will be ignored for file 'FILE_KEY'");
+ }
+
private BatchReport.Symbol newSymbol(TextRange declaration, TextRange... references) {
BatchReport.Symbol.Builder builder = BatchReport.Symbol.newBuilder()
.setDeclaration(declaration);
@@ -295,7 +310,7 @@ public class SymbolsLineReaderTest {
}
private SymbolsLineReader newReader(BatchReport.Symbol... symbols) {
- return new SymbolsLineReader(Arrays.asList(symbols).iterator(), rangeOffsetConverter);
+ return new SymbolsLineReader(FILE, Arrays.asList(symbols).iterator(), rangeOffsetConverter);
}
private TextRange newSingleLineTextRangeWithExpectedLabel(int line, int startOffset, int endOffset, String rangeLabel) {