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;
.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();
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);
}
}
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()));
}
}
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;
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
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);
}
}
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);
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;
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;
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()) {
.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) {
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;
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);
}
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) {