From 5c2db95c7683eaca6039d120264ab5f9ced68546 Mon Sep 17 00:00:00 2001 From: Greg Watts Date: Tue, 6 Aug 2024 22:47:59 -0500 Subject: [PATCH] Add Java 23 test source --- .github/workflows/CI.yml | 6 +- .../scripts/ClassVersionChecker.java | 1 + .../.gitignore | 5 ++ io.openliberty.java.internal_fat_23/README.md | 48 ++++++++++ .../build.gradle | 57 ++++++++++++ .../run/jvm.options | 5 ++ .../run/server.env | 2 + .../io/openliberty/java/internal/TestApp.java | 20 +++++ .../java/internal/TestService.java | 90 +++++++++++++++++++ .../java/internal/package-info.java | 13 +++ .../src/main/java/module-info.java | 17 ++++ .../src/main/liberty/config/server.xml | 6 ++ settings.gradle | 1 + 13 files changed, 268 insertions(+), 3 deletions(-) create mode 100644 io.openliberty.java.internal_fat_23/.gitignore create mode 100644 io.openliberty.java.internal_fat_23/README.md create mode 100644 io.openliberty.java.internal_fat_23/build.gradle create mode 100644 io.openliberty.java.internal_fat_23/run/jvm.options create mode 100644 io.openliberty.java.internal_fat_23/run/server.env create mode 100644 io.openliberty.java.internal_fat_23/src/main/java/io/openliberty/java/internal/TestApp.java create mode 100644 io.openliberty.java.internal_fat_23/src/main/java/io/openliberty/java/internal/TestService.java create mode 100644 io.openliberty.java.internal_fat_23/src/main/java/io/openliberty/java/internal/package-info.java create mode 100644 io.openliberty.java.internal_fat_23/src/main/java/module-info.java create mode 100644 io.openliberty.java.internal_fat_23/src/main/liberty/config/server.xml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 342963b..7f30859 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -13,7 +13,7 @@ jobs: build: strategy: matrix: - java-version: [ '17', '18', '19', '20', '21', '22' ] + java-version: [ '17', '18', '19', '20', '21', '22', '23-ea' ] runs-on: ubuntu-latest @@ -36,14 +36,14 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: java-version: ${{ matrix.java-version }} - distribution: 'oracle' + distribution: 'temurin' # This is the JDK gradle will use since gradle does not always support the -ea version - name: Set up JDK 17 uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: java-version: '17' - distribution: 'oracle' + distribution: 'temurin' cache: gradle - name: Toolchain debug diff --git a/.github/workflows/scripts/ClassVersionChecker.java b/.github/workflows/scripts/ClassVersionChecker.java index 5ead5ee..68339db 100755 --- a/.github/workflows/scripts/ClassVersionChecker.java +++ b/.github/workflows/scripts/ClassVersionChecker.java @@ -34,6 +34,7 @@ public static void main(String[] args) throws IOException { majorCodeMap.put("20", 64); majorCodeMap.put("21", 65); majorCodeMap.put("22", 66); + majorCodeMap.put("23", 67); String filename = args[0]; int expected = majorCodeMap.get(args[1]); diff --git a/io.openliberty.java.internal_fat_23/.gitignore b/io.openliberty.java.internal_fat_23/.gitignore new file mode 100644 index 0000000..b402fb7 --- /dev/null +++ b/io.openliberty.java.internal_fat_23/.gitignore @@ -0,0 +1,5 @@ +.gradle/ +/bin/ +/build/ +/generated/ +/wlp diff --git a/io.openliberty.java.internal_fat_23/README.md b/io.openliberty.java.internal_fat_23/README.md new file mode 100644 index 0000000..a5f1ce3 --- /dev/null +++ b/io.openliberty.java.internal_fat_23/README.md @@ -0,0 +1,48 @@ +# Repo for quick testing of Liberty apps +Especially useful for new Java versions + + +### For versions of Java that already have gradle support +To build the WAR file locally, from the root directory of the open-liberty-misc repository run: + +``` +./gradlew io.openliberty.java.internal_fat_23:build +``` + + +### For versions of Java that do not have gradle support yet +Make the following updates in the following files (example given here as if you were working with pre-gradle support for Java 23): + +- In **build.gradle**, set: + +``` + languageVersion = JavaLanguageVersion.of(23) +``` + +- And then set the environment variable JDK23 to your Java 23 JDK home, for example: + +``` +(Mac) export JDK23="/path/to/your/jdk23/home" +(Unix) JDK23="/path/to/your/jdk23/home" +(Win DOS) set JDK23="C:\path\to\your\jdk23\home" +(Win PS) $env:JDK23="C:\path\to\your\jdk23\home" +``` + +- To build the WAR file locally, from the root directory of the open-liberty-misc repository run: + +``` +./gradlew io.openliberty.java.internal_fat_23:build -P"org.gradle.java.installations.fromEnv=JDK23" +``` +where **JDK23** is a system environment variable that reflects the location of your Java 23 JDK to use to compile the source (see last step). + + +### When moving to a new release of Java +- **build.gradle** + +``` + appUrl = 'http://localhost:9080/io.openliberty.java.internal_fat_23/' + + +``` + +Then add new code to **TestServices.java** either directly or via another class and make sure **TestApp.java** is in the same directory. diff --git a/io.openliberty.java.internal_fat_23/build.gradle b/io.openliberty.java.internal_fat_23/build.gradle new file mode 100644 index 0000000..d1165fe --- /dev/null +++ b/io.openliberty.java.internal_fat_23/build.gradle @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +// To create this WAR file (ex: ./gradlew build...) for newer versions of Java (typically early access ones) before gradle supports it +// See the README.md file + +apply plugin: 'war' + +description = "Basic Liberty repo" + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +compileJava { + doFirst { + options.compilerArgs = [ + '--module-path', classpath.asPath, + '--enable-preview' + ] + classpath = files() + options.warnings = true + options.deprecation = true + options.debug = true + options.incremental = false + } +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(23) + } +} + +repositories { + mavenCentral() +} + +dependencies { + compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1.1' + compileOnly group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1' + compileOnly group: 'javax.enterprise', name: 'cdi-api', version: '2.0' +} + +// This is the URL the test application will be available at +ext { + appUrl = 'http://localhost:9080/io.openliberty.java.internal_fat_23/' +} diff --git a/io.openliberty.java.internal_fat_23/run/jvm.options b/io.openliberty.java.internal_fat_23/run/jvm.options new file mode 100644 index 0000000..68494ad --- /dev/null +++ b/io.openliberty.java.internal_fat_23/run/jvm.options @@ -0,0 +1,5 @@ +# Enable Java preview features +--enable-preview + +# Enable Java incubator modules +--add-modules=jdk.incubator.foreign diff --git a/io.openliberty.java.internal_fat_23/run/server.env b/io.openliberty.java.internal_fat_23/run/server.env new file mode 100644 index 0000000..8f10574 --- /dev/null +++ b/io.openliberty.java.internal_fat_23/run/server.env @@ -0,0 +1,2 @@ +# Need to update the JAVA_HOME environment variable to point to your Java 23 JDK +JAVA_HOME=/jdk/temurin/jdk23 \ No newline at end of file diff --git a/io.openliberty.java.internal_fat_23/src/main/java/io/openliberty/java/internal/TestApp.java b/io.openliberty.java.internal_fat_23/src/main/java/io/openliberty/java/internal/TestApp.java new file mode 100644 index 0000000..893d969 --- /dev/null +++ b/io.openliberty.java.internal_fat_23/src/main/java/io/openliberty/java/internal/TestApp.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.java.internal; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("/") +public class TestApp extends Application { +} diff --git a/io.openliberty.java.internal_fat_23/src/main/java/io/openliberty/java/internal/TestService.java b/io.openliberty.java.internal_fat_23/src/main/java/io/openliberty/java/internal/TestService.java new file mode 100644 index 0000000..4487694 --- /dev/null +++ b/io.openliberty.java.internal_fat_23/src/main/java/io/openliberty/java/internal/TestService.java @@ -0,0 +1,90 @@ +/* Copyright (c) 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.java.internal; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Arrays; + +import javax.enterprise.context.ApplicationScoped; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +@Path("/") +@ApplicationScoped +public class TestService { + + private StringWriter sw = new StringWriter(); + + @GET + public String test() { + try { + log(">>> ENTER"); + doTest(); + log("<<< EXIT SUCCESSFUL"); + } catch (Exception e) { + e.printStackTrace(System.out); + e.printStackTrace(new PrintWriter(sw)); + log("<<< EXIT FAILED"); + } + String result = sw.toString(); + sw = new StringWriter(); + return result; + } + + + private void doTest() throws Exception { + log("Beginning Java 23 testing"); + + double f = Math.random()/Math.nextDown(1.0); + int milesRun = (int)(0 * (1.0 - f) + 101*f); // Random integer between 0 and 100 + String comment = eval(milesRun); + log(comment); + + if (comment == null || !comment.toLowerCase().contains("you")) { + log("Failed testing"); + throw new Exception("Comment did not contain the string \"you\"!. It was: " + comment); + } + + log("Goodbye testing"); + } + + /** + * Primitive Types in Patterns, instanceof, and switch (Preview) : JEP 455 -> https://openjdk.org/jeps/455 + * + * @param miles + * @return + */ + private static String eval(int miles) { + return switch (miles) { + case 0 -> "Are you Still sleeping?"; + case 1 -> "You have a long ways to go..."; + case 2 -> "Have you warmed up yet?"; + case int i when i >= 3 && i < 8 -> "Feeling it, aren't you?"; + case int i when i >= 8 && i < 13 -> "Pacing yourself"; + case 13 -> "You are halfway!"; + case int i when i >= 14 && i < 20 -> "Your legs are burning"; + case int i when i >= 20 && i < 26 -> "You're almost there!"; + case 26 -> "You are done!"; + case int i when i > 26 -> "Ultra marathon runner, you are!"; + case int i -> "Huh? Don't know what to do with value: " + i; // default + }; + } + + + public void log(String msg) { + System.out.println(msg); + sw.append(msg); + sw.append("
"); + } +} diff --git a/io.openliberty.java.internal_fat_23/src/main/java/io/openliberty/java/internal/package-info.java b/io.openliberty.java.internal_fat_23/src/main/java/io/openliberty/java/internal/package-info.java new file mode 100644 index 0000000..5b12d4e --- /dev/null +++ b/io.openliberty.java.internal_fat_23/src/main/java/io/openliberty/java/internal/package-info.java @@ -0,0 +1,13 @@ +/******************************************************************************* + * Copyright (c) 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.java.internal; diff --git a/io.openliberty.java.internal_fat_23/src/main/java/module-info.java b/io.openliberty.java.internal_fat_23/src/main/java/module-info.java new file mode 100644 index 0000000..a30b750 --- /dev/null +++ b/io.openliberty.java.internal_fat_23/src/main/java/module-info.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +open module io.openliberty.java.internal.basic_app { + + requires java.ws.rs; + +} diff --git a/io.openliberty.java.internal_fat_23/src/main/liberty/config/server.xml b/io.openliberty.java.internal_fat_23/src/main/liberty/config/server.xml new file mode 100644 index 0000000..269f129 --- /dev/null +++ b/io.openliberty.java.internal_fat_23/src/main/liberty/config/server.xml @@ -0,0 +1,6 @@ + + + servlet-4.0 + jaxrs-2.1 + + diff --git a/settings.gradle b/settings.gradle index 9490384..7b26ca9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -18,3 +18,4 @@ include 'io.openliberty.java.internal_fat_19' include 'io.openliberty.java.internal_fat_20' include 'io.openliberty.java.internal_fat_21' include 'io.openliberty.java.internal_fat_22' +include 'io.openliberty.java.internal_fat_23'