Search in sources :

Example 1 with FileLinesContext

use of org.sonar.api.measures.FileLinesContext in project sonarqube by SonarSource.

the class LineMeasureSensor method processFileMeasures.

private void processFileMeasures(InputFile inputFile, SensorContext context) {
    File ioFile = inputFile.file();
    File measureFile = new File(ioFile.getParentFile(), ioFile.getName() + MEASURES_EXTENSION);
    if (measureFile.exists()) {
        LOG.debug("Processing " + measureFile.getAbsolutePath());
        try {
            FileLinesContext linesContext = contextFactory.createFor(inputFile);
            List<String> lines = FileUtils.readLines(measureFile, context.fileSystem().encoding().name());
            int lineNumber = 0;
            for (String line : lines) {
                lineNumber++;
                if (StringUtils.isBlank(line) || line.startsWith("#")) {
                    continue;
                }
                processMeasure(inputFile, linesContext, measureFile, lineNumber, line);
            }
            linesContext.save();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
}
Also used : IOException(java.io.IOException) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) FileLinesContext(org.sonar.api.measures.FileLinesContext)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 InputFile (org.sonar.api.batch.fs.InputFile)1 FileLinesContext (org.sonar.api.measures.FileLinesContext)1