Skip to content

Commit

Permalink
Enable support for testing on Java 21.
Browse files Browse the repository at this point in the history
Signed-off-by: James R. Perkins <[email protected]>
  • Loading branch information
jamezp committed Feb 1, 2024
1 parent f37a562 commit 5023201
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest ]
java: ['11', '17']
java: ['11', '17', '21']

steps:
- uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -392,15 +391,16 @@ protected String getContent(String url) throws Exception {
}

protected Process startServer(Path dir, String fileName, String... args) throws Exception {
final List<String> serverArgs = List.of(args);
List<String> cmd = new ArrayList<>();
cmd.add(getJavaCommand());
cmd.addAll(getJvmArgs());
cmd.addAll(getJvmArgs(serverArgs.contains("-secmgr")));
// On windows, to remove when Upgraded to WILDFLY 26.1.1 that should contain XNIO 3.8.7
// https://issues.redhat.com/browse/XNIO-404
cmd.add("-Djdk.io.File.enableADS=true");
cmd.add("-jar");
cmd.add(dir.resolve("target").resolve(fileName == null ? TEST_FILE : fileName).toAbsolutePath().toString());
cmd.addAll(Arrays.asList(args));
cmd.addAll(serverArgs);
final Path out = TestEnvironment.createTempPath("logs", getClass().getName() + "-process.txt");
final Path parent = out.getParent();
if (parent != null && Files.notExists(parent)) {
Expand Down Expand Up @@ -515,7 +515,7 @@ private static String getJavaCommand() {
return cmd;
}

private static Collection<String> getJvmArgs() {
private static Collection<String> getJvmArgs(final boolean securityManager) {
final Collection<String> result = new ArrayList<>();
final String defaultArgs = System.getProperty("test.jvm.args");
if (defaultArgs != null) {
Expand All @@ -526,6 +526,9 @@ private static Collection<String> getJvmArgs() {
}
}
}
if (securityManager && TestEnvironment.javaVersion() >= 17) {
result.add("-Djava.security.manager=allow");
}
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ class TestEnvironment {
private static final int MGMT_PORT = getProperty("ts.mgmt.port", 9990);
private static final String TMP_DIR = System.getProperty("java.io.tmpdir", "target");
private static final boolean IS_WINDOWS;
private static final int JAVA_VERSION;

static {
final String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);
IS_WINDOWS = os.contains("win");
JAVA_VERSION = Integer.parseInt(System.getProperty("java.vm.specification.version"));
}

/**
Expand Down Expand Up @@ -107,6 +109,15 @@ static Path createTempPath(final String... paths) {
return Paths.get(TMP_DIR, paths);
}

/**
* Returns the current Java version.
*
* @return the java version
*/
static int javaVersion() {
return JAVA_VERSION;
}

private static int getProperty(final String name, final int dft) {
final String value = System.getProperty(name);
return value == null ? dft : Integer.parseInt(value);
Expand Down

0 comments on commit 5023201

Please sign in to comment.