Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
"java-surefire/src/test/resources/**"
],
"packageRules": [
{
"description": "Java EE 6 is a test fixture that deliberately triggers a LinkageError",
"matchFileNames": [
"java-jsp/pom.xml"
],
"matchPackageNames": [
"javax:javaee-web-api"
],
"matchCurrentVersion": "/^6\\./",
"enabled": false
},
{
"description": "Plugin API has compatibility rules, so disable it to prevent accidental updates",
"matchPackageNames": [
Expand Down
9 changes: 9 additions & 0 deletions java-jsp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,25 @@
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.3.RELEASE</version>
<destFileName>spring-webmvc.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>8.0.1</version>
<destFileName>javaee-web-api-8.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<destFileName>javaee-web-api-6.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<destFileName>jstl.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/test-jars</outputDirectory>
Expand Down
40 changes: 26 additions & 14 deletions java-jsp/src/test/java/org/sonar/java/jsp/JasperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ class JasperTest {
</html>""";

private static final String SPRING_TLD = "<%@ taglib prefix=\"spring\" uri=\"http://www.springframework.org/tags\" %>\n";
private static final String JSTL_SOURCE = """
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<html>
<body>
<h2>Hello World!</h2>
<c:if test="true">what-if</c:if>
</body>
</html>
""";

Path tempFolder;
Path webInf;
Expand All @@ -74,9 +83,10 @@ class JasperTest {
@RegisterExtension
public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG);
private Path jspFile;
private final File springJar = Paths.get("target/test-jars/spring-webmvc-5.2.3.RELEASE.jar").toFile();
private final File jstlJar = Paths.get("target/test-jars/jstl-1.2.jar").toFile();
private final File jee6Jar = Paths.get("target/test-jars/javaee-web-api-6.0.jar").toFile();
private final File springJar = Paths.get("target/test-jars/spring-webmvc.jar").toFile();
private final File jstlJar = Paths.get("target/test-jars/jstl.jar").toFile();
private final File javaee6Jar = Paths.get("target/test-jars/javaee-web-api-6.jar").toFile();
private final File javaee8Jar = Paths.get("target/test-jars/javaee-web-api-8.jar").toFile();

@BeforeEach
void setUp() throws Exception {
Expand Down Expand Up @@ -172,23 +182,25 @@ void test_with_classpath() throws Exception {


@Test
void test_with_classpath_jee6_jstl() throws Exception {
SensorContextTester ctx = jspContext("""
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<html>
<body>
<h2>Hello World!</h2>
<c:if test="true">what-if</c:if>
</body>
</html>
""");
Collection<GeneratedFile> generatedFiles = new Jasper().generateFiles(ctx, asList(jee6Jar, jstlJar));
void test_linkage_error_with_classpath_javaee6_jstl() throws Exception {
SensorContextTester ctx = jspContext(JSTL_SOURCE);
assertThat(javaee6Jar).exists();
Collection<GeneratedFile> generatedFiles = new Jasper().generateFiles(ctx, asList(javaee6Jar, jstlJar));

assertThat(generatedFiles).isEmpty();
assertThat(logTester.logs(Level.DEBUG)).matches(logs -> logs.stream().anyMatch(line ->
line.startsWith("Error transpiling src/main/webapp/WEB-INF/jsp/test.jsp. Error:\njava.lang.ClassFormatError")));
}

@Test
void test_with_classpath_javaee8_jstl() throws Exception {
SensorContextTester ctx = jspContext(JSTL_SOURCE);
assertThat(javaee8Jar).exists();
Collection<GeneratedFile> generatedFiles = new Jasper().generateFiles(ctx, asList(javaee8Jar, jstlJar));

assertThat(generatedFiles).hasSize(1);
}

@Test
void test_compilation_without_webinf() throws Exception {
SensorContext ctx = jspContext(JSP_SOURCE, tempFolder.resolve("test.jsp"));
Expand Down
Loading