Search in sources :

Example 1 with JavaSquid

use of org.sonar.java.JavaSquid in project sonar-java by SonarSource.

the class FileLinesVisitorTest method countTrivia.

private int countTrivia(String filename) {
    TriviaVisitor triviaVisitor = new TriviaVisitor();
    JavaSquid squid = new JavaSquid(new JavaVersionImpl(), null, null, null, null, triviaVisitor);
    squid.scan(Lists.newArrayList(new File(baseDir, filename)), Collections.emptyList());
    return triviaVisitor.numberTrivia;
}
Also used : JavaVersionImpl(org.sonar.java.model.JavaVersionImpl) JavaSquid(org.sonar.java.JavaSquid) File(java.io.File)

Example 2 with JavaSquid

use of org.sonar.java.JavaSquid in project sonar-java by SonarSource.

the class FileLinesVisitorTest method checkLines.

private void checkLines(String filename, FileLinesContext context) {
    SonarComponents sonarComponents = mock(SonarComponents.class);
    when(sonarComponents.fileLength(Mockito.any(File.class))).thenAnswer(invocation -> {
        File arg = (File) invocation.getArguments()[0];
        return Files.readLines(arg, StandardCharsets.UTF_8).size();
    });
    when(sonarComponents.fileLinesContextFor(Mockito.any(File.class))).thenReturn(context);
    JavaSquid squid = new JavaSquid(new JavaVersionImpl(), null, null, null, null, new FileLinesVisitor(sonarComponents));
    squid.scan(Lists.newArrayList(new File(baseDir, filename)), Collections.emptyList());
}
Also used : SonarComponents(org.sonar.java.SonarComponents) JavaVersionImpl(org.sonar.java.model.JavaVersionImpl) JavaSquid(org.sonar.java.JavaSquid) File(java.io.File)

Example 3 with JavaSquid

use of org.sonar.java.JavaSquid in project sonar-java by SonarSource.

the class JavaSquidSensor method execute.

@Override
public void execute(SensorContext context) {
    javaResourceLocator.setSensorContext(context);
    sonarComponents.setSensorContext(context);
    sonarComponents.setRuleRepositoryKey(CheckList.REPOSITORY_KEY);
    List<Class<? extends JavaCheck>> checks = ImmutableList.<Class<? extends JavaCheck>>builder().addAll(CheckList.getJavaChecks()).addAll(CheckList.getDebugChecks()).build();
    sonarComponents.registerCheckClasses(CheckList.REPOSITORY_KEY, checks);
    sonarComponents.registerTestCheckClasses(CheckList.REPOSITORY_KEY, CheckList.getJavaTestChecks());
    Measurer measurer = new Measurer(fs, context, noSonarFilter);
    JavaSquid squid = new JavaSquid(getJavaVersion(), isXFileEnabled(), sonarComponents, measurer, javaResourceLocator, postAnalysisIssueFilter, sonarComponents.checkClasses());
    squid.scan(getSourceFiles(), getTestFiles());
    sonarComponents.saveAnalysisErrors();
}
Also used : Measurer(org.sonar.java.Measurer) JavaCheck(org.sonar.plugins.java.api.JavaCheck) JavaSquid(org.sonar.java.JavaSquid)

Example 4 with JavaSquid

use of org.sonar.java.JavaSquid in project sonar-java by SonarSource.

the class SyntaxHighlighterVisitorTest method scan.

private void scan(File file) {
    JavaSquid squid = new JavaSquid(new JavaVersionImpl(), null, null, null, null, new JavaCheck[] { syntaxHighlighterVisitor });
    squid.scan(Lists.newArrayList(file), Collections.<File>emptyList());
}
Also used : JavaVersionImpl(org.sonar.java.model.JavaVersionImpl) JavaSquid(org.sonar.java.JavaSquid)

Aggregations

JavaSquid (org.sonar.java.JavaSquid)4 JavaVersionImpl (org.sonar.java.model.JavaVersionImpl)3 File (java.io.File)2 Measurer (org.sonar.java.Measurer)1 SonarComponents (org.sonar.java.SonarComponents)1 JavaCheck (org.sonar.plugins.java.api.JavaCheck)1