Search in sources :

Example 6 with FileSystem

use of org.sonar.api.batch.fs.FileSystem in project sonarqube by SonarSource.

the class RandomAccessSensor method execute.

@Override
public void execute(SensorContext context) {
    File f = new File(context.settings().getString(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS));
    FileSystem fs = context.fileSystem();
    FilePredicates p = fs.predicates();
    try {
        for (String path : FileUtils.readLines(f)) {
            createIssues(fs.inputFile(p.and(p.hasPath(path), p.hasType(Type.MAIN), p.hasLanguage(Xoo.KEY))), context);
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
Also used : FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) IOException(java.io.IOException) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File)

Example 7 with FileSystem

use of org.sonar.api.batch.fs.FileSystem in project sonar-web by SonarSource.

the class WebSensor method execute.

@Override
public void execute(SensorContext sensorContext) {
    // configure the lexer
    final PageLexer lexer = new PageLexer();
    FileSystem fileSystem = sensorContext.fileSystem();
    // configure page scanner and the visitors
    final HtmlAstScanner scanner = setupScanner(sensorContext);
    FilePredicates predicates = fileSystem.predicates();
    Iterable<InputFile> inputFiles = fileSystem.inputFiles(predicates.and(predicates.hasType(InputFile.Type.MAIN), predicates.hasLanguage(WebConstants.LANGUAGE_KEY)));
    for (InputFile inputFile : inputFiles) {
        WebSourceCode sourceCode = new WebSourceCode(inputFile);
        try (FileReader reader = new FileReader(inputFile.file())) {
            scanner.scan(lexer.parse(reader), sourceCode, fileSystem.encoding());
            saveMetrics(sensorContext, sourceCode);
            saveLineLevelMeasures(inputFile, sourceCode);
        } catch (Exception e) {
            LOG.error("Cannot analyze file " + inputFile.file().getAbsolutePath(), e);
        }
    }
}
Also used : PageLexer(org.sonar.plugins.web.lex.PageLexer) FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) WebSourceCode(org.sonar.plugins.web.visitor.WebSourceCode) FileReader(java.io.FileReader) HtmlAstScanner(org.sonar.plugins.web.visitor.HtmlAstScanner) InputFile(org.sonar.api.batch.fs.InputFile)

Aggregations

FilePredicates (org.sonar.api.batch.fs.FilePredicates)7 FileSystem (org.sonar.api.batch.fs.FileSystem)7 InputFile (org.sonar.api.batch.fs.InputFile)6 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Objects (java.util.Objects)1 StreamSupport (java.util.stream.StreamSupport)1 Type (org.sonar.api.batch.fs.InputFile.Type)1 Sensor (org.sonar.api.batch.sensor.Sensor)1 SensorContext (org.sonar.api.batch.sensor.SensorContext)1 SensorDescriptor (org.sonar.api.batch.sensor.SensorDescriptor)1 NewIssue (org.sonar.api.batch.sensor.issue.NewIssue)1 RuleKey (org.sonar.api.rule.RuleKey)1 PageLexer (org.sonar.plugins.web.lex.PageLexer)1 HtmlAstScanner (org.sonar.plugins.web.visitor.HtmlAstScanner)1 WebSourceCode (org.sonar.plugins.web.visitor.WebSourceCode)1