use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class DefaultSensorStorage method store.
@Override
public void store(DefaultSymbolTable symbolTable) {
ScannerReportWriter writer = reportPublisher.getWriter();
DefaultInputFile inputFile = (DefaultInputFile) symbolTable.inputFile();
inputFile.setPublish(true);
int componentRef = inputFile.batchId();
if (writer.hasComponentData(FileStructure.Domain.SYMBOLS, componentRef)) {
throw new UnsupportedOperationException("Trying to save symbol table twice for the same file is not supported: " + symbolTable.inputFile().absolutePath());
}
final ScannerReport.Symbol.Builder builder = ScannerReport.Symbol.newBuilder();
final ScannerReport.TextRange.Builder rangeBuilder = ScannerReport.TextRange.newBuilder();
writer.writeComponentSymbols(componentRef, symbolTable.getReferencesBySymbol().entrySet().stream().map(input -> {
builder.clear();
rangeBuilder.clear();
TextRange declaration = input.getKey();
builder.setDeclaration(rangeBuilder.setStartLine(declaration.start().line()).setStartOffset(declaration.start().lineOffset()).setEndLine(declaration.end().line()).setEndOffset(declaration.end().lineOffset()).build());
for (TextRange reference : input.getValue()) {
builder.addReference(rangeBuilder.setStartLine(reference.start().line()).setStartOffset(reference.start().lineOffset()).setEndLine(reference.end().line()).setEndOffset(reference.end().lineOffset()).build());
}
return builder.build();
}).collect(Collectors.toList()));
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class DefaultSensorStorage method store.
@Override
public void store(DefaultHighlighting highlighting) {
ScannerReportWriter writer = reportPublisher.getWriter();
DefaultInputFile inputFile = (DefaultInputFile) highlighting.inputFile();
inputFile.setPublish(true);
int componentRef = inputFile.batchId();
if (writer.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, componentRef)) {
throw new UnsupportedOperationException("Trying to save highlighting twice for the same file is not supported: " + inputFile.absolutePath());
}
final ScannerReport.SyntaxHighlightingRule.Builder builder = ScannerReport.SyntaxHighlightingRule.newBuilder();
final ScannerReport.TextRange.Builder rangeBuilder = ScannerReport.TextRange.newBuilder();
writer.writeComponentSyntaxHighlighting(componentRef, highlighting.getSyntaxHighlightingRuleSet().stream().map(input -> {
builder.setRange(rangeBuilder.setStartLine(input.range().start().line()).setStartOffset(input.range().start().lineOffset()).setEndLine(input.range().end().line()).setEndOffset(input.range().end().lineOffset()).build());
builder.setType(ScannerReportUtils.toProtocolType(input.getTextType()));
return builder.build();
}).collect(toList()));
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class InputComponentStore method put.
public InputComponentStore put(InputFile inputFile) {
DefaultInputFile file = (DefaultInputFile) inputFile;
addToLanguageCache(file);
inputFileCache.put(file.moduleKey(), inputFile.relativePath(), inputFile);
globalInputFileCache.put(getProjectRelativePath(file), inputFile);
inputComponents.put(inputFile.key(), inputFile);
filesByNameCache.put(FilenamePredicate.getFilename(inputFile), inputFile);
filesByExtensionCache.put(FileExtensionPredicate.getExtension(inputFile), inputFile);
return this;
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class InputFileBuilder method create.
@CheckForNull
DefaultInputFile create(Path file, InputFile.Type type, Charset defaultEncoding) {
String relativePath = pathResolver.relativePath(moduleBaseDir, file);
if (relativePath == null) {
LOG.warn("File '{}' is ignored. It is not located in module basedir '{}'.", file.toAbsolutePath(), moduleBaseDir);
return null;
}
DefaultIndexedFile indexedFile = new DefaultIndexedFile(moduleKey, moduleBaseDir, relativePath, type, idGenerator.get());
String language = langDetection.language(indexedFile);
if (language == null && langDetection.forcedLanguage() != null) {
LOG.warn("File '{}' is ignored because it doens't belong to the forced langauge '{}'", file.toAbsolutePath(), langDetection.forcedLanguage());
return null;
}
indexedFile.setLanguage(language);
DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> metadataGenerator.setMetadata(f, defaultEncoding));
if (language != null) {
inputFile.setPublish(true);
}
return inputFile;
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class SameInputFilePredicate method test.
@Override
public boolean test(InputFile inputFile) {
FileData fileDataPerPath = projectRepositories.fileData(moduleKey, inputFile.relativePath());
if (fileDataPerPath == null) {
// ADDED
return true;
}
String previousHash = fileDataPerPath.hash();
if (StringUtils.isEmpty(previousHash)) {
// ADDED
return true;
}
// this will trigger computation of metadata
String hash = ((DefaultInputFile) inputFile).hash();
if (StringUtils.equals(hash, previousHash)) {
// SAME
LOG.debug("'{}' filtering unmodified file", inputFile.relativePath());
return false;
}
// CHANGED
return true;
}
Aggregations