use of org.sonar.java.model.JavaVersionImpl in project sonar-java by SonarSource.
the class JavaCheckVerifier method verifyNoIssueWithoutSemantic.
public static void verifyNoIssueWithoutSemantic(String filename, JavaFileScanner check, int javaVersion) {
JavaCheckVerifier javaCheckVerifier = new JavaCheckVerifier() {
@Override
public String getExpectedIssueTrigger() {
return "// NOSEMANTIC_ISSUE";
}
};
javaCheckVerifier.expectNoIssues();
javaCheckVerifier.providedJavaVersion = true;
javaCheckVerifier.javaVersion = new JavaVersionImpl(javaVersion);
scanFile(filename, check, javaCheckVerifier, Collections.<File>emptyList(), false);
}
use of org.sonar.java.model.JavaVersionImpl 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;
}
use of org.sonar.java.model.JavaVersionImpl 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());
}
use of org.sonar.java.model.JavaVersionImpl in project sonar-java by SonarSource.
the class MeasurerTest method checkMetric.
private void checkMetric(String filename, String metric, @Nullable Number expectedValue, int numberOfMetrics) {
String relativePath = PathUtils.sanitize(new File(baseDir, filename).getPath());
TestInputFileBuilder inputFile = new TestInputFileBuilder(context.module().key(), relativePath);
inputFile.setModuleBaseDir(fs.baseDirPath());
fs.add(inputFile.build());
Measurer measurer = new Measurer(fs, context, mock(NoSonarFilter.class));
JavaSquid squid = new JavaSquid(new JavaVersionImpl(), null, measurer, null, null, new JavaCheck[0]);
squid.scan(Lists.newArrayList(new File(baseDir, filename)), Collections.emptyList());
assertThat(context.measures("projectKey:" + relativePath)).hasSize(numberOfMetrics);
Measure<Serializable> measure = context.measure("projectKey:" + relativePath, metric);
if (expectedValue == null) {
assertThat(measure).isNull();
} else {
assertThat(measure.value()).isEqualTo(expectedValue);
}
}
use of org.sonar.java.model.JavaVersionImpl in project sonar-java by SonarSource.
the class StrutsTest method initAndScan.
private static void initAndScan() {
File prjDir = new File("target/test-projects/struts-core-1.3.9");
File srcDir = new File(prjDir, "src");
context = SensorContextTester.create(prjDir);
DefaultFileSystem fs = context.fileSystem();
Collection<File> files = FileUtils.listFiles(srcDir, new String[] { "java" }, true);
for (File file : files) {
fs.add(new TestInputFileBuilder("", file.getPath()).build());
}
Measurer measurer = new Measurer(fs, context, mock(NoSonarFilter.class));
JavaResourceLocator javaResourceLocator = mock(JavaResourceLocator.class);
JavaSquid squid = new JavaSquid(new JavaVersionImpl(), null, measurer, javaResourceLocator, null, new JavaCheck[0]);
squid.scan(files, Collections.<File>emptyList());
}
Aggregations