Search in sources :

Example 86 with WebSourceCode

use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.

the class InlineStyleCheckTest method test.

@Test
public void test() throws Exception {
    WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/inlineStyleCheck.html"), new InlineStyleCheck());
    checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(1).withMessage("Use CSS classes instead.");
}
Also used : WebSourceCode(org.sonar.plugins.web.visitor.WebSourceCode) File(java.io.File) Test(org.junit.Test)

Example 87 with WebSourceCode

use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.

the class IllegalTabCheckTest method test.

@Test
public void test() throws Exception {
    WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/IllegalTabCheck.html"), new IllegalTabCheck());
    checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(2).withMessage("Replace all tab characters in this file by sequences of white-spaces.");
}
Also used : WebSourceCode(org.sonar.plugins.web.visitor.WebSourceCode) File(java.io.File) Test(org.junit.Test)

Example 88 with WebSourceCode

use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.

the class WhiteSpaceAroundCheckTest method test.

@Test
public void test() throws Exception {
    WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/whiteSpaceAroundCheck.html"), new WhiteSpaceAroundCheck());
    checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(1).withMessage("A whitespace is missing after the starting tag at column 4.").next().atLine(1).withMessage("Add a space at column 18.").next().atLine(3).withMessage("Add a space at column 18.").next().atLine(5).withMessage("A whitespace is missing after the starting tag at column 2.").next().atLine(7).withMessage("A whitespace is missing after the starting tag at column 3.").next().atLine(9).withMessage("A whitespace is missing after the starting tag at column 3.").next().atLine(11).withMessage("A whitespace is missing after the starting tag at column 3.").next().atLine(13).withMessage("A whitespace is missing after the starting tag at column 4.").next().atLine(13).withMessage("Add a space at column 18.");
}
Also used : WebSourceCode(org.sonar.plugins.web.visitor.WebSourceCode) File(java.io.File) Test(org.junit.Test)

Example 89 with WebSourceCode

use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.

the class PageCountLines method addMeasures.

private void addMeasures() {
    WebSourceCode webSourceCode = getWebSourceCode();
    webSourceCode.addMeasure(CoreMetrics.NCLOC, linesOfCode);
    webSourceCode.addMeasure(CoreMetrics.COMMENT_LINES, commentLines);
    webSourceCode.setDetailedLinesOfCode(detailedLinesOfCode);
    webSourceCode.setDetailedLinesOfComments(detailedLinesOfComments);
    LOG.debug("WebSensor: " + getWebSourceCode().toString() + ":" + linesOfCode + "," + commentLines + "," + headerCommentLines + "," + blankLines);
}
Also used : WebSourceCode(org.sonar.plugins.web.visitor.WebSourceCode)

Example 90 with WebSourceCode

use of org.sonar.plugins.web.visitor.WebSourceCode 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

WebSourceCode (org.sonar.plugins.web.visitor.WebSourceCode)93 File (java.io.File)91 Test (org.junit.Test)89 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)10 InputFile (org.sonar.api.batch.fs.InputFile)8 FileReader (java.io.FileReader)6 PageLexer (org.sonar.plugins.web.lex.PageLexer)3 Node (org.sonar.plugins.web.node.Node)3 HtmlAstScanner (org.sonar.plugins.web.visitor.HtmlAstScanner)3 FileNotFoundException (java.io.FileNotFoundException)1 ExpectedException (org.junit.rules.ExpectedException)1 FilePredicates (org.sonar.api.batch.fs.FilePredicates)1 FileSystem (org.sonar.api.batch.fs.FileSystem)1 ComplexityVisitor (org.sonar.plugins.web.analyzers.ComplexityVisitor)1 PageCountLines (org.sonar.plugins.web.analyzers.PageCountLines)1