Search in sources :

Example 6 with FilePredicates

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

the class MultilineIssuesSensor method execute.

@Override
public void execute(SensorContext context) {
    FileSystem fs = context.fileSystem();
    FilePredicates p = fs.predicates();
    for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.MAIN)))) {
        createIssues(file, context);
    }
}
Also used : FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) InputFile(org.sonar.api.batch.fs.InputFile)

Example 7 with FilePredicates

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

the class CreateIssueByInternalKeySensor method execute.

@Override
public void execute(SensorContext context) {
    FileSystem fs = context.fileSystem();
    FilePredicates p = fs.predicates();
    for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.MAIN)))) {
        createIssues(file, context);
    }
}
Also used : FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) InputFile(org.sonar.api.batch.fs.InputFile)

Example 8 with FilePredicates

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

the class OneBugIssuePerLineSensor method analyse.

private void analyse(SensorContext context, String language, String repo) {
    FileSystem fs = context.fileSystem();
    FilePredicates p = fs.predicates();
    for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(language), p.hasType(Type.MAIN)))) {
        createIssues(file, context, repo);
    }
}
Also used : FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) InputFile(org.sonar.api.batch.fs.InputFile)

Example 9 with FilePredicates

use of org.sonar.api.batch.fs.FilePredicates 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 10 with FilePredicates

use of org.sonar.api.batch.fs.FilePredicates 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)10 InputFile (org.sonar.api.batch.fs.InputFile)9 FileSystem (org.sonar.api.batch.fs.FileSystem)7 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 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 CpdMapping (org.sonar.api.batch.CpdMapping)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 Check (org.sonar.xoo.checks.Check)1