Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new JSP option javaSourceLevel #25494

Merged
merged 6 commits into from
Jan 6, 2024
Merged
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
2 changes: 1 addition & 1 deletion dev/cnf/dependabot/check_this_in_if_it_changes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2444,7 +2444,7 @@
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.35.0</version>
<version>3.36.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
Expand Down
2 changes: 1 addition & 1 deletion dev/cnf/oss_dependencies.maven
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ org.eclipse.birt.runtime.3_7_1:org.apache.xml.serializer:2.7.1
org.eclipse.birt.runtime:org.w3c.css.sac:1.3.1.v200903091627
org.eclipse.jdt:ecj:3.26.0
org.eclipse.jdt:ecj:3.33.0
org.eclipse.jdt:ecj:3.35.0
org.eclipse.jdt:ecj:3.36.0
org.eclipse.jetty.websocket:javax-websocket-client-impl:9.2.2.v20140723
org.eclipse.jetty.websocket:javax-websocket-client-impl:9.4.39.v20210325
org.eclipse.jetty.websocket:websocket-api:9.2.2.v20140723
Expand Down
3 changes: 0 additions & 3 deletions dev/com.ibm.ws.jsp.2.3_fat/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
# http://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# IBM Corporation - initial API and implementation
#*******************************************************************************
-include= ~../cnf/resources/bnd/bundle.props
bVersion=1.0
Expand Down
3 changes: 0 additions & 3 deletions dev/com.ibm.ws.jsp.2.3_fat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
dependencies {
requiredLibs project(':io.openliberty.org.apache.commons.codec'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import com.ibm.ws.jsp23.fat.tests.JSP23JSP22ServerTest;
import com.ibm.ws.jsp23.fat.tests.JSPCdiTest;
import com.ibm.ws.jsp23.fat.tests.JSPExceptionTests;
import com.ibm.ws.jsp23.fat.tests.JSPJava11Test;
import com.ibm.ws.jsp23.fat.tests.JSPJava17Test;
import com.ibm.ws.jsp23.fat.tests.JSPJava21Test;
import com.ibm.ws.jsp23.fat.tests.JSPJava8Test;
import com.ibm.ws.jsp23.fat.tests.JSPPrepareJSPThreadCountDefaultValueTests;
import com.ibm.ws.jsp23.fat.tests.JSPPrepareJSPThreadCountNonDefaultValueTests;
Expand All @@ -42,6 +45,9 @@
JSPExceptionTests.class,
JSPSkipMetaInfTests.class,
JSPJava8Test.class,
JSPJava11Test.class,
JSPJava17Test.class,
JSPJava21Test.class,
JSPCdiTest.class,
JSP23JSP22ServerTest.class,
JSPPrepareJSPThreadCountNonDefaultValueTests.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*******************************************************************************
* Copyright (c) 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package com.ibm.ws.jsp23.fat.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Collections;
import java.util.logging.Logger;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.ibm.websphere.simplicity.ShrinkHelper;
import com.ibm.websphere.simplicity.config.ServerConfiguration;
import com.ibm.ws.jsp23.fat.JSPUtils;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

import componenttest.annotation.MinimumJavaLevel;
import componenttest.annotation.Server;
import componenttest.annotation.SkipForRepeat;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.custom.junit.runner.Mode;
import componenttest.custom.junit.runner.Mode.TestMode;
import componenttest.topology.impl.LibertyServer;

/**
* JSP 2.3 tests which use Java 11 specific features.
*
* Tests must only run when Java 11 is in use.
*
*/
@Mode(TestMode.FULL)
@MinimumJavaLevel(javaLevel = 11)
@SkipForRepeat("CDI-2.0") // No need to run against cdi-2.0 since these tests don't use CDI at all.
@RunWith(FATRunner.class)
public class JSPJava11Test {
private static final String APP_NAME = "TestJSPWithJava11";
private static final Logger LOG = Logger.getLogger(JSPJava11Test.class.getName());

@Server("jspJava11Server")
public static LibertyServer server;

@BeforeClass
public static void setup() throws Exception {
ShrinkHelper.defaultDropinApp(server, APP_NAME + ".war");

server.startServer(JSPJava11Test.class.getSimpleName() + ".log");
}

@AfterClass
public static void testCleanup() throws Exception {
// Stop the server
if (server != null && server.isStarted()) {
server.stopServer();
}
}

/**
* Simple test for index.jsp. Page uses Java 11's String#strip method
*
* @throws Exception
* if something goes horribly wrong
*/
@Test
public void testJava11JSP() throws Exception {
WebConversation wc = new WebConversation();
wc.setExceptionsThrownOnErrorStatus(false);

String url = JSPUtils.createHttpUrlString(server, APP_NAME, "index.jsp");
LOG.info("url: " + url);

WebRequest request = new GetMethodWebRequest(url);
WebResponse response = wc.getResponse(request);
LOG.info("Servlet response : " + response.getText());

assertEquals("Expected " + 200 + " status code was not returned!",
200, response.getResponseCode());
assertTrue("Java 11's String strip() method failed", response.getText().contains("success-strip"));
assertTrue("Java 11's String lines() did not return a stream.", response.getText().contains("java.util.stream.ReferencePipeline"));
assertTrue("Java 11's Map copyOf method failed", response.getText().contains("{key=success-copyof}"));
}

/**
* Same test as testJava11JSP, but using the runtime JDK (via JSP's useJDKCompiler option rather than the default Eclipse Compiler for Java (ECJ))
*
* https://openliberty.io/docs/latest/reference/config/jspEngine.html
*
* @throws Exception if something goes horribly wrong
*
*/
@Test
public void testJava11viaUseJDKCompiler() throws Exception {
volosied marked this conversation as resolved.
Show resolved Hide resolved

ServerConfiguration configuration = server.getServerConfiguration();
configuration.getJspEngine().setUseJDKCompiler(true);
LOG.info("New server configuration used: " + configuration);
server.setMarkToEndOfLog();
server.updateServerConfiguration(configuration);
server.restartApplication(APP_NAME);
server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), false, "CWWKT0016I:.*TestJSPWithJava11.*");

WebConversation wc = new WebConversation();
wc.setExceptionsThrownOnErrorStatus(false);

String url = JSPUtils.createHttpUrlString(server, APP_NAME, "index.jsp");
LOG.info("url: " + url);

WebRequest request = new GetMethodWebRequest(url);
WebResponse response = wc.getResponse(request);
LOG.info("Servlet response : " + response.getText());

assertEquals("Expected " + 200 + " status code was not returned!",
200, response.getResponseCode());
assertTrue("Java 11's String strip() method failed", response.getText().contains("success-strip"));
assertTrue("Java 11's String lines() did not return a stream.", response.getText().contains("java.util.stream.ReferencePipeline"));
assertTrue("Java 11's Map copyOf method failed", response.getText().contains("{key=success-copyof}"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package com.ibm.ws.jsp23.fat.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Collections;
import java.util.logging.Logger;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.ibm.websphere.simplicity.ShrinkHelper;
import com.ibm.ws.jsp23.fat.JSPUtils;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

import componenttest.annotation.MinimumJavaLevel;
import componenttest.annotation.MaximumJavaLevel;
import componenttest.annotation.Server;
import componenttest.annotation.SkipForRepeat;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.topology.impl.LibertyServer;

import com.ibm.websphere.simplicity.config.ServerConfiguration;
/**
* JSP 2.3 tests which use Java 17 specific features.
*
* Tests must only run when Java 17 or later is in use.
*
*/
@MinimumJavaLevel(javaLevel = 17)
pnicolucci marked this conversation as resolved.
Show resolved Hide resolved
@SkipForRepeat("CDI-2.0") // No need to run against cdi-2.0 since these tests don't use CDI at all.
@RunWith(FATRunner.class)
public class JSPJava17Test {
private static final String APP_NAME = "TestJSPWithJava17";
private static final Logger LOG = Logger.getLogger(JSPJava17Test.class.getName());

@Server("jspJava17Server")
public static LibertyServer server;

@BeforeClass
public static void setup() throws Exception {
ShrinkHelper.defaultDropinApp(server, APP_NAME + ".war");

server.startServer(JSPJava17Test.class.getSimpleName() + ".log");
}

@AfterClass
public static void testCleanup() throws Exception {
// Stop the server
if (server != null && server.isStarted()) {
// testBothjdkSourceLevelAndjavaSourceLevel causes CWWJS0005W: Both javaSourceLevel=17 and jdkSourceLevel=18 are specified. Defaulting to javaSourceLevel=17
server.stopServer("CWWJS0005W");
}
}

/**
* Simple test for index.jsp. Page uses Java 17's instanceof pattern matching
*
* @throws Exception
* if something goes horribly wrong
*/
@Test
public void testJava17JSP() throws Exception {
WebConversation wc = new WebConversation();
wc.setExceptionsThrownOnErrorStatus(false);

String url = JSPUtils.createHttpUrlString(server, APP_NAME, "index.jsp");
LOG.info("url: " + url);

WebRequest request = new GetMethodWebRequest(url);
WebResponse response = wc.getResponse(request);
LOG.info("Servlet response : " + response.getText());

assertEquals("Expected " + 200 + " status code was not returned!",
200, response.getResponseCode());
assertTrue("The response did not contain: success", response.getText().contains("success-text-block"));
assertTrue("The response did not contain: success", response.getText().contains("success-pattern-matching"));
}

/**
* Same test as testJava17JSP, but using the runtime JDK (via JSP's useJDKCompiler option rather than the default Eclipse Compiler for Java (ECJ))
*
* https://openliberty.io/docs/latest/reference/config/jspEngine.html
*
* @throws Exception if something goes horribly wrong
*
*/
@Test
public void testJava17viaUseJDKCompiler() throws Exception {
volosied marked this conversation as resolved.
Show resolved Hide resolved

ServerConfiguration configuration = server.getServerConfiguration();
configuration.getJspEngine().setUseJDKCompiler(true);
LOG.info("New server configuration used: " + configuration);

server.setMarkToEndOfLog();
server.updateServerConfiguration(configuration);
server.restartApplication(APP_NAME);
server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), false, "CWWKT0016I:.*TestJSPWithJava17.*");

WebConversation wc = new WebConversation();
wc.setExceptionsThrownOnErrorStatus(false);

String url = JSPUtils.createHttpUrlString(server, APP_NAME, "index.jsp");
LOG.info("url: " + url);

WebRequest request = new GetMethodWebRequest(url);
WebResponse response = wc.getResponse(request);
LOG.info("Servlet response : " + response.getText());

assertEquals("Expected " + 200 + " status code was not returned!",
200, response.getResponseCode());
assertTrue("The response did not contain: success", response.getText().contains("success-text-block"));
assertTrue("The response did not contain: success", response.getText().contains("success-pattern-matching"));
}

/*
* Verifies that javaSourceLevel overrides jdkSourceLevel if both are set. Warning is also logged
*/
@Test
public void testBothjdkSourceLevelAndjavaSourceLevel() throws Exception {

ServerConfiguration configuration = server.getServerConfiguration();
configuration.getJspEngine().setJdkSourceLevel("18");
LOG.info("New server configuration used: " + configuration);

server.setMarkToEndOfLog();
server.updateServerConfiguration(configuration);
server.restartApplication(APP_NAME);
server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), false, "CWWKT0016I:.*TestJSPWithJava17.*");

WebConversation wc = new WebConversation();
wc.setExceptionsThrownOnErrorStatus(false);

String url = JSPUtils.createHttpUrlString(server, APP_NAME, "index.jsp");
LOG.info("url: " + url);

WebRequest request = new GetMethodWebRequest(url);
WebResponse response = wc.getResponse(request);
LOG.info("Servlet response : " + response.getText());

assertEquals("Expected " + 200 + " status code was not returned!",
200, response.getResponseCode());
assertTrue("The response did not contain: success", response.getText().contains("success-text-block"));
assertTrue("The response did not contain: success", response.getText().contains("success-pattern-matching"));
}
}
Loading