use of org.sonar.java.model.GeneratedFile in project sonar-java by SonarSource.
the class JasperTest method test_exclude_current_jsp.
@Test
void test_exclude_current_jsp() throws Exception {
SensorContextTester ctx = jspContext(JSP_SOURCE);
ctx.setSettings(new MapSettings().setProperty("sonar.exclusions", "**/any.js,**/test_jsp.java"));
Collection<GeneratedFile> generatedFiles = new Jasper().generateFiles(ctx, emptyList());
assertThat(generatedFiles).isEmpty();
}
use of org.sonar.java.model.GeneratedFile in project sonar-java by SonarSource.
the class JasperTest method test_failing_tag_compilation.
@Test
void test_failing_tag_compilation() throws Exception {
String tagLib = "<%@ taglib prefix=\"t\" tagdir=\"/WEB-INF/tags\" %>";
SensorContextTester ctx = jspContext(tagLib + "<t:mytag />");
createJspFile(tagLib + "<% new Missing(); %> ", webInf.resolve("tags/mytag.tag"));
Map<String, GeneratedFile> generatedFiles = new Jasper().generateFiles(ctx, emptyList()).stream().collect(Collectors.toMap(GeneratedFile::filename, f -> f));
assertThat(generatedFiles).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).matches(logs -> logs.stream().anyMatch(line -> line.startsWith("Error transpiling src/main/webapp/WEB-INF/jsp/test.jsp. Error:\norg.apache.jasper.JasperException:")));
}
use of org.sonar.java.model.GeneratedFile in project sonar-java by SonarSource.
the class JavaSensorTest method assertJasperIsInvoked.
private void assertJasperIsInvoked(MapSettings settings) throws IOException {
Path base = tmp.newFolder().toPath();
Path generatedFilePath = tmp.newFile("Generated.java").toPath();
Files.write(generatedFilePath, "class Generated {}".getBytes());
GeneratedFile generatedFile = new GeneratedFile(generatedFilePath);
SensorContextTester context = SensorContextTester.create(base);
context.setSettings(settings);
context.fileSystem().setWorkDir(tmp.newFolder().toPath());
SonarComponents sonarComponents = createSonarComponentsMock(context);
JavaFileScanner javaFileScanner = mock(JavaFileScanner.class);
JspCodeScanner testCodeVisitor = mock(JspCodeScanner.class);
when(sonarComponents.jspChecks()).thenReturn(Collections.singletonList(testCodeVisitor));
when(sonarComponents.mainChecks()).thenReturn(Collections.singletonList(javaFileScanner));
Jasper jasper = mock(Jasper.class);
when(jasper.generateFiles(any(), any())).thenReturn(asList(generatedFile));
JavaSensor jss = new JavaSensor(sonarComponents, context.fileSystem(), mock(JavaResourceLocator.class), new MapSettings().asConfig(), mock(NoSonarFilter.class), null, jasper);
jss.execute(context);
ArgumentCaptor<JavaFileScannerContext> scannerContext = ArgumentCaptor.forClass(JavaFileScannerContext.class);
verify(testCodeVisitor, times(1)).scanFile(scannerContext.capture());
assertThat(scannerContext.getValue().getInputFile()).isSameAs(generatedFile);
// normal visitors are not invoked on generated files
verify(javaFileScanner, never()).scanFile(any());
}
Aggregations