Skip to content

Commit fe15128

Browse files
committed
Add Java 22 test src
1 parent 7c69aa8 commit fe15128

File tree

12 files changed

+347
-3
lines changed

12 files changed

+347
-3
lines changed

gradle/wrapper/gradle-wrapper.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
#distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
5+
#distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.gradle/
2+
/bin/
3+
/build/
4+
/generated/
5+
/gradle/
6+
/wlp
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Repo for quick testing of Liberty apps
2+
Especially useful for new Java versions
3+
4+
### For versions of Java that already have gradle support
5+
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_22:build
10+
```
11+
12+
To build+run locally, this currently requires some manual effort:
13+
* Note, the **build.gradle** file is configured to look for a Liberty install under `/wlp`. You might need to change it to point it to your local test Liberty install instead.
14+
* Copy the `jvm.options` file and the contents of the `server.env` file from the project's `run` directory and add them to your `/wlp/usr/servers/io.openliberty.java.internal_fat_22Server/server.env` file (or equivalent location).
15+
* Change to the root directory of this local `io.openliberty.java.internal_fat_22` repository and run:
16+
17+
```
18+
./gradlew io.openliberty.java.internal_fat_22:start
19+
```
20+
21+
---
22+
23+
### For versions of Java that do not have gradle support yet
24+
Make the following updates in the following files (example given here as if you were working with pre-gradle support for Java 22):
25+
26+
- In **build.gradle**, set:
27+
28+
```
29+
languageVersion = JavaLanguageVersion.of(22)
30+
```
31+
32+
- And then set the environment variable JDK22 to your Java 22 JDK home, for example:
33+
34+
```
35+
(Mac) export JDK22="/path/to/your/jdk22/home"
36+
(Unix) JDK22="/path/to/your/jdk22/home"
37+
(Win DOS) set JDK22="C:\path\to\your\jdk22\home"
38+
(Win PS) $env:JDK22="C:\path\to\your\jdk22\home"
39+
```
40+
41+
- To build the WAR file locally, from the root directory of the open-liberty-misc repository run:
42+
43+
```
44+
./gradlew io.openliberty.java.internal_fat_22:build -P"org.gradle.java.installations.fromEnv=JDK22"
45+
```
46+
where **JDK22** is a system environment variable that reflects the location of your Java XX JDK you wish the source to be complied at (see last step).
47+
48+
49+
To build+run locally, this currently requires some manual effort:
50+
* Note, the **build.gradle** file is configured to look for a Liberty install under `/wlp`. You might need to change it to point it to your local test Liberty install instead.
51+
* Copy the `jvm.options` file and the contents of the `server.env` file from the project's `run` directory and add them to your `/wlp/usr/servers/io.openliberty.java.internal_fat_22Server/server.env` file (or equivalent location).
52+
* Change to the root directory of this local `io.openliberty.java.internal_fat_22` repository and run:
53+
54+
```
55+
./gradlew io.openliberty.java.internal_fat_22:start -P"org.gradle.java.installations.fromEnv=JDK22"
56+
```
57+
where **JDK22** is a system environment variable that reflects the location of your Java XX JDK you wish the source to be complied at (see last step).
58+
59+
60+
If testing with the `io.openliberty.java.internal_fat` FAT from OpenLiberty, copy the file gradle builds (in build/libs) `io.openliberty.java.internal_fat_22.war` to the `io.openliberty.java.internal_fat/publish/servers/java22-server/apps` directory.
61+
62+
---
63+
64+
### When moving to a new release of Java
65+
66+
Here are the locations where you might want to update up the Java release number to the current Java version
67+
68+
- **org.eclipse.wst.common.component** (in the `.settings` directory)
69+
70+
```
71+
<wb-module deploy-name="io.openliberty.java.internal_fat_22">
72+
<property name="context-root" value="io.openliberty.java.internal_fat_22"/>
73+
```
74+
75+
- **build.gradle**
76+
77+
```
78+
appUrl = 'http://localhost:9080/io.openliberty.java.internal_fat_22/'
79+
80+
<Make sure to add any new dependencies or update existing ones to the proper levels>
81+
```
82+
83+
- **gradle-wrapper.properties** (might as well bump up to the latest supported version of gradle)
84+
85+
```
86+
distributionUrl=https\://services.gradle.org/distributions/gradle-X.Y-bin.zip
87+
```
88+
89+
Then add new code to **TestServices.java** either directly or via another class and make sure **TestApp.java** is in the same directory as it.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
// Change the installDir setting if your Liberty is located outside of /wlp
16+
17+
apply plugin: 'war'
18+
19+
description = "Basic Liberty repo"
20+
21+
tasks.withType(JavaCompile) {
22+
options.encoding = 'UTF-8'
23+
}
24+
25+
compileJava {
26+
//inputs.property("moduleName", moduleName)
27+
doFirst {
28+
options.compilerArgs = [
29+
'--module-path', classpath.asPath,
30+
'--enable-preview'
31+
]
32+
classpath = files()
33+
options.warnings = true
34+
options.deprecation = true
35+
options.debug = true
36+
options.incremental = false
37+
}
38+
}
39+
test {
40+
useJUnitPlatform()
41+
}
42+
43+
java {
44+
toolchain {
45+
languageVersion = JavaLanguageVersion.of(22)
46+
}
47+
}
48+
49+
buildscript {
50+
repositories {
51+
mavenCentral()
52+
}
53+
dependencies {
54+
classpath 'io.openliberty.tools:liberty-gradle-plugin:3.0'
55+
}
56+
}
57+
58+
repositories {
59+
mavenCentral()
60+
}
61+
62+
configurations {
63+
serverLibs
64+
}
65+
66+
dependencies {
67+
compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1.1'
68+
// compileOnly group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
69+
compileOnly group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
70+
compileOnly group: 'javax.enterprise', name: 'cdi-api', version: '2.0'
71+
// compileOnly group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
72+
// compileOnly group: 'javax.transaction', name: 'javax.transaction-api', version: '1.3'
73+
// libertyRuntime group: 'io.openliberty', name: 'openliberty-runtime', version: '22.0.0.12'
74+
// serverLibs group: 'org.apache.derby', name: 'derby', version: '10.14.2.0' // '10.15.1.3'
75+
}
76+
77+
ext {
78+
appUrl = 'http://localhost:9080/io.openliberty.java.internal_fat_22/'
79+
}
80+
81+
task copyServerLibs(type: Copy) {
82+
from configurations.serverLibs
83+
// Default location of local Liberty server
84+
into "/wlp/usr/servers/${project.name}Server/lib"
85+
}
86+
87+
// Not currently working, must manually handle
88+
tasks.register('copyEnvFiles', Copy) {
89+
println "Start of copyEnvFiles"
90+
from file('run/jvm.options')
91+
// Default location of local Liberty server
92+
into new File("/wlp/usr/servers/${project.name}Server")
93+
from file('run/server.env')
94+
// Default location of local Liberty server
95+
into new File("/wlp/usr/servers/${project.name}Server")
96+
println "End of copyEnvFiles"
97+
}
98+
99+
task openBrowser {
100+
description = "Open browser to ${appUrl}"
101+
doLast {
102+
java.awt.Desktop.desktop.browse "${appUrl}".toURI()
103+
}
104+
}
105+
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 22 JDK
2+
JAVA_HOME=/jdk/hotspot/jdk22
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: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 java.io.PrintWriter;
16+
import java.io.StringWriter;
17+
import java.util.ArrayList;
18+
import java.util.Arrays;
19+
20+
import javax.enterprise.context.ApplicationScoped;
21+
import javax.ws.rs.GET;
22+
import javax.ws.rs.Path;
23+
24+
@Path("/")
25+
@ApplicationScoped
26+
public class TestService {
27+
28+
private StringWriter sw = new StringWriter();
29+
30+
@GET
31+
public String test() {
32+
try {
33+
log(">>> ENTER");
34+
doTest();
35+
log("<<< EXIT SUCCESSFUL");
36+
} catch (Exception e) {
37+
e.printStackTrace(System.out);
38+
e.printStackTrace(new PrintWriter(sw));
39+
log("<<< EXIT FAILED");
40+
}
41+
String result = sw.toString();
42+
sw = new StringWriter();
43+
return result;
44+
}
45+
46+
47+
private void doTest() throws Exception {
48+
log("Beginning Java 22 testing");
49+
ArrayList<String> favoriteShows = new ArrayList<String>(Arrays.asList("Outpost","Grimm","Community","Scrubs","Castle","Star Trek"));
50+
int count = countElements(favoriteShows);
51+
52+
if (count != favoriteShows.size()) {
53+
log("Failed testing");
54+
throw new Exception("Number of elements counted in ArrayList (" + count + ") is not equal to the size (" + favoriteShows.size() + ")!");
55+
}
56+
57+
log("Goodbye testing");
58+
}
59+
60+
/**
61+
* Demonstrate unnamed variables : JEP 456 -> https://openjdk.org/jeps/456
62+
*
63+
* @param shows
64+
* @return
65+
*/
66+
public int countElements(ArrayList<String> list) {
67+
int total = 0;
68+
for (var _ : list) { // Use _ for unnamed variable
69+
total++;
70+
}
71+
return total;
72+
}
73+
74+
75+
public void log(String msg) {
76+
System.out.println(msg);
77+
sw.append(msg);
78+
sw.append("<br/>");
79+
}
80+
}
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;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
open module io.openliberty.java.internal.basic_app {
14+
15+
requires java.ws.rs;
16+
17+
}

0 commit comments

Comments
 (0)