use of org.sonar.api.batch.fs.FileSystem in project magik-tools by StevenLooman.
the class MagikSquidSensor method execute.
@Override
public void execute(final SensorContext context) {
final FileSystem fileSystem = context.fileSystem();
final FilePredicates predicates = fileSystem.predicates();
final FilePredicate filePredicate = predicates.and(predicates.hasType(InputFile.Type.MAIN), predicates.hasLanguage(Magik.KEY));
final List<InputFile> inputFiles = new ArrayList<>();
fileSystem.inputFiles(filePredicate).forEach(inputFiles::add);
final ProgressReport progressReport = new ProgressReport("Report about progress of Sonar Magik analyzer", SLEEP_PERIOD);
final List<String> filenames = inputFiles.stream().map(InputFile::toString).collect(Collectors.toList());
progressReport.start(filenames);
for (final InputFile inputFile : inputFiles) {
this.scanMagikFile(context, inputFile);
progressReport.nextFile();
}
progressReport.stop();
}
use of org.sonar.api.batch.fs.FileSystem in project sonar-go by SonarSource.
the class GoCoverageReport method saveFileCoverage.
private static void saveFileCoverage(SensorContext sensorContext, String filePath, List<CoverageStat> coverageStats) throws IOException {
FileSystem fileSystem = sensorContext.fileSystem();
InputFile inputFile = findInputFile(filePath, fileSystem);
if (inputFile != null) {
LOG.debug("Saving coverage measures for file '{}'", filePath);
List<String> lines = Arrays.asList(inputFile.contents().split("\\r?\\n"));
NewCoverage newCoverage = sensorContext.newCoverage().onFile(inputFile);
FileCoverage fileCoverage = new FileCoverage(coverageStats, lines);
for (Map.Entry<Integer, LineCoverage> entry : fileCoverage.lineMap.entrySet()) {
newCoverage.lineHits(entry.getKey(), entry.getValue().hits);
}
newCoverage.save();
} else {
LOG.warn("File '{}' is not included in the project, ignoring coverage", filePath);
}
}
use of org.sonar.api.batch.fs.FileSystem in project sonar-iac by SonarSource.
the class IacSensor method execute.
@Override
public void execute(SensorContext sensorContext) {
if (!isActive(sensorContext)) {
return;
}
importExternalReports(sensorContext);
DurationStatistics statistics = new DurationStatistics(sensorContext.config());
FileSystem fileSystem = sensorContext.fileSystem();
Iterable<InputFile> inputFiles = fileSystem.inputFiles(mainFilePredicate(sensorContext));
List<String> filenames = StreamSupport.stream(inputFiles.spliterator(), false).map(InputFile::toString).collect(Collectors.toList());
ProgressReport progressReport = new ProgressReport("Progress of the " + language.getName() + " analysis", TimeUnit.SECONDS.toMillis(10));
progressReport.start(filenames);
boolean success = false;
Analyzer analyzer = new Analyzer(treeParser(), visitors(sensorContext, statistics), statistics);
try {
success = analyzer.analyseFiles(sensorContext, inputFiles, progressReport);
} finally {
if (success) {
progressReport.stop();
} else {
progressReport.cancel();
}
}
statistics.log();
}
use of org.sonar.api.batch.fs.FileSystem in project sonar-php by SonarSource.
the class CoverageResultImporter method saveCoverageMeasure.
/**
* Saves the required metrics found on the fileNode
*
* @param fileNode the file
*/
private void saveCoverageMeasure(FileNode fileNode, SensorContext context) {
FileSystem fileSystem = context.fileSystem();
// PHP supports only absolute paths
String path = fileNode.getName();
InputFile inputFile = fileSystem.inputFile(fileSystem.predicates().hasPath(path));
// targeted file for coverage is not null.
if (inputFile != null) {
saveCoverageLineHitsData(fileNode, inputFile, context);
// Saving the uncovered statements (lines) is no longer needed because coverage metrics are internally derived by the NewCoverage
} else {
unresolvedInputFiles.add(path);
}
}
use of org.sonar.api.batch.fs.FileSystem in project sonar-findbugs by spotbugs.
the class FindbugsExecutorTest method shoulFailIfNoCompiledClasses.
public void shoulFailIfNoCompiledClasses() throws Exception {
FileSystem fs = mock(FileSystem.class);
when(fs.baseDir()).thenReturn(new File("."));
SimpleConfiguration configuration = new SimpleConfiguration();
// settings.setProperty(CoreProperties.CORE_VIOLATION_LOCALE_PROPERTY, Locale.getDefault().getDisplayName());
FindbugsConfiguration conf = new FindbugsConfiguration(fs, configuration, null, null);
FindbugsExecutor executor = new FindbugsExecutor(conf, fsEmpty, configEmpty);
assertThrows(IllegalStateException.class, () -> {
executor.execute();
});
}
Aggregations