Skip to content

Commit beb393f

Browse files
authored
Merge pull request #37 from gjwatts/add-java-23-specific-test-src
Add Java 23 test source
2 parents 15ae778 + 5c2db95 commit beb393f

File tree

13 files changed

+268
-3
lines changed

13 files changed

+268
-3
lines changed

.github/workflows/CI.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
build:
1414
strategy:
1515
matrix:
16-
java-version: [ '17', '18', '19', '20', '21', '22' ]
16+
java-version: [ '17', '18', '19', '20', '21', '22', '23-ea' ]
1717

1818
runs-on: ubuntu-latest
1919

@@ -36,14 +36,14 @@ jobs:
3636
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
3737
with:
3838
java-version: ${{ matrix.java-version }}
39-
distribution: 'oracle'
39+
distribution: 'temurin'
4040

4141
# This is the JDK gradle will use since gradle does not always support the -ea version
4242
- name: Set up JDK 17
4343
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
4444
with:
4545
java-version: '17'
46-
distribution: 'oracle'
46+
distribution: 'temurin'
4747
cache: gradle
4848

4949
- name: Toolchain debug

.github/workflows/scripts/ClassVersionChecker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public static void main(String[] args) throws IOException {
3434
majorCodeMap.put("20", 64);
3535
majorCodeMap.put("21", 65);
3636
majorCodeMap.put("22", 66);
37+
majorCodeMap.put("23", 67);
3738

3839
String filename = args[0];
3940
int expected = majorCodeMap.get(args[1]);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.gradle/
2+
/bin/
3+
/build/
4+
/generated/
5+
/wlp
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Repo for quick testing of Liberty apps
2+
Especially useful for new Java versions
3+
4+
5+
### For versions of Java that already have gradle support
6+
To build the WAR file locally, from the root directory of the open-liberty-misc repository run:
7+
8+
```
9+
./gradlew io.openliberty.java.internal_fat_23:build
10+
```
11+
12+
13+
### For versions of Java that do not have gradle support yet
14+
Make the following updates in the following files (example given here as if you were working with pre-gradle support for Java 23):
15+
16+
- In **build.gradle**, set:
17+
18+
```
19+
languageVersion = JavaLanguageVersion.of(23)
20+
```
21+
22+
- And then set the environment variable JDK23 to your Java 23 JDK home, for example:
23+
24+
```
25+
(Mac) export JDK23="/path/to/your/jdk23/home"
26+
(Unix) JDK23="/path/to/your/jdk23/home"
27+
(Win DOS) set JDK23="C:\path\to\your\jdk23\home"
28+
(Win PS) $env:JDK23="C:\path\to\your\jdk23\home"
29+
```
30+
31+
- To build the WAR file locally, from the root directory of the open-liberty-misc repository run:
32+
33+
```
34+
./gradlew io.openliberty.java.internal_fat_23:build -P"org.gradle.java.installations.fromEnv=JDK23"
35+
```
36+
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).
37+
38+
39+
### When moving to a new release of Java
40+
- **build.gradle**
41+
42+
```
43+
appUrl = 'http://localhost:9080/io.openliberty.java.internal_fat_23/'
44+
45+
<Make sure to add any new dependencies or update existing ones to the proper levels>
46+
```
47+
48+
Then add new code to **TestServices.java** either directly or via another class and make sure **TestApp.java** is in the same directory.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* IBM Corporation - initial API and implementation
12+
*******************************************************************************/
13+
// To create this WAR file (ex: ./gradlew build...) for newer versions of Java (typically early access ones) before gradle supports it
14+
// See the README.md file
15+
16+
apply plugin: 'war'
17+
18+
description = "Basic Liberty repo"
19+
20+
tasks.withType(JavaCompile) {
21+
options.encoding = 'UTF-8'
22+
}
23+
24+
compileJava {
25+
doFirst {
26+
options.compilerArgs = [
27+
'--module-path', classpath.asPath,
28+
'--enable-preview'
29+
]
30+
classpath = files()
31+
options.warnings = true
32+
options.deprecation = true
33+
options.debug = true
34+
options.incremental = false
35+
}
36+
}
37+
38+
java {
39+
toolchain {
40+
languageVersion = JavaLanguageVersion.of(23)
41+
}
42+
}
43+
44+
repositories {
45+
mavenCentral()
46+
}
47+
48+
dependencies {
49+
compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1.1'
50+
compileOnly group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
51+
compileOnly group: 'javax.enterprise', name: 'cdi-api', version: '2.0'
52+
}
53+
54+
// This is the URL the test application will be available at
55+
ext {
56+
appUrl = 'http://localhost:9080/io.openliberty.java.internal_fat_23/'
57+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Enable Java preview features
2+
--enable-preview
3+
4+
# Enable Java incubator modules
5+
--add-modules=jdk.incubator.foreign
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Need to update the JAVA_HOME environment variable to point to your Java 23 JDK
2+
JAVA_HOME=/jdk/temurin/jdk23
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* IBM Corporation - initial API and implementation
12+
*******************************************************************************/
13+
package io.openliberty.java.internal;
14+
15+
import javax.ws.rs.ApplicationPath;
16+
import javax.ws.rs.core.Application;
17+
18+
@ApplicationPath("/")
19+
public class TestApp extends Application {
20+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/* Copyright (c) 2024 IBM Corporation and others.
2+
* All rights reserved. This program and the accompanying materials
3+
* are made available under the terms of the Eclipse Public License 2.0
4+
* which accompanies this distribution, and is available at
5+
* http://www.eclipse.org/legal/epl-2.0/
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* IBM Corporation - initial API and implementation
11+
*******************************************************************************/
12+
package io.openliberty.java.internal;
13+
14+
import java.io.PrintWriter;
15+
import java.io.StringWriter;
16+
import java.util.ArrayList;
17+
import java.util.Arrays;
18+
19+
import javax.enterprise.context.ApplicationScoped;
20+
import javax.ws.rs.GET;
21+
import javax.ws.rs.Path;
22+
23+
@Path("/")
24+
@ApplicationScoped
25+
public class TestService {
26+
27+
private StringWriter sw = new StringWriter();
28+
29+
@GET
30+
public String test() {
31+
try {
32+
log(">>> ENTER");
33+
doTest();
34+
log("<<< EXIT SUCCESSFUL");
35+
} catch (Exception e) {
36+
e.printStackTrace(System.out);
37+
e.printStackTrace(new PrintWriter(sw));
38+
log("<<< EXIT FAILED");
39+
}
40+
String result = sw.toString();
41+
sw = new StringWriter();
42+
return result;
43+
}
44+
45+
46+
private void doTest() throws Exception {
47+
log("Beginning Java 23 testing");
48+
49+
double f = Math.random()/Math.nextDown(1.0);
50+
int milesRun = (int)(0 * (1.0 - f) + 101*f); // Random integer between 0 and 100
51+
String comment = eval(milesRun);
52+
log(comment);
53+
54+
if (comment == null || !comment.toLowerCase().contains("you")) {
55+
log("Failed testing");
56+
throw new Exception("Comment did not contain the string \"you\"!. It was: " + comment);
57+
}
58+
59+
log("Goodbye testing");
60+
}
61+
62+
/**
63+
* Primitive Types in Patterns, instanceof, and switch (Preview) : JEP 455 -> https://openjdk.org/jeps/455
64+
*
65+
* @param miles
66+
* @return
67+
*/
68+
private static String eval(int miles) {
69+
return switch (miles) {
70+
case 0 -> "Are you Still sleeping?";
71+
case 1 -> "You have a long ways to go...";
72+
case 2 -> "Have you warmed up yet?";
73+
case int i when i >= 3 && i < 8 -> "Feeling it, aren't you?";
74+
case int i when i >= 8 && i < 13 -> "Pacing yourself";
75+
case 13 -> "You are halfway!";
76+
case int i when i >= 14 && i < 20 -> "Your legs are burning";
77+
case int i when i >= 20 && i < 26 -> "You're almost there!";
78+
case 26 -> "You are done!";
79+
case int i when i > 26 -> "Ultra marathon runner, you are!";
80+
case int i -> "Huh? Don't know what to do with value: " + i; // default
81+
};
82+
}
83+
84+
85+
public void log(String msg) {
86+
System.out.println(msg);
87+
sw.append(msg);
88+
sw.append("<br/>");
89+
}
90+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* IBM Corporation - initial API and implementation
12+
*******************************************************************************/
13+
package io.openliberty.java.internal;

0 commit comments

Comments
 (0)