use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class GenericCoverageReportParser method parseFiles.
private void parseFiles(SMInputCursor fileCursor, SensorContext context) throws XMLStreamException {
while (fileCursor.getNext() != null) {
checkElementName(fileCursor, "file");
String filePath = mandatoryAttribute(fileCursor, "path");
InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath));
if (inputFile == null) {
numberOfUnknownFiles++;
if (numberOfUnknownFiles <= MAX_STORED_UNKNOWN_FILE_PATHS) {
firstUnknownFiles.add(filePath);
}
continue;
}
Preconditions.checkState(inputFile.language() != null, "Line %s of report refers to a file with an unknown language: %s", fileCursor.getCursorLocation().getLineNumber(), filePath);
matchedFileKeys.add(inputFile.absolutePath());
NewCoverage newCoverage = context.newCoverage().onFile(inputFile);
SMInputCursor lineToCoverCursor = fileCursor.childElementCursor();
while (lineToCoverCursor.getNext() != null) {
parseLineToCover(lineToCoverCursor, newCoverage);
}
newCoverage.save();
}
}
use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class MeasuresPublisher method updateTestExecutionFromTestPlan.
private void updateTestExecutionFromTestPlan(final InputFile inputFile) {
final MutableTestPlan testPlan = testPlanBuilder.getTestPlanByFile(inputFile);
if (testPlan == null || Iterables.isEmpty(testPlan.testCases())) {
return;
}
long nonSkippedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() != Status.SKIPPED).count();
measureCache.put(inputFile.key(), TESTS_KEY, new DefaultMeasure<Integer>().forMetric(TESTS).withValue((int) nonSkippedTests));
long executionTime = StreamSupport.stream(testPlan.testCases().spliterator(), false).mapToLong(t -> t.durationInMs() != null ? t.durationInMs().longValue() : 0L).sum();
measureCache.put(inputFile.key(), TEST_EXECUTION_TIME_KEY, new DefaultMeasure<Long>().forMetric(TEST_EXECUTION_TIME).withValue(executionTime));
long errorTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.ERROR).count();
measureCache.put(inputFile.key(), TEST_ERRORS_KEY, new DefaultMeasure<Integer>().forMetric(TEST_ERRORS).withValue((int) errorTests));
long skippedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.SKIPPED).count();
measureCache.put(inputFile.key(), SKIPPED_TESTS_KEY, new DefaultMeasure<Integer>().forMetric(SKIPPED_TESTS).withValue((int) skippedTests));
long failedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.FAILURE).count();
measureCache.put(inputFile.key(), TEST_FAILURES_KEY, new DefaultMeasure<Integer>().forMetric(TEST_FAILURES).withValue((int) failedTests));
}
use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class SourceProvider method getEscapedSource.
public List<String> getEscapedSource(DefaultInputComponent component) {
if (!component.isFile()) {
// Folder
return Collections.emptyList();
}
try {
InputFile inputFile = (InputFile) component;
List<String> lines = FileUtils.readLines(inputFile.file(), fs.encoding());
List<String> escapedLines = new ArrayList<>(lines.size());
for (String line : lines) {
escapedLines.add(StringEscapeUtils.escapeHtml(line));
}
return escapedLines;
} catch (IOException e) {
LOG.warn("Unable to read source code of resource {}", component, e);
return Collections.emptyList();
}
}
use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class DefaultBlameOutput method finish.
public void finish(boolean success) {
progressReport.stop(count + "/" + total + " files analyzed");
if (success && !allFilesToBlame.isEmpty()) {
LOG.warn("Missing blame information for the following files:");
for (InputFile f : allFilesToBlame) {
LOG.warn(" * " + f.absolutePath());
}
LOG.warn("This may lead to missing/broken features in SonarQube");
}
}
use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class HighlightingMediumTest method computeSyntaxHighlightingOnTempProject.
@Test
public void computeSyntaxHighlightingOnTempProject() throws IOException {
File baseDir = temp.newFolder();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
File xoohighlightingFile = new File(srcDir, "sample.xoo.highlighting");
FileUtils.write(xooFile, "Sample xoo\ncontent plop");
FileUtils.write(xoohighlightingFile, "0:10:s\n11:18:k");
TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").build()).start();
InputFile file = result.inputFile("src/sample.xoo");
assertThat(result.highlightingTypeFor(file, 1, 0)).containsExactly(TypeOfText.STRING);
assertThat(result.highlightingTypeFor(file, 1, 9)).containsExactly(TypeOfText.STRING);
assertThat(result.highlightingTypeFor(file, 2, 0)).containsExactly(TypeOfText.KEYWORD);
assertThat(result.highlightingTypeFor(file, 2, 8)).isEmpty();
}
Aggregations