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

Add Java 22 test source #16

Merged
merged 2 commits into from
Feb 2, 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
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Ignore gradle files and folders at the root
/.gradle/
/gradle/
/gradlew
/gradlew.bat

# Ignore bin folders at the root of each project
/*/bin/
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
14 changes: 7 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -202,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
5 changes: 5 additions & 0 deletions io.openliberty.java.internal_fat_22/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.gradle/
/bin/
/build/
/generated/
/wlp
48 changes: 48 additions & 0 deletions io.openliberty.java.internal_fat_22/README.md
Original file line number Diff line number Diff line change
@@ -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_22:build
```


### For versions of Java that do not have gradle support yet
gjwatts marked this conversation as resolved.
Show resolved Hide resolved
Make the following updates in the following files (example given here as if you were working with pre-gradle support for Java 22):

- In **build.gradle**, set:

```
languageVersion = JavaLanguageVersion.of(22)
```

- And then set the environment variable JDK22 to your Java 22 JDK home, for example:

```
(Mac) export JDK22="/path/to/your/jdk22/home"
(Unix) JDK22="/path/to/your/jdk22/home"
(Win DOS) set JDK22="C:\path\to\your\jdk22\home"
(Win PS) $env:JDK22="C:\path\to\your\jdk22\home"
```

- To build the WAR file locally, from the root directory of the open-liberty-misc repository run:

```
./gradlew io.openliberty.java.internal_fat_22:build -P"org.gradle.java.installations.fromEnv=JDK22"
```
where **JDK22** is a system environment variable that reflects the location of your Java 22 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_22/'

<Make sure to add any new dependencies or update existing ones to the proper levels>
```

Then add new code to **TestServices.java** either directly or via another class and make sure **TestApp.java** is in the same directory.
57 changes: 57 additions & 0 deletions io.openliberty.java.internal_fat_22/build.gradle
Original file line number Diff line number Diff line change
@@ -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(22)
}
}

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_22/'
}
5 changes: 5 additions & 0 deletions io.openliberty.java.internal_fat_22/run/jvm.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Enable Java preview features
--enable-preview

# Enable Java incubator modules
--add-modules=jdk.incubator.foreign
2 changes: 2 additions & 0 deletions io.openliberty.java.internal_fat_22/run/server.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Need to update the JAVA_HOME environment variable to point to your Java 22 JDK
JAVA_HOME=/jdk/temurin/jdk22
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*******************************************************************************
* 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 22 testing");
ArrayList<String> favoriteShows = new ArrayList<String>(Arrays.asList("Outpost","Grimm","Community","Scrubs","Castle","Star Trek"));
int count = countElements(favoriteShows);

if (count != favoriteShows.size()) {
log("Failed testing");
throw new Exception("Number of elements counted in ArrayList (" + count + ") is not equal to the size (" + favoriteShows.size() + ")!");
}

log("Goodbye testing");
}

/**
* Demonstrate unnamed variables : JEP 456 -> https://openjdk.org/jeps/456
*
* @param shows
* @return
*/
public int countElements(ArrayList<String> list) {
int total = 0;
for (var _ : list) { // Use _ for unnamed variable
total++;
}
return total;
}


public void log(String msg) {
System.out.println(msg);
sw.append(msg);
sw.append("<br/>");
}
}
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 17 additions & 0 deletions io.openliberty.java.internal_fat_22/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<server>
<featureManager>
<feature>servlet-4.0</feature>
<feature>jaxrs-2.1</feature>
</featureManager>
</server>
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 IBM Corporation and others.
* Copyright (c) 2021, 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
Expand All @@ -17,3 +17,4 @@ include 'io.openliberty.java.internal_fat_18'
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'