use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class CoveragePublisher method publish.
@Override
public void publish(ScannerReportWriter writer) {
for (final DefaultInputFile inputFile : componentStore.allFilesToPublish()) {
Map<Integer, LineCoverage.Builder> coveragePerLine = new LinkedHashMap<>();
int lineCount = inputFile.lines();
applyLineMeasure(inputFile.key(), lineCount, CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, coveragePerLine, (value, builder) -> builder.setHits(Integer.parseInt(value) > 0));
applyLineMeasure(inputFile.key(), lineCount, CoreMetrics.CONDITIONS_BY_LINE_KEY, coveragePerLine, (value, builder) -> builder.setConditions(Integer.parseInt(value)));
applyLineMeasure(inputFile.key(), lineCount, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine, (value, builder) -> builder.setCoveredConditions(Integer.parseInt(value)));
writer.writeComponentCoverage(inputFile.batchId(), Iterables.transform(coveragePerLine.values(), BuildCoverage.INSTANCE));
}
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class FileIndexer method indexFile.
private Void indexFile(DefaultModuleFileSystem fileSystem, Progress progress, Path sourceFile, InputFile.Type type) throws IOException {
// get case of real file without resolving link
Path realFile = sourceFile.toRealPath(LinkOption.NOFOLLOW_LINKS);
DefaultInputFile inputFile = inputFileBuilder.create(realFile, type, fileSystem.encoding());
if (inputFile != null) {
if (exclusionFilters.accept(inputFile, type) && accept(inputFile)) {
synchronized (this) {
fileSystem.add(inputFile);
indexParentDir(fileSystem, inputFile);
progress.markAsIndexed(inputFile);
}
LOG.debug("'{}' indexed {}with language '{}'", inputFile.relativePath(), type == Type.TEST ? "as test " : "", inputFile.language());
inputFileBuilder.checkMetadata(inputFile);
} else {
progress.increaseExcludedByPatternsCount();
}
}
return null;
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class TaskResult method highlightingTypeFor.
/**
* Get highlighting types at a given position in an inputfile
* @param lineOffset 0-based offset in file
*/
public List<TypeOfText> highlightingTypeFor(InputFile file, int line, int lineOffset) {
int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef();
if (!reader.hasSyntaxHighlighting(ref)) {
return Collections.emptyList();
}
TextPointer pointer = file.newPointer(line, lineOffset);
List<TypeOfText> result = new ArrayList<>();
try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = reader.readComponentSyntaxHighlighting(ref)) {
while (it.hasNext()) {
ScannerReport.SyntaxHighlightingRule rule = it.next();
TextRange ruleRange = toRange(file, rule.getRange());
if (ruleRange.start().compareTo(pointer) <= 0 && ruleRange.end().compareTo(pointer) > 0) {
result.add(ScannerReportUtils.toBatchType(rule.getType()));
}
}
} catch (Exception e) {
throw new IllegalStateException("Can't read syntax highlighting for " + file.absolutePath(), e);
}
return result;
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class JSONReport method writeJsonComponents.
private void writeJsonComponents(JsonWriter json) throws IOException {
json.name("components").beginArray();
// Dump modules
writeJsonModuleComponents(json, rootModule);
for (DefaultInputFile inputFile : componentStore.allFilesToPublish()) {
String moduleKey = getModule(inputFile).definition().getKeyWithBranch();
String key = ComponentKeys.createEffectiveKey(moduleKey, inputFile);
json.beginObject().prop("key", key).prop("path", inputFile.relativePath()).prop("moduleKey", moduleKey).prop("status", inputFile.status().name()).endObject();
}
for (InputDir inputDir : componentStore.allDirs()) {
String moduleKey = getModule(inputDir).definition().getKeyWithBranch();
String key = ComponentKeys.createEffectiveKey(moduleKey, inputDir);
json.beginObject().prop("key", key).prop("path", inputDir.relativePath()).prop("moduleKey", moduleKey).endObject();
}
json.endArray();
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class LocalIssueTracking method loadSourceHashes.
@CheckForNull
private SourceHashHolder loadSourceHashes(InputComponent component) {
SourceHashHolder sourceHashHolder = null;
if (component.isFile()) {
DefaultInputModule module = (DefaultInputModule) componentTree.getParent(componentTree.getParent(component));
DefaultInputFile file = (DefaultInputFile) component;
sourceHashHolder = new SourceHashHolder(module, file, lastLineHashes);
}
return sourceHashHolder;
}
Aggregations