Search in sources :

Example 1 with VueLexer

use of org.sonar.plugins.html.lex.VueLexer in project sonar-web by SonarSource.

the class HtmlSensor method execute.

@Override
public void execute(SensorContext sensorContext) {
    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.or(predicates.hasLanguages(HtmlConstants.LANGUAGE_KEY, HtmlConstants.JSP_LANGUAGE_KEY), predicates.or(Stream.of(OTHER_FILE_SUFFIXES).map(predicates::hasExtension).toArray(FilePredicate[]::new)))));
    for (InputFile inputFile : inputFiles) {
        if (sensorContext.isCancelled()) {
            return;
        }
        HtmlSourceCode sourceCode = new HtmlSourceCode(inputFile);
        try (Reader reader = new InputStreamReader(inputFile.inputStream(), inputFile.charset())) {
            PageLexer lexer = inputFile.filename().endsWith(".vue") ? new VueLexer() : new PageLexer();
            scanner.scan(lexer.parse(reader), sourceCode);
            saveMetrics(sensorContext, sourceCode);
            saveLineLevelMeasures(inputFile, sourceCode);
        } catch (Exception e) {
            LOG.error("Cannot analyze file " + inputFile, e);
            sensorContext.newAnalysisError().onFile(inputFile).message(e.getMessage()).save();
        }
    }
}
Also used : VueLexer(org.sonar.plugins.html.lex.VueLexer) PageLexer(org.sonar.plugins.html.lex.PageLexer) InputStreamReader(java.io.InputStreamReader) FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) HtmlSourceCode(org.sonar.plugins.html.visitor.HtmlSourceCode) HtmlAstScanner(org.sonar.plugins.html.visitor.HtmlAstScanner) InputFile(org.sonar.api.batch.fs.InputFile)

Aggregations

InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 FilePredicates (org.sonar.api.batch.fs.FilePredicates)1 FileSystem (org.sonar.api.batch.fs.FileSystem)1 InputFile (org.sonar.api.batch.fs.InputFile)1 PageLexer (org.sonar.plugins.html.lex.PageLexer)1 VueLexer (org.sonar.plugins.html.lex.VueLexer)1 HtmlAstScanner (org.sonar.plugins.html.visitor.HtmlAstScanner)1 HtmlSourceCode (org.sonar.plugins.html.visitor.HtmlSourceCode)1