getJavaOptions() {
- return javaOpts.asList();
- }
-
- /**
- * Adds an option which will be passed to JBoss Modules.
- *
- * Note that {@code -mp} or {@code --modulepath} is not supported. Use {@link #addModuleDir(String)} to add a module
- * directory.
- *
- *
- * @param arg the argument to add
- *
- * @return the builder
- */
- public JBossModulesCommandBuilder addModuleOption(final String arg) {
- if (arg != null) {
- if (arg.startsWith("-javaagent:")) {
- addModuleAgent = true;
- } else if ("-mp".equals(arg) || "--modulepath".equals(arg)) {
- throw MESSAGES.invalidArgument(arg, "addModuleOption");
- } else if ("-secmgr".equals(arg)) {
- throw MESSAGES.invalidArgument(arg, "setUseSecurityManager");
- }
- moduleOpts.add(arg);
- }
- return this;
- }
-
- /**
- * Adds the options which will be passed to JBoss Modules.
- *
- * Note that {@code -mp} or {@code --modulepath} is not supported. Use {@link #addModuleDirs(String...)} to add a
- * module directory.
- *
- *
- * @param args the argument to add
- *
- * @return the builder
- */
- public JBossModulesCommandBuilder addModuleOptions(final String... args) {
- if (args != null) {
- for (String arg : args) {
- addModuleOption(arg);
- }
- }
- return this;
- }
-
- /**
- * Adds the options which will be passed to JBoss Modules.
- *
- * Note that {@code -mp} or {@code --modulepath} is not supported. Use {@link #addModuleDirs(Iterable)} to add a
- * module directory.
- *
- *
- * @param args the argument to add
- *
- * @return the builder
- */
- public JBossModulesCommandBuilder addModuleOptions(final Iterable args) {
- if (args != null) {
- for (String arg : args) {
- addModuleOption(arg);
- }
- }
- return this;
- }
-
- /**
- * Clears the current module options and adds the options which will be passed to JBoss Modules.
- *
- * Note that {@code -mp} or {@code --modulepath} is not supported. Use {@link #addModuleDirs(String...)} to add a
- * module directory.
- *
- *
- * @param args the argument to use
- *
- * @return the builder
- */
- public JBossModulesCommandBuilder setModuleOptions(final String... args) {
- moduleOpts.clear();
- addModuleOptions(args);
- return this;
- }
-
- /**
- * Clears the current module options and adds the options which will be passed to JBoss Modules.
- *
- * Note that {@code -mp} or {@code --modulepath} is not supported. Use {@link #addModuleDirs(Iterable)} to add a
- * module directory.
- *
- *
- * @param args the argument to use
- *
- * @return the builder
- */
- public JBossModulesCommandBuilder setModuleOptions(final Iterable args) {
- moduleOpts.clear();
- addModuleOptions(args);
- return this;
- }
-
- /**
- * Sets the Java home where the Java executable can be found.
- *
- * @param javaHome the Java home or {@code null} to use te system property {@code java.home}
- *
- * @return the builder
- */
- public JBossModulesCommandBuilder setJavaHome(final String javaHome) {
- environment.setJvm(Jvm.of(javaHome));
- return this;
- }
-
- /**
- * Sets the Java home where the Java executable can be found.
- *
- * @param javaHome the Java home or {@code null} to use te system property {@code java.home}
- *
- * @return the builder
- */
- public JBossModulesCommandBuilder setJavaHome(final Path javaHome) {
- environment.setJvm(Jvm.of(javaHome));
- return this;
- }
-
- /**
- * Set to {@code true} to use JBoss Modules lockless mode.
- *
- * @param b {@code true} to use lockless mode
- *
- * @return the builder
- */
- public JBossModulesCommandBuilder setModulesLockless(final boolean b) {
- if (b) {
- modulesLocklessArg = "-Djboss.modules.lockless=true";
- } else {
- modulesLocklessArg = null;
- }
- return this;
- }
-
- /**
- * Set to {@code true} to gather metrics for JBoss Modules.
- *
- * @param b {@code true} to gather metrics for JBoss Modules.
- *
- * @return this builder
- */
- public JBossModulesCommandBuilder setModulesMetrics(final boolean b) {
- if (b) {
- modulesMetricsArg = "-Djboss.modules.metrics=true";
- } else {
- modulesMetricsArg = null;
- }
- return this;
- }
-
- @Override
- public List buildArguments() {
- final List cmd = new ArrayList<>();
- // Check to see if an agent was added as a module option, if so we want to add JBoss Modules as an agent.
- if (addModuleAgent) {
- cmd.add("-javaagent:" + getModulesJarName());
- }
- cmd.addAll(getJavaOptions());
- if (environment.getJvm().isModular()) {
- cmd.addAll(DEFAULT_MODULAR_VM_ARGUMENTS);
- for (final String optionalModularArgument : OPTIONAL_DEFAULT_MODULAR_VM_ARGUMENTS) {
- if (Jvm.isPackageAvailable(environment.getJvm().getPath(), optionalModularArgument)) {
- cmd.add(optionalModularArgument);
- }
- }
- }
- if (environment.getJvm().enhancedSecurityManagerAvailable()) {
- cmd.add(SECURITY_MANAGER_PROP_WITH_ALLOW_VALUE);
- }
- // Add these to JVM level system properties
- if (modulesLocklessArg != null) {
- cmd.add(modulesLocklessArg);
- }
- if (modulesMetricsArg != null) {
- cmd.add(modulesMetricsArg);
- }
- cmd.add("-jar");
- cmd.add(getModulesJarName());
- if (useSecurityManager()) {
- cmd.add(SECURITY_MANAGER_ARG);
- }
- // Add the agent argument for jboss-modules
- cmd.addAll(moduleOpts);
- cmd.add("-mp");
- cmd.add(getModulePaths());
- cmd.add(moduleName);
-
- cmd.addAll(getServerArguments());
- return cmd;
- }
-
- @Override
- public List build() {
- final List cmd = new ArrayList<>();
- cmd.add(environment.getJvm().getCommand());
- cmd.addAll(buildArguments());
- return cmd;
- }
-
- protected void setSingleServerArg(final String key, final String value) {
- serverArgs.set(key, value);
- }
-
- protected void addServerArg(final String key, final String value) {
- serverArgs.add(key, value);
- }
-
- /**
- * Returns the first argument from the server arguments.
- *
- * @param key the key to the argument
- *
- * @return the first argument or {@code null}
- */
- protected String getServerArg(final String key) {
- return serverArgs.get(key);
- }
-
- /**
- * Allows the subclass to do additional checking on whether the server argument should be added or not. In some
- * cases it may be desirable for the argument passed to be added or processed elsewhere.
- *
- * @param argument the argument to test
- *
- * @return {@code true} if the argument should be added to the server arguments, {@code false} if the argument is
- * handled by the subclass
- */
- boolean addServerArgument(final Argument argument) {
- return true;
- }
-
- static boolean isJavaSecurityManagerConfigured(final Argument argument) {
- return !ALLOW_VALUE.equals(argument.getValue()) && !DISALLOW_VALUE.equals(argument.getValue());
- }
-}
diff --git a/launcher/src/main/java/org/wildfly/core/launcher/Jvm.java b/launcher/src/main/java/org/wildfly/core/launcher/Jvm.java
deleted file mode 100644
index 0414449015c..00000000000
--- a/launcher/src/main/java/org/wildfly/core/launcher/Jvm.java
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * Copyright The WildFly Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package org.wildfly.core.launcher;
-
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
-import org.wildfly.core.launcher.logger.LauncherMessages;
-
-/**
- * Represents a JVM description.
- *
- * @author James R. Perkins
- */
-class Jvm {
- private static final String JAVA_EXE;
- private static final Path JAVA_HOME;
- private static final boolean MODULAR_JVM = true;
- private static final boolean ENHANCED_SECURITY_MANAGER = Runtime.version().feature() >= 12;
-
- static {
- String exe = "java";
- if (Environment.isWindows()) {
- exe = "java.exe";
- }
- JAVA_EXE = exe;
- final String javaHome = System.getProperty("java.home");
- JAVA_HOME = Paths.get(javaHome);
- }
-
- private static final Jvm DEFAULT = new Jvm(JAVA_HOME, MODULAR_JVM, ENHANCED_SECURITY_MANAGER);
-
- private final Path path;
- private final boolean isModular;
- private final boolean enhancedSecurityManager;
-
- private Jvm(final Path path, final boolean isModular, final boolean enhancedSecurityManager) {
- this.path = path;
- this.isModular = isModular;
- this.enhancedSecurityManager = enhancedSecurityManager;
- }
-
- /**
- * The current JVM.
- *
- * @return the current JVM
- */
- static Jvm current() {
- return DEFAULT;
- }
-
- /**
- * Creates a new JVM. If the {@code javaHome} is {@code null} the {@linkplain #current() current} JVM is returned.
- *
- * @param javaHome the path to the Java home
- *
- * @return a JVM descriptor based on the Java home path
- */
- static Jvm of(final String javaHome) {
- if (javaHome == null) {
- return DEFAULT;
- }
- return of(Paths.get(javaHome));
- }
-
- /**
- * Creates a new JVM. If the {@code javaHome} is {@code null} the {@linkplain #current() current} JVM is returned.
- *
- * @param javaHome the path to the Java home
- *
- * @return a JVM descriptor based on the Java home path
- */
- static Jvm of(final Path javaHome) {
- if (javaHome == null || javaHome.equals(JAVA_HOME)) {
- return DEFAULT;
- }
- final Path path = validateJavaHome(javaHome);
- return new Jvm(path, isModularJavaHome(path), hasEnhancedSecurityManager(javaHome));
- }
-
- /**
- * The the command which can launch this JVM.
- *
- * @return the command
- */
- public String getCommand() {
- return resolveJavaCommand(path);
- }
-
- /**
- * The path to this JVM.
- *
- * @return the path
- */
- public Path getPath() {
- return path;
- }
-
- /**
- * Indicates whether or not this is a modular JVM.
- *
- * @return {@code true} if this is a modular JVM, otherwise {@code false}
- */
- public boolean isModular() {
- return isModular;
- }
-
- /**
- * Indicates whether or not this is a modular JVM supporting special SecurityManager values like "allow", "disallow" & "default"
- *
- * @return {@code true} if this is a modular JVM with enhanced SecurityManager, otherwise {@code false}
- */
- public boolean enhancedSecurityManagerAvailable() {
- return enhancedSecurityManager;
- }
-
- private static boolean isModularJavaHome(final Path javaHome) {
- final Path jmodsDir = javaHome.resolve("jmods");
- // If the jmods directory exists we can safely assume this is a modular JDK, note even in a modular JDK this
- // may not exist.
- if (Files.isDirectory(jmodsDir)) {
- return true;
- }
- // Next check for a $JAVA_HOME/release file, for a JRE this will not exist
- final Path releaseFile = javaHome.resolve("release");
- if (Files.isReadable(releaseFile) && Files.isRegularFile(releaseFile)) {
- // Read the file and look for a JAVA_VERSION property
- try (final BufferedReader reader = Files.newBufferedReader(releaseFile, StandardCharsets.UTF_8)) {
- String line;
- while ((line = reader.readLine()) != null) {
- if (line.startsWith("JAVA_VERSION=")) {
- // Get the version value
- final int index = line.indexOf('=');
- return isModularJavaVersion(line.substring(index + 1).replace("\"", ""));
- }
- }
- } catch (IOException ignore) {
- }
- }
- // Final check is to launch a new process with some modular JVM arguments and check the exit code
- return isModular(javaHome);
- }
-
- private static boolean isModularJavaVersion(final String version) {
- if (version != null) {
- try {
- final String[] versionParts = version.split("\\.");
- if (versionParts.length == 1) {
- return Integer.parseInt(versionParts[0]) >= 9;
- } else if (versionParts.length > 1) {
- // Check the first part and if one, use the second part
- if ("1".equals(versionParts[0])) {
- return Integer.parseInt(versionParts[2]) >= 9;
- }
- return Integer.parseInt(versionParts[0]) >= 9;
- }
- } catch (Exception ignore) {
- }
- }
- return false;
- }
-
- /**
- * Checks to see if the {@code javaHome} supports special security manager tokens like "allow", "disallow" & "default"
- *
- * @param javaHome the Java Home if {@code null} an attempt to discover the Java Home will be done
- *
- * @return {@code true} if this is a modular environment
- */
- private static boolean hasEnhancedSecurityManager(final Path javaHome) {
- final List cmd = new ArrayList<>();
- cmd.add(resolveJavaCommand(javaHome));
- cmd.add("-Djava.security.manager=allow");
- cmd.add("-version");
- return checkProcessStatus(cmd);
- }
-
- static boolean isPackageAvailable(final Path javaHome, final String optionalModularArgument) {
- final List cmd = new ArrayList<>();
- cmd.add(resolveJavaCommand(javaHome));
- cmd.add(optionalModularArgument);
- cmd.add("-version");
- return checkProcessStatus(cmd);
- }
-
- /**
- * Checks to see if the {@code javaHome} is a modular JVM.
- *
- * @param javaHome the Java Home if {@code null} an attempt to discover the Java Home will be done
- *
- * @return {@code true} if this is a modular environment
- */
- private static boolean isModular(final Path javaHome) {
- final List cmd = new ArrayList<>();
- cmd.add(resolveJavaCommand(javaHome));
- cmd.add("--add-modules=java.se");
- cmd.add("-version");
- return checkProcessStatus(cmd);
- }
- /**
- * Checks the process status.
- *
- * @param cmd command to execute
- *
- * @return {@code true} if command was successful, {@code false} if process failed.
- */
- private static boolean checkProcessStatus(final List cmd) {
- boolean result;
- final ProcessBuilder builder = new ProcessBuilder(cmd);
- Process process = null;
- Path stdout = null;
- try {
- // Create a temporary file for stdout
- stdout = Files.createTempFile("stdout", ".txt");
- process = builder.redirectErrorStream(true)
- .redirectOutput(stdout.toFile()).start();
-
- if (process.waitFor(30, TimeUnit.SECONDS)) {
- result = process.exitValue() == 0;
- } else {
- result = false;
- }
- } catch (IOException | InterruptedException e) {
- result = false;
- } finally {
- if (process != null && process.isAlive()) {
- process.destroyForcibly();
- }
- if (stdout != null) {
- try {
- if (containsWarning(stdout)) {
- result = false;
- }
- Files.deleteIfExists(stdout);
- } catch (IOException ignore) {
- }
- }
- }
- return result;
- }
-
- private static boolean containsWarning(final Path logFile) throws IOException {
- String line;
- try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(logFile.toFile())))) {
- while ((line = br.readLine()) != null) {
- if (line.startsWith("WARNING:")) {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Returns the Java executable command.
- *
- * @param javaHome the java home directory or {@code null} to use the default
- *
- * @return the java command to use
- */
- private static String resolveJavaCommand(final Path javaHome) {
- final String exe;
- if (javaHome == null) {
- exe = "java";
- } else {
- exe = javaHome.resolve("bin").resolve("java").toString();
- }
- if (exe.contains(" ")) {
- return "\"" + exe + "\"";
- }
- return exe;
- }
-
- private static Path validateJavaHome(final Path javaHome) {
- if (javaHome == null || Files.notExists(javaHome)) {
- throw LauncherMessages.MESSAGES.pathDoesNotExist(javaHome);
- }
- if (!Files.isDirectory(javaHome)) {
- throw LauncherMessages.MESSAGES.invalidDirectory(javaHome);
- }
- final Path result = javaHome.toAbsolutePath().normalize();
- final Path exe = result.resolve("bin").resolve(JAVA_EXE);
- if (Files.notExists(exe)) {
- final int count = exe.getNameCount();
- throw LauncherMessages.MESSAGES.invalidDirectory(exe.subpath(count - 2, count).toString(), javaHome);
- }
- return result;
- }
-}
diff --git a/launcher/src/main/java/org/wildfly/core/launcher/Launcher.java b/launcher/src/main/java/org/wildfly/core/launcher/Launcher.java
deleted file mode 100644
index 0ffa70051af..00000000000
--- a/launcher/src/main/java/org/wildfly/core/launcher/Launcher.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright The WildFly Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package org.wildfly.core.launcher;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.ProcessBuilder.Redirect;
-import java.nio.file.Path;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Builds a {@link java.lang.Process process} to launch a standalone or domain server based on the {@link
- * org.wildfly.core.launcher.CommandBuilder command builder}.
- *
- * The process is only created by the launcher and not managed. It's the responsibility of the consumer to manage the
- * process.
- *
- * @author James R. Perkins
- */
-@SuppressWarnings("unused")
-public class Launcher {
-
- private final CommandBuilder builder;
- private boolean redirectErrorStream;
- private Redirect outputDestination;
- private Redirect errorDestination;
- private File workingDirectory;
- private final Map env;
-
- /**
- * Creates a new launcher.
- *
- * @param builder the builder to build the list of commands
- */
- public Launcher(final CommandBuilder builder) {
- this.builder = builder;
- redirectErrorStream = false;
- outputDestination = null;
- errorDestination = null;
- env = new HashMap<>();
- }
-
- /**
- * Creates a new launcher to create a {@link java.lang.Process process} based on the command builder.
- *
- * @param builder the builder used to launch the process
- *
- * @return the newly created launcher
- */
- public static Launcher of(final CommandBuilder builder) {
- return new Launcher(builder);
- }
-
- /**
- * Sets the output and error streams to inherit the output and error streams from it's parent process.
- *
- * @return the launcher
- */
- public Launcher inherit() {
- outputDestination = Redirect.INHERIT;
- errorDestination = Redirect.INHERIT;
- return this;
- }
-
- /**
- * Set to {@code true} if the error stream should be redirected to the output stream.
- *
- * @param redirectErrorStream {@code true} to merge the error stream into the output stream, otherwise {@code
- * false}
- * to keep the streams separate
- *
- * @return the launcher
- */
- public Launcher setRedirectErrorStream(final boolean redirectErrorStream) {
- this.redirectErrorStream = redirectErrorStream;
- return this;
- }
-
- /**
- * Redirects the output of the process to a file.
- *
- * @param file the file to redirect the output to
- *
- * @return the launcher
- *
- * @see java.lang.ProcessBuilder.Redirect#to(java.io.File)
- */
- public Launcher redirectOutput(final File file) {
- outputDestination = Redirect.to(file);
- return this;
- }
-
- /**
- * Redirects the output of the process to a file.
- *
- * @param path the path to redirect the output to
- *
- * @return the launcher
- *
- * @see java.lang.ProcessBuilder.Redirect#to(java.io.File)
- */
- public Launcher redirectOutput(final Path path) {
- return redirectOutput(path.toFile());
- }
-
- /**
- * Redirects the output of the process to the destination provided.
- *
- * @param destination the output destination
- *
- * @return the launcher
- *
- * @see java.lang.ProcessBuilder#redirectOutput(java.lang.ProcessBuilder.Redirect)
- */
- public Launcher redirectOutput(final Redirect destination) {
- outputDestination = destination;
- return this;
- }
-
- /**
- * Redirects the error stream of the process to a file.
- *
- * @param file the file to redirect the error stream to
- *
- * @return the launcher
- *
- * @see java.lang.ProcessBuilder.Redirect#to(java.io.File)
- */
- public Launcher redirectError(final File file) {
- errorDestination = Redirect.to(file);
- return this;
- }
-
-
- /**
- * Redirects the error stream of the process to the destination provided.
- *
- * @param destination the error stream destination
- *
- * @return the launcher
- *
- * @see java.lang.ProcessBuilder#redirectError(java.lang.ProcessBuilder.Redirect)
- */
- public Launcher redirectError(final Redirect destination) {
- errorDestination = destination;
- return this;
- }
-
- /**
- * Sets the working directory for the process created.
- *
- * @param path the path to the working directory
- *
- * @return the launcher
- *
- * @see java.lang.ProcessBuilder#directory(java.io.File)
- */
- public Launcher setDirectory(final Path path) {
- workingDirectory = path.toFile();
- return this;
- }
-
- /**
- * Sets the working directory for the process created.
- *
- * @param dir the working directory
- *
- * @return the launcher
- *
- * @see java.lang.ProcessBuilder#directory(java.io.File)
- */
- public Launcher setDirectory(final File dir) {
- workingDirectory = dir;
- return this;
- }
-
- /**
- * Sets the working directory for the process created.
- *
- * @param dir the working directory
- *
- * @return the launcher
- *
- * @see java.lang.ProcessBuilder#directory(java.io.File)
- */
- public Launcher setDirectory(final String dir) {
- return setDirectory(Environment.validateAndNormalizeDir(dir, true));
- }
-
- /**
- * Adds an environment variable to the process being created. If the key or value is {@code null}, the environment
- * variable will not be added.
- *
- * @param key they key for the variable
- * @param value the value for the variable
- *
- * @return the launcher
- * @see ProcessBuilder#environment()
- */
- public Launcher addEnvironmentVariable(final String key, final String value) {
- if (key != null && value != null) {
- env.put(key, value);
- }
- return this;
- }
-
- /**
- * Adds the environment variables to the process being created. Note that {@code null} keys or values will not be
- * added.
- *
- * @param env the environment variables to add
- *
- * @return the launcher
- * @see ProcessBuilder#environment()
- */
- public Launcher addEnvironmentVariables(final Map env) {
- env.forEach((key, value) -> {
- if (key != null && value != null) {
- addEnvironmentVariable(key, value);
- }
- });
- return this;
- }
-
- /**
- * Launches a new process based on the commands from the {@link org.wildfly.core.launcher.CommandBuilder builder}.
- *
- * @return the newly created process
- *
- * @throws IOException if an error occurs launching the process
- */
- public Process launch() throws IOException {
- final ProcessBuilder processBuilder = new ProcessBuilder(builder.build());
- if (outputDestination != null) {
- processBuilder.redirectOutput(outputDestination);
- }
- if (errorDestination != null) {
- processBuilder.redirectError(errorDestination);
- }
- if (workingDirectory != null) {
- processBuilder.directory(workingDirectory);
- }
- if (!env.isEmpty()) {
- processBuilder.environment().putAll(env);
- }
- processBuilder.redirectErrorStream(redirectErrorStream);
- return processBuilder.start();
- }
-}
diff --git a/launcher/src/main/java/org/wildfly/core/launcher/ProcessHelper.java b/launcher/src/main/java/org/wildfly/core/launcher/ProcessHelper.java
deleted file mode 100644
index 6520fc81d98..00000000000
--- a/launcher/src/main/java/org/wildfly/core/launcher/ProcessHelper.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright The WildFly Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package org.wildfly.core.launcher;
-
-/**
- * A helper class to help with managing a process.
- *
- * @author James R. Perkins
- */
-public class ProcessHelper {
-
- /**
- * Checks to see if the process has died.
- *
- * @param process the process to check
- *
- * @return {@code true} if the process has died, otherwise {@code false}
- * @see Process#isAlive()
- */
- @SuppressWarnings("unused")
- @Deprecated(forRemoval = true)
- public static boolean processHasDied(final Process process) {
- return !process.isAlive();
- }
-
- /**
- * Destroys the process if the process is not {@code null}.
- *
- * @param process the process to destroy, terminate
- *
- * @return 0 if the process was successfully destroyed
- */
- public static int destroyProcess(final Process process) throws InterruptedException {
- if (process == null)
- return 0;
- process.destroy();
- return process.waitFor();
- }
-
- /**
- * Adds a shutdown hook for the process.
- *
- * @param process the process to add a shutdown hook for
- *
- * @return the thread set as the shutdown hook
- *
- * @throws java.lang.SecurityException If a security manager is present and it denies {@link
- * java.lang.RuntimePermission RuntimePermission("shutdownHooks")
}
- */
- public static Thread addShutdownHook(final Process process) {
- final Thread thread = new Thread(() -> {
- if (process != null) {
- process.destroyForcibly();
- try {
- process.waitFor();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- });
- thread.setDaemon(true);
- Runtime.getRuntime().addShutdownHook(thread);
- return thread;
- }
-}
diff --git a/launcher/src/main/java/org/wildfly/core/launcher/StandaloneCommandBuilder.java b/launcher/src/main/java/org/wildfly/core/launcher/StandaloneCommandBuilder.java
deleted file mode 100644
index a0a18953999..00000000000
--- a/launcher/src/main/java/org/wildfly/core/launcher/StandaloneCommandBuilder.java
+++ /dev/null
@@ -1,670 +0,0 @@
-/*
- * Copyright The WildFly Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-package org.wildfly.core.launcher;
-
-import static org.wildfly.core.launcher.logger.LauncherMessages.MESSAGES;
-
-import java.io.File;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.StringJoiner;
-
-import org.wildfly.core.launcher.Arguments.Argument;
-
-/**
- * Builds a list of commands used to launch a standalone instance of WildFly.
- *
- * This builder is not thread safe and the same instance should not be used in multiple threads.
- *
- * @author James R. Perkins
- */
-@SuppressWarnings({"unused", "UnusedReturnValue"})
-public class StandaloneCommandBuilder extends AbstractCommandBuilder implements CommandBuilder {
-
- // JPDA remote socket debugging
- static final String DEBUG_FORMAT = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=%s,address=%d";
-
- private static final String MODULE_NAME = "org.jboss.as.standalone";
- private static final String SERVER_BASE_DIR = "jboss.server.base.dir";
- private static final String SERVER_CONFIG_DIR = "jboss.server.config.dir";
- private static final String SERVER_LOG_DIR = "jboss.server.log.dir";
-
- private Path baseDir;
- private final Arguments javaOpts;
- private String debugArg;
- private String modulesLocklessArg;
- private String modulesMetricsArg;
- private final Map securityProperties;
- private boolean addModuleAgent;
- private final Collection moduleOpts;
-
- /**
- * Creates a new command builder for a standalone instance.
- *
- * Note the {@code wildflyHome} and {@code javaHome} are not validated using the constructor. The static {@link
- * #of(java.nio.file.Path)} is preferred.
- *
- * @param wildflyHome the path to WildFly
- */
- private StandaloneCommandBuilder(final Path wildflyHome) {
- super(wildflyHome, MODULE_NAME);
- javaOpts = new Arguments();
- javaOpts.addAll(DEFAULT_VM_ARGUMENTS);
- securityProperties = new LinkedHashMap<>();
- moduleOpts = new ArrayList<>();
- addModuleAgent = false;
- }
-
- /**
- * Creates a command builder for a standalone instance of WildFly.
- *
- * @param wildflyHome the path to the WildFly home directory
- *
- * @return a new builder
- */
- public static StandaloneCommandBuilder of(final Path wildflyHome) {
- return new StandaloneCommandBuilder(Environment.validateWildFlyDir(wildflyHome));
- }
-
- /**
- * Creates a command builder for a standalone instance of WildFly.
- *
- * @param wildflyHome the path to the WildFly home directory
- *
- * @return a new builder
- */
- public static StandaloneCommandBuilder of(final String wildflyHome) {
- return new StandaloneCommandBuilder(Environment.validateWildFlyDir(wildflyHome));
- }
-
- /**
- * Adds a JVM argument to the command ignoring {@code null} arguments.
- *
- * @param jvmArg the JVM argument to add
- *
- * @return the builder
- */
- public StandaloneCommandBuilder addJavaOption(final String jvmArg) {
- if (jvmArg != null && !jvmArg.trim().isEmpty()) {
- final Argument argument = Arguments.parse(jvmArg);
- switch (argument.getKey()) {
- case SERVER_BASE_DIR:
- if (argument.getValue() != null) {
- setBaseDirectory(argument.getValue());
- }
- break;
- case SERVER_CONFIG_DIR:
- if (argument.getValue() != null) {
- setConfigurationDirectory(argument.getValue());
- }
- break;
- case SERVER_LOG_DIR:
- if (argument.getValue() != null) {
- setLogDirectory(argument.getValue());
- }
- break;
- case SECURITY_MANAGER_PROP:
- // [WFCORE-5778] java.security.manager system property with value "allow" detected.
- // It doesn't mean SM is going to be installed but it indicates SM can be installed dynamically.
- setUseSecurityManager(isJavaSecurityManagerConfigured(argument));
- break;
- default:
- javaOpts.add(argument);
- break;
- }
- }
- return this;
- }
-
- /**
- * Adds the array of JVM arguments to the command.
- *
- * @param javaOpts the array of JVM arguments to add, {@code null} arguments are ignored
- *
- * @return the builder
- */
- public StandaloneCommandBuilder addJavaOptions(final String... javaOpts) {
- if (javaOpts != null) {
- for (String javaOpt : javaOpts) {
- addJavaOption(javaOpt);
- }
- }
- return this;
- }
-
- /**
- * Adds the collection of JVM arguments to the command.
- *
- * @param javaOpts the collection of JVM arguments to add, {@code null} arguments are ignored
- *
- * @return the builder
- */
- public StandaloneCommandBuilder addJavaOptions(final Iterable javaOpts) {
- if (javaOpts != null) {
- for (String javaOpt : javaOpts) {
- addJavaOption(javaOpt);
- }
- }
- return this;
- }
-
- /**
- * Sets the JVM arguments to use. This overrides any default JVM arguments that would normally be added and ignores
- * {@code null} values in the collection.
- *
- * If the collection is {@code null} the JVM arguments will be cleared and no new arguments will be added.
- *
- * @param javaOpts the JVM arguments to use
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setJavaOptions(final Iterable javaOpts) {
- this.javaOpts.clear();
- return addJavaOptions(javaOpts);
- }
-
- /**
- * Sets the JVM arguments to use. This overrides any default JVM arguments that would normally be added and ignores
- * {@code null} values in the array.
- *
- * If the array is {@code null} the JVM arguments will be cleared and no new arguments will be added.
- *
- * @param javaOpts the JVM arguments to use
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setJavaOptions(final String... javaOpts) {
- this.javaOpts.clear();
- return addJavaOptions(javaOpts);
- }
-
- /**
- * Returns the JVM arguments.
- *
- * @return the JVM arguments
- */
- public List getJavaOptions() {
- return javaOpts.asList();
- }
-
- /**
- * Adds an option which will be passed to JBoss Modules.
- *
- * Note that {@code -mp} or {@code --modulepath} is not supported. Use {@link #addModuleDir(String)} to add a module
- * directory.
- *
- *
- * @param arg the argument to add
- *
- * @return the builder
- */
- public StandaloneCommandBuilder addModuleOption(final String arg) {
- if (arg != null) {
- if (arg.startsWith("-javaagent:")) {
- addModuleAgent = true;
- } else if ("-mp".equals(arg) || "--modulepath".equals(arg)) {
- throw MESSAGES.invalidArgument(arg, "addModuleOption");
- } else if ("-secmgr".equals(arg)) {
- throw MESSAGES.invalidArgument(arg, "setUseSecurityManager");
- }
- moduleOpts.add(arg);
- }
- return this;
- }
-
- /**
- * Adds the options which will be passed to JBoss Modules.
- *
- * Note that {@code -mp} or {@code --modulepath} is not supported. Use {@link #addModuleDirs(String...)} to add a
- * module directory.
- *
- *
- * @param args the argument to add
- *
- * @return the builder
- */
- public StandaloneCommandBuilder addModuleOptions(final String... args) {
- if (args != null) {
- for (String arg : args) {
- addModuleOption(arg);
- }
- }
- return this;
- }
-
- /**
- * Adds the options which will be passed to JBoss Modules.
- *
- * Note that {@code -mp} or {@code --modulepath} is not supported. Use {@link #addModuleDirs(Iterable)} to add a
- * module directory.
- *
- *
- * @param args the argument to add
- *
- * @return the builder
- */
- public StandaloneCommandBuilder addModuleOptions(final Iterable args) {
- if (args != null) {
- for (String arg : args) {
- addModuleOption(arg);
- }
- }
- return this;
- }
-
- /**
- * Clears the current module options and adds the options which will be passed to JBoss Modules.
- *
- * Note that {@code -mp} or {@code --modulepath} is not supported. Use {@link #addModuleDirs(String...)} to add a
- * module directory.
- *
- *
- * @param args the argument to use
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setModuleOptions(final String... args) {
- moduleOpts.clear();
- addModuleOptions(args);
- return this;
- }
-
- /**
- * Clears the current module options and adds the options which will be passed to JBoss Modules.
- *
- * Note that {@code -mp} or {@code --modulepath} is not supported. Use {@link #addModuleDirs(Iterable)} to add a
- * module directory.
- *
- *
- * @param args the argument to use
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setModuleOptions(final Iterable args) {
- moduleOpts.clear();
- addModuleOptions(args);
- return this;
- }
-
- /**
- * Sets the debug argument for the JVM with a default port of {@code 8787}.
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setDebug() {
- return setDebug(false, 8787);
- }
-
- /**
- * Sets the debug argument for the JVM.
- *
- * @param port the port to listen on
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setDebug(final int port) {
- return setDebug(false, port);
- }
-
- /**
- * Sets the debug JPDA remote socket debugging argument.
- *
- * @param suspend {@code true} to suspend otherwise {@code false}
- * @param port the port to listen on
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setDebug(final boolean suspend, final int port) {
- debugArg = String.format(DEBUG_FORMAT, (suspend ? "y" : "n"), port);
- return this;
- }
-
- /**
- * Sets the base directory to use.
- *
- * The default is {@code $JBOSS_HOME/standalone}.
- *
- * @param baseDir the base directory or {@code null} to resolve the base directory
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setBaseDirectory(final String baseDir) {
- this.baseDir = Environment.validateAndNormalizeDir(baseDir, true);
- return this;
- }
-
- /**
- * Sets the base directory to use.
- *
- * The default is {@code $JBOSS_HOME/standalone}.
- *
- * @param baseDir the base directory or {@code null} to resolve the base directory
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setBaseDirectory(final Path baseDir) {
- this.baseDir = Environment.validateAndNormalizeDir(baseDir, true);
- return this;
- }
-
- /**
- * Sets the Java home where the Java executable can be found.
- *
- * @param javaHome the Java home or {@code null} to use te system property {@code java.home}
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setJavaHome(final String javaHome) {
- environment.setJvm(Jvm.of(javaHome));
- return this;
- }
-
- /**
- * Sets the Java home where the Java executable can be found.
- *
- * @param javaHome the Java home or {@code null} to use te system property {@code java.home}
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setJavaHome(final Path javaHome) {
- environment.setJvm(Jvm.of(javaHome));
- return this;
- }
-
- /**
- * Set to {@code true} to use JBoss Modules lockless mode.
- *
- * @param b {@code true} to use lockless mode
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setModulesLockless(final boolean b) {
- if (b) {
- modulesLocklessArg = "-Djboss.modules.lockless=true";
- } else {
- modulesLocklessArg = null;
- }
- return this;
- }
-
- /**
- * Set to {@code true} to gather metrics for JBoss Modules.
- *
- * @param b {@code true} to gather metrics for JBoss Modules.
- *
- * @return this builder
- */
- public StandaloneCommandBuilder setModulesMetrics(final boolean b) {
- if (b) {
- modulesMetricsArg = "-Djboss.modules.metrics=true";
- } else {
- modulesMetricsArg = null;
- }
- return this;
- }
-
- /**
- * Sets the configuration file for the server. The file must be in the {@link #setConfigurationDirectory(String)
- * configuration} directory. A value of {@code null} will remove the configuration file.
- *
- * This will override any previous value set via {@link #addServerArgument(String)}.
- *
- * @param configFile the configuration file name or {@code null} to remove the configuration file
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setServerConfiguration(final String configFile) {
- setSingleServerArg("-c", configFile);
- return this;
- }
-
- /**
- * Returns the configuration file {@link #setServerConfiguration(String) set} or {@code null} if one was not set.
- *
- * @return the configuration file set or {@code null} if not set
- */
- public String getServerConfiguration() {
- return getServerArg("-c");
- }
-
- /**
- * Sets the configuration file for the server. The file must be in the {@link #setConfigurationDirectory(String)
- * configuration} directory. A value of {@code null} will remove the configuration file.
- *
- * This will override any previous value set via {@link #addServerArgument(String)}.
- *
- * @param configFile the configuration file name or {@code null} to remove the configuration file
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setServerReadOnlyConfiguration(final String configFile) {
- setSingleServerArg("--read-only-server-config", configFile);
- return this;
- }
-
- /**
- * Returns the configuration file {@link #setServerConfiguration(String) set} or {@code null} if one was not set.
- *
- * @return the configuration file set or {@code null} if not set
- */
- public String getReadOnlyServerConfiguration() {
- return getServerArg("--read-only-server-config");
- }
-
- /**
- * Adds a security property to be passed to the server with a {@code null} value.
- *
- * @param key the property key
- *
- * @return the builder
- */
- public StandaloneCommandBuilder addSecurityProperty(final String key) {
- securityProperties.put(key, null);
- return this;
- }
-
- /**
- * Adds a security property to be passed to the server.
- *
- * @param key the property key
- * @param value the property value
- *
- * @return the builder
- */
- public StandaloneCommandBuilder addSecurityProperty(final String key, final String value) {
- securityProperties.put(key, value);
- return this;
- }
-
- /**
- * Adds all the security properties to be passed to the server.
- *
- * @param properties a map of the properties to add, {@code null} values are allowed in the map
- *
- * @return the builder
- */
- public StandaloneCommandBuilder addSecurityProperties(final Map properties) {
- securityProperties.putAll(properties);
- return this;
- }
-
- /**
- * Configures the git repository for the standalone server.
- *
- * @param gitRepository the git repository to clone to get the server configuration from
- * @param gitBranch the branch to use to get the server configuration
- * @param gitAuthentication the Elytron configuration file for managing git credentials
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setGitRepository(final String gitRepository, final String gitBranch, final String gitAuthentication) {
- if (gitRepository == null) {
- throw MESSAGES.nullParam("git-repo");
- }
- addServerArg("--git-repo", gitRepository);
- if (gitBranch != null) {
- addServerArg("--git-branch", gitBranch);
- }
- if (gitAuthentication != null) {
- addServerArg("--git-auth", gitAuthentication);
- }
-
- return this;
- }
-
- /**
- * Adds the YAML configuration file argument with the given YAML configuration files.
- *
- * @param yamlFiles the files to add
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setYamlFiles(final Collection yamlFiles) {
- if (yamlFiles == null || yamlFiles.isEmpty()) {
- return this;
- }
- StringJoiner joiner = new StringJoiner(File.pathSeparator);
- for (Path yamlFile : yamlFiles) {
- joiner.add(yamlFile.toAbsolutePath().toString());
- }
- setSingleServerArg("--yaml", joiner.toString());
- return this;
- }
-
- /**
- * Adds the YAML configuration file argument with the given YAML configuration files.
- *
- * @param yamlFiles the files to add
- *
- * @return the builder
- */
- public StandaloneCommandBuilder setYamlFiles(final Path... yamlFiles) {
- if (yamlFiles == null || yamlFiles.length == 0) {
- return this;
- }
- return setYamlFiles(List.of(yamlFiles));
- }
-
- /**
- * Sets the stability level of the domain controller process.
- * @param stability a stability level
- * @return a reference to this builder
- */
- public StandaloneCommandBuilder setStability(String stability) {
- if (stability != null) {
- this.setSingleServerArg("--stability", stability);
- }
- return this;
- }
-
- @Override
- public List buildArguments() {
- final List cmd = new ArrayList<>();
- cmd.add("-D[Standalone]");
- // Check to see if an agent was added as a module option, if so we want to add JBoss Modules as an agent.
- if (addModuleAgent) {
- cmd.add("-javaagent:" + getModulesJarName());
- }
- cmd.addAll(getJavaOptions());
- if (environment.getJvm().isModular()) {
- cmd.addAll(DEFAULT_MODULAR_VM_ARGUMENTS);
- for (final String optionalModularArgument : OPTIONAL_DEFAULT_MODULAR_VM_ARGUMENTS) {
- if (Jvm.isPackageAvailable(environment.getJvm().getPath(), optionalModularArgument)) {
- cmd.add(optionalModularArgument);
- }
- }
- }
- if (environment.getJvm().enhancedSecurityManagerAvailable()) {
- cmd.add(SECURITY_MANAGER_PROP_WITH_ALLOW_VALUE);
- }
- // Add these to JVM level system properties
- addSystemPropertyArg(cmd, HOME_DIR, getWildFlyHome());
- addSystemPropertyArg(cmd, SERVER_BASE_DIR, getBaseDirectory());
- addSystemPropertyArg(cmd, SERVER_LOG_DIR, getLogDirectory());
- addSystemPropertyArg(cmd, SERVER_CONFIG_DIR, getConfigurationDirectory());
- if (modulesLocklessArg != null) {
- cmd.add(modulesLocklessArg);
- }
- if (modulesMetricsArg != null) {
- cmd.add(modulesMetricsArg);
- }
- if (debugArg != null) {
- cmd.add(debugArg);
- }
- cmd.add(getBootLogArgument("server.log"));
- cmd.add(getLoggingPropertiesArgument("logging.properties"));
- cmd.add("-jar");
- cmd.add(getModulesJarName());
- if (useSecurityManager()) {
- cmd.add(SECURITY_MANAGER_ARG);
- }
- // Add the agent argument for jboss-modules
- cmd.addAll(moduleOpts);
- cmd.add("-mp");
- cmd.add(getModulePaths());
- cmd.add(MODULE_NAME);
-
- // Add the security properties
- StringBuilder sb = new StringBuilder(64);
- for (Map.Entry entry : securityProperties.entrySet()) {
- sb.append("-S").append(entry.getKey());
- if (entry.getValue() != null) {
- sb.append('=').append(entry.getValue());
- }
- cmd.add(sb.toString());
- sb.setLength(0);
- }
-
- cmd.addAll(getServerArguments());
- return cmd;
- }
-
- @Override
- public Path getJavaHome() {
- return environment.getJvm().getPath();
- }
-
- @Override
- public Path getBaseDirectory() {
- if (baseDir == null) {
- return normalizePath("standalone");
- }
- return baseDir;
- }
-
- @Override
- protected StandaloneCommandBuilder getThis() {
- return this;
- }
-
- @Override
- boolean addServerArgument(final Argument argument) {
- switch (argument.getKey()) {
- case SERVER_BASE_DIR:
- if (argument.getValue() != null) {
- setBaseDirectory(argument.getValue());
- return false;
- }
- break;
- case SERVER_CONFIG_DIR:
- if (argument.getValue() != null) {
- setConfigurationDirectory(argument.getValue());
- return false;
- }
- break;
- case SERVER_LOG_DIR:
- if (argument.getValue() != null) {
- setLogDirectory(argument.getValue());
- return false;
- }
- break;
- }
- return true;
- }
-}
diff --git a/launcher/src/main/java/org/wildfly/core/launcher/logger/LauncherMessages.java b/launcher/src/main/java/org/wildfly/core/launcher/logger/LauncherMessages.java
deleted file mode 100644
index 1f6db0e4e6e..00000000000
--- a/launcher/src/main/java/org/wildfly/core/launcher/logger/LauncherMessages.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright The WildFly Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package org.wildfly.core.launcher.logger;
-
-import java.nio.file.Path;
-
-import org.jboss.logging.annotations.Message;
-import org.jboss.logging.annotations.MessageBundle;
-
-/**
- * @author James R. Perkins
- */
-@MessageBundle(projectCode = "WFLYLNCHR", length = 4)
-public interface LauncherMessages {
-
- LauncherMessages MESSAGES = Messages.getBundle(LauncherMessages.class);
-
- /**
- * Creates a message indicating the path does not exist.
- *
- * @param path the path that does not exist
- *
- * @return an exception for the error
- */
- @Message(id = 1, value = "The path '%s' does not exist")
- IllegalArgumentException pathDoesNotExist(Path path);
-
- @Message(id = 2, value = "The directory '%s' is not a valid directory")
- IllegalArgumentException invalidDirectory(Path dir);
-
- @Message(id = 3, value = "Invalid directory, could not find '%s' in '%s'")
- IllegalArgumentException invalidDirectory(String filename, Path dir);
-
- @Message(id = 4, value = "Path '%s' is not a regular file.")
- IllegalArgumentException pathNotAFile(Path path);
-
- @Message(id = 5, value = "The parameter %s cannot be null.")
- IllegalArgumentException nullParam(String name);
-
- @Message(id = 6, value = "Invalid hostname: %s")
- IllegalArgumentException invalidHostname(CharSequence hostname);
-
- @Message(id = 7, value = "The argument %s is not allowed for %s.")
- IllegalArgumentException invalidArgument(String argument, String methodName);
-}
diff --git a/launcher/src/main/java/org/wildfly/core/launcher/logger/Messages.java b/launcher/src/main/java/org/wildfly/core/launcher/logger/Messages.java
deleted file mode 100644
index 987853a56e7..00000000000
--- a/launcher/src/main/java/org/wildfly/core/launcher/logger/Messages.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright The WildFly Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package org.wildfly.core.launcher.logger;
-
-import static java.security.AccessController.doPrivileged;
-
-import java.lang.reflect.Field;
-import java.security.PrivilegedAction;
-import java.util.Locale;
-
-/**
- * Copied the logging Messages to use 0 dependencies for this module.
- *
- * @author David M. Lloyd
- * @author James R. Perkins
- */
-class Messages {
-
- private Messages() {
- }
-
- /**
- * Get a message bundle of the given type.
- *
- * @param type the bundle type class
- *
- * @return the bundle
- */
- public static T getBundle(final Class type) {
- return doPrivileged(new PrivilegedAction() {
- public T run() {
- final Locale locale = Locale.getDefault();
- final String lang = locale.getLanguage();
- final String country = locale.getCountry();
- final String variant = locale.getVariant();
-
- Class extends T> bundleClass = null;
- if (variant != null && !variant.isEmpty()) try {
- bundleClass = Class.forName(join(type.getName(), "$bundle", lang, country, variant), true, type.getClassLoader()).asSubclass(type);
- } catch (ClassNotFoundException e) {
- // ignore
- }
- if (bundleClass == null && country != null && !country.isEmpty()) try {
- bundleClass = Class.forName(join(type.getName(), "$bundle", lang, country, null), true, type.getClassLoader()).asSubclass(type);
- } catch (ClassNotFoundException e) {
- // ignore
- }
- if (bundleClass == null && lang != null && !lang.isEmpty()) try {
- bundleClass = Class.forName(join(type.getName(), "$bundle", lang, null, null), true, type.getClassLoader()).asSubclass(type);
- } catch (ClassNotFoundException e) {
- // ignore
- }
- if (bundleClass == null) try {
- bundleClass = Class.forName(join(type.getName(), "$bundle", null, null, null), true, type.getClassLoader()).asSubclass(type);
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("Invalid bundle " + type + " (implementation not found)");
- }
- final Field field;
- try {
- field = bundleClass.getField("INSTANCE");
- } catch (NoSuchFieldException e) {
- throw new IllegalArgumentException("Bundle implementation " + bundleClass + " has no instance field");
- }
- try {
- return type.cast(field.get(null));
- } catch (IllegalAccessException e) {
- throw new IllegalArgumentException("Bundle implementation " + bundleClass + " could not be instantiated", e);
- }
- }
- });
- }
-
- private static String join(final String interfaceName, final String type, final String lang, final String country, final String variant) {
- final StringBuilder build = new StringBuilder();
- build.append(interfaceName).append('_').append(type);
- if (lang != null && !lang.isEmpty()) {
- build.append('_');
- build.append(lang);
- }
- if (country != null && !country.isEmpty()) {
- build.append('_');
- build.append(country);
- }
- if (variant != null && !variant.isEmpty()) {
- build.append('_');
- build.append(variant);
- }
- return build.toString();
- }
-}
diff --git a/launcher/src/test/java/org/wildfly/core/launcher/CommandBuilderTest.java b/launcher/src/test/java/org/wildfly/core/launcher/CommandBuilderTest.java
deleted file mode 100644
index 509cb42a6c9..00000000000
--- a/launcher/src/test/java/org/wildfly/core/launcher/CommandBuilderTest.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * Copyright The WildFly Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package org.wildfly.core.launcher;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.wildfly.core.launcher.Arguments.Argument;
-
-/**
- * @author James R. Perkins
- */
-public class CommandBuilderTest {
-
- private static final Path WILDFLY_HOME;
- private static final Path WILDFLY_BOOTABLE_JAR;
-
- static {
- WILDFLY_HOME = Paths.get(System.getProperty("wildfly.launcher.home")).toAbsolutePath().normalize();
- WILDFLY_BOOTABLE_JAR = Paths.get(System.getProperty("wildfly.launcher.bootable.jar")).toAbsolutePath().normalize();
-
- // Create some default directories and empty bootable fake jar file
- try {
- Files.createFile(WILDFLY_BOOTABLE_JAR);
- Files.createDirectories(WILDFLY_HOME.resolve("modules"));
- Files.createDirectories(WILDFLY_HOME.resolve("configuration"));
- Files.createDirectories(WILDFLY_HOME.resolve("data"));
- } catch (IOException ignore) {
- }
- }
-
- @Test
- public void testJBossModulesBuilder() {
- // Set up a standalone command builder
- final JBossModulesCommandBuilder commandBuilder = JBossModulesCommandBuilder.of(WILDFLY_HOME, "org.jboss.as.launcher.test")
- .addJavaOption("-Djava.security.manager")
- .addJavaOption("-Djava.net.preferIPv4Stack=true")
- .addJavaOption("-Djava.net.preferIPv4Stack=false")
- .addModuleOption("-javaagent:test-agent1.jar")
- .addServerArgument("--server=test");
-
- // Get all the commands
- List commands = commandBuilder.buildArguments();
-
- Assert.assertTrue("Missing -secmgr option", commands.contains("-secmgr"));
-
- Assert.assertTrue("Missing jboss-modules.jar", commands.stream().anyMatch(entry -> entry.matches("-javaagent:.*jboss-modules.jar$")));
- Assert.assertTrue("Missing test-agent1.jar", commands.contains("-javaagent:test-agent1.jar"));
- Assert.assertTrue("Missing --server=test", commands.contains("--server=test"));
-
- // If we're using Java 9+ ensure the modular JDK options were added
- testModularJvmArguments(commands, 1);
-
- // A system property should only be added ones
- long count = 0L;
- for (String s : commandBuilder.getJavaOptions()) {
- if (s.contains("java.net.preferIPv4Stack")) {
- count++;
- }
- }
- Assert.assertEquals("There should be only one java.net.preferIPv4Stack system property", 1, count);
-
- // The value saved should be the last value added
- Assert.assertTrue("java.net.preferIPv4Stack should be set to false", commandBuilder.getJavaOptions().contains("-Djava.net.preferIPv4Stack=false"));
- }
-
- @Test
- public void testStandaloneBuilder() {
- // Set up a standalone command builder
- final StandaloneCommandBuilder commandBuilder = StandaloneCommandBuilder.of(WILDFLY_HOME)
- .setAdminOnly()
- .setBindAddressHint("0.0.0.0")
- .setDebug(true, 5005)
- .setServerConfiguration("standalone-full.xml")
- .addJavaOption("-Djava.security.manager")
- .addJavaOption("-Djava.net.preferIPv4Stack=true")
- .addJavaOption("-Djava.net.preferIPv4Stack=false")
- .addModuleOption("-javaagent:test-agent1.jar")
- .setBindAddressHint("management", "0.0.0.0");
-
- // Get all the commands
- List commands = commandBuilder.buildArguments();
-
- Assert.assertTrue("--admin-only is missing", commands.contains("--admin-only"));
-
- Assert.assertTrue("Missing -b=0.0.0.0", commands.contains("-b=0.0.0.0"));
-
- Assert.assertTrue("Missing -b=0.0.0.0", commands.contains("-bmanagement=0.0.0.0"));
-
- Assert.assertTrue("Missing debug argument", commands.contains(String.format(StandaloneCommandBuilder.DEBUG_FORMAT, "y", 5005)));
-
- Assert.assertTrue("Missing server configuration file override", commands.contains("-c=standalone-full.xml"));
-
- Assert.assertTrue("Missing -secmgr option", commands.contains("-secmgr"));
-
- Assert.assertTrue("Missing jboss-modules.jar", commands.stream().anyMatch(entry -> entry.matches("-javaagent:.*jboss-modules.jar$")));
- Assert.assertTrue("Missing test-agent1.jar", commands.contains("-javaagent:test-agent1.jar"));
-
- // If we're using Java 9+ ensure the modular JDK options were added
- testModularJvmArguments(commands, 1);
-
- // A system property should only be added ones
- long count = 0L;
- for (String s : commandBuilder.getJavaOptions()) {
- if (s.contains("java.net.preferIPv4Stack")) {
- count++;
- }
- }
- Assert.assertEquals("There should be only one java.net.preferIPv4Stack system property", 1, count);
-
- // The value saved should be the last value added
- Assert.assertTrue("java.net.preferIPv4Stack should be set to false", commandBuilder.getJavaOptions().contains("-Djava.net.preferIPv4Stack=false"));
-
- // Rename the binding address
- commandBuilder.setBindAddressHint(null);
- commands = commandBuilder.buildArguments();
- Assert.assertFalse("Binding address should have been removed", commands.contains("-b=0.0.0.0"));
- }
-
- @Test
- public void testBootableJarBuilder() {
- // Set up a bootable command builder
- final BootableJarCommandBuilder commandBuilder = BootableJarCommandBuilder.of(WILDFLY_BOOTABLE_JAR)
- .setInstallDir(Paths.get("foo"))
- .setInstallDir(Paths.get("bar"))
- .setBindAddressHint("0.0.0.0")
- .setDebug(true, 5005)
- .addJavaOption("-Djava.security.manager")
- .addJavaOption("-Djava.net.preferIPv4Stack=true")
- .addJavaOption("-Djava.net.preferIPv4Stack=false")
- .setBindAddressHint("management", "0.0.0.0")
- .setYamlFiles(Path.of("bad.yml"))
- .setYamlFiles(Path.of("dummy.yml"));
-
- // Get all the commands
- List commands = commandBuilder.buildArguments();
-
- Assert.assertTrue("--install-dir is missing", commands.contains("--install-dir=bar"));
-
- Assert.assertTrue("Missing -b=0.0.0.0", commands.contains("-b=0.0.0.0"));
-
- Assert.assertTrue("Missing -b=0.0.0.0", commands.contains("-bmanagement=0.0.0.0"));
-
- Assert.assertTrue("Missing debug argument", commands.contains(String.format(StandaloneCommandBuilder.DEBUG_FORMAT, "y", 5005)));
-
- Assert.assertTrue("--yaml is missing", commands.contains("--yaml=" + Path.of("dummy.yml").toFile().getAbsolutePath()));
-
- // If we're using Java 12+. the enhanced security manager option must be set.
- testEnhancedSecurityManager(commands, 1);
- // Bootable JAR handles JPMS arguments thanks to its Manifest file.
- testJPMSArguments(commands, 0);
- // A system property should only be added ones
- long count = 0L;
- for (String s : commandBuilder.getJavaOptions()) {
- if (s.contains("java.net.preferIPv4Stack")) {
- count++;
- }
- }
- Assert.assertEquals("There should be only one java.net.preferIPv4Stack system property", 1, count);
-
- // Install dir should be added once.
- count = 0L;
- for (String s : commandBuilder.getServerArguments()) {
- if (s.contains("--install-dir")) {
- count++;
- }
- }
- Assert.assertEquals("There should be only one --install-dir", 1, count);
-
- // Install dir should be added once.
- count = 0L;
- for (String s : commandBuilder.getServerArguments()) {
- if (s.contains("--yaml")) {
- count++;
- }
- }
- Assert.assertEquals("There should be only one --yaml", 1, count);
-
- // Rename the binding address
- commandBuilder.setBindAddressHint(null);
- commands = commandBuilder.buildArguments();
- Assert.assertFalse("Binding address should have been removed", commands.contains("-b=0.0.0.0"));
- }
-
- @Test
- public void testDomainBuilder() {
- // Set up a standalone command builder
- final DomainCommandBuilder commandBuilder = DomainCommandBuilder.of(WILDFLY_HOME)
- .setAdminOnly()
- .setBindAddressHint("0.0.0.0")
- .setMasterAddressHint("0.0.0.0")
- .setDomainConfiguration("domain.xml")
- .setHostConfiguration("host.xml")
- .addProcessControllerJavaOption("-Djava.security.manager")
- .setBindAddressHint("management", "0.0.0.0");
-
- // Get all the commands
- List commands = commandBuilder.buildArguments();
-
- Assert.assertTrue("--admin-only is missing", commands.contains("--admin-only"));
-
- Assert.assertTrue("Missing -b=0.0.0.0", commands.contains("-b=0.0.0.0"));
-
- Assert.assertTrue("Missing -b=0.0.0.0", commands.contains("--primary-address=0.0.0.0"));
-
- Assert.assertTrue("Missing -b=0.0.0.0", commands.contains("-bmanagement=0.0.0.0"));
-
- Assert.assertTrue("Missing server configuration file override", commands.contains("-c=domain.xml"));
-
- Assert.assertTrue("Missing -secmgr option", commands.contains("-secmgr"));
-
- // If we're using Java 9+ ensure the modular JDK options were added
- testModularJvmArguments(commands, 2);
-
- // Rename the binding address
- commandBuilder.setBindAddressHint(null);
- commands = commandBuilder.buildArguments();
- Assert.assertFalse("Binding address should have been removed", commands.contains("-b=0.0.0.0"));
- }
-
- @Test
- public void testCliBuilder() {
- // Set up a standalone command builder
- final CliCommandBuilder commandBuilder = CliCommandBuilder.asModularLauncher(WILDFLY_HOME)
- .addJavaOption("-Djava.net.preferIPv4Stack=true")
- .addJavaOption("-Djava.net.preferIPv4Stack=false");
-
- // Get all the commands
- final List commands = commandBuilder.buildArguments();
-
- // If we're using Java 9+ ensure the modular JDK options were added
- testModularJvmArguments(commands, 1);
-
- // A system property should only be added ones
- long count = 0L;
- for (String s : commandBuilder.getJavaOptions()) {
- if (s.contains("java.net.preferIPv4Stack")) {
- count++;
- }
- }
- Assert.assertEquals("There should be only one java.net.preferIPv4Stack system property", 1, count);
-
- // The value saved should be the last value added
- Assert.assertTrue("java.net.preferIPv4Stack should be set to false", commandBuilder.getJavaOptions().contains("-Djava.net.preferIPv4Stack=false"));
- }
-
- @Test
- public void testArguments() {
- final Arguments arguments = new Arguments();
- arguments.add("-Dkey=value");
- arguments.add("-X");
- arguments.add("-X");
- arguments.set("single-key", "single-value");
- arguments.set("single-key", "single-value");
- arguments.addAll("-Dprop1=value1", "-Dprop2=value2", "-Dprop3=value3");
-
- // Validate the arguments
- Iterator iter = arguments.getArguments("key").iterator();
- Assert.assertTrue("Missing 'key' entry", iter.hasNext());
- Assert.assertEquals("value", arguments.get("key"));
- Assert.assertEquals("-Dkey=value", iter.next().asCommandLineArgument());
-
- // -X should have been added twice
- Assert.assertEquals(2, arguments.getArguments("-X").size());
-
- // Using set should only add the value once
- Assert.assertEquals("Should not be more than one 'single-key' argument", 1, arguments.getArguments("single-key").size());
-
- // Convert the arguments to a list and ensure each entry has been added in the format expected
- final List stringArgs = arguments.asList();
- Assert.assertEquals(7, stringArgs.size());
- Assert.assertTrue("Missing -Dkey=value", stringArgs.contains("-Dkey=value"));
- Assert.assertTrue("Missing -X", stringArgs.contains("-X"));
- Assert.assertTrue("Missing single-key=single-value", stringArgs.contains("single-key=single-value"));
- Assert.assertTrue("Missing -Dprop1=value1", stringArgs.contains("-Dprop1=value1"));
- Assert.assertTrue("Missing -Dprop2=value2", stringArgs.contains("-Dprop2=value2"));
- Assert.assertTrue("Missing -Dprop3=value3", stringArgs.contains("-Dprop3=value3"));
- }
-
- private void testEnhancedSecurityManager(final Collection command, final int expectedCount) {
- // If we're using Java 12+ ensure enhanced security manager option was added
- if (Jvm.current().enhancedSecurityManagerAvailable()) {
- assertArgumentExists(command, "-Djava.security.manager=allow", expectedCount);
- } else {
- Assert.assertFalse("Did not expect \"-Djava.security.manager=allow\" to be in the command list",
- command.contains("-Djava.security.manager=allow"));
- }
- }
-
- private void testJPMSArguments(final Collection command, final int expectedCount) {
- // Check exports and opens
- assertArgumentExists(command, "--add-exports=java.desktop/sun.awt=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-exports=java.naming/com.sun.jndi.ldap=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-exports=java.naming/com.sun.jndi.url.ldap=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-exports=java.naming/com.sun.jndi.url.ldaps=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-exports=jdk.naming.dns/com.sun.jndi.dns=ALL-UNNAMED", expectedCount);
- if (getJavaVersion() <= 12) {
- // for condition see WFCORE-4296 - java.base/com.sun.net.ssl.internal.ssl isn't available since JDK13
- assertArgumentExists(command, "--add-opens=java.base/com.sun.net.ssl.internal.ssl=ALL-UNNAMED", expectedCount);
- }
- assertArgumentExists(command, "--add-opens=java.base/java.lang=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-opens=java.base/java.io=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-opens=java.base/java.net=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-opens=java.base/java.security=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-opens=java.base/java.util=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-opens=java.base/java.util.concurrent=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-opens=java.management/javax.management=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-opens=java.naming/javax.naming=ALL-UNNAMED", expectedCount);
- assertArgumentExists(command, "--add-modules=java.se", expectedCount);
- }
-
- private static int getJavaVersion() {
- return Runtime.version().feature();
- }
-
- private void testModularJvmArguments(final Collection command, final int expectedCount) {
- testEnhancedSecurityManager(command, expectedCount);
- testJPMSArguments(command, expectedCount);
- }
-
- private static void assertArgumentExists(final Collection args, final String arg, final int expectedCount) {
- int count = 0;
- for (String value : args) {
- if (value.equals(arg)) {
- count++;
- }
- }
- Assert.assertEquals(String.format("Expected %d %s arguments, found %d", expectedCount, arg, count), expectedCount, count);
- }
-
-}
diff --git a/launcher/src/test/java/org/wildfly/core/launcher/JvmTest.java b/launcher/src/test/java/org/wildfly/core/launcher/JvmTest.java
deleted file mode 100644
index bb4aedfdedb..00000000000
--- a/launcher/src/test/java/org/wildfly/core/launcher/JvmTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright The WildFly Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package org.wildfly.core.launcher;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.Collections;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * @author James R. Perkins
- */
-public class JvmTest {
-
- @Test
- public void testReleaseFile() throws Exception {
- testReleaseFile("", false);
- testReleaseFile("1.8.0", false);
- testReleaseFile("1.8.0_191", false);
- testReleaseFile("9", true);
- testReleaseFile("9.0", true);
- testReleaseFile("9.0.1", true);
- testReleaseFile("10", true);
- testReleaseFile("10.0", true);
- testReleaseFile("10.0.2", true);
- testReleaseFile("11", true);
- testReleaseFile("11.0.1", true);
- }
-
- private static void testReleaseFile(final String version, final boolean expectedValue) throws IOException {
- final Path javaHome = createFakeJavaHome(version);
- try {
- Assert.assertEquals(String.format("Expected version %s to %s a modular JVM", version, (expectedValue ? "be" : "not be")),
- expectedValue, Jvm.of(javaHome).isModular());
- } finally {
- Files.walkFileTree(javaHome, new SimpleFileVisitor() {
- @Override
- public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
- Files.delete(file);
- return FileVisitResult.CONTINUE;
- }
-
- @Override
- public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException {
- Files.delete(dir);
- return FileVisitResult.CONTINUE;
- }
- });
- }
- }
-
- private static Path createFakeJavaHome(final String version) throws IOException {
- final Path javaHome = Files.createTempDirectory("fake-java-home");
- Files.createFile(Files.createDirectory(javaHome.resolve("bin")).resolve(Environment.isWindows() ? "java.exe" : "java"));
- final Path releaseFile = javaHome.resolve("release");
- Files.write(releaseFile, Collections.singleton(String.format("JAVA_VERSION=\"%s\"%n", version)), StandardCharsets.UTF_8);
- return javaHome;
- }
-}
diff --git a/launcher/src/test/java/org/wildfly/core/launcher/LauncherTest.java b/launcher/src/test/java/org/wildfly/core/launcher/LauncherTest.java
deleted file mode 100644
index d1895af6ebf..00000000000
--- a/launcher/src/test/java/org/wildfly/core/launcher/LauncherTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright The WildFly Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package org.wildfly.core.launcher;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author James R. Perkins
- */
-public class LauncherTest {
-
- private Path stdout;
-
- @Before
- public void setup() throws IOException {
- stdout = Files.createTempFile("stdout", ".txt");
- }
-
- @After
- public void deleteStdout() throws IOException {
- if (stdout != null) {
- Files.deleteIfExists(stdout);
- }
- }
-
- @Test
- public void checkSingleNullEnvironmentVariable() throws Exception {
- final TestCommandBuilder commandBuilder = new TestCommandBuilder();
- checkProcess(Launcher.of(commandBuilder).addEnvironmentVariable("TEST", null));
- }
-
- @Test
- public void checkNullEnvironmentVariables() throws Exception {
- final TestCommandBuilder commandBuilder = new TestCommandBuilder();
- final Map env = new HashMap<>();
- env.put("TEST", null);
- env.put("TEST_2", "test2");
- checkProcess(Launcher.of(commandBuilder).addEnvironmentVariables(env));
- }
-
- private void checkProcess(final Launcher launcher) throws IOException, InterruptedException {
- Process process = null;
- try {
- process = launcher.setRedirectErrorStream(true).redirectOutput(stdout).launch();
- Assert.assertNotNull("Process should not be null", process);
- Assert.assertTrue("Process should have exited within 5 seconds", process.waitFor(5, TimeUnit.SECONDS));
- Assert.assertEquals(String.format("Process should have exited with an exit code of 0:%n%s", Files.readString(stdout)),
- 0, process.exitValue());
- } finally {
- ProcessHelper.destroyProcess(process);
- }
- }
-
- /**
- * @author James R. Perkins
- */
- private static class TestCommandBuilder implements CommandBuilder {
- @Override
- public List buildArguments() {
- return List.of();
- }
-
- @Override
- public List build() {
- return List.of(Jvm.current().getCommand(), "-version");
- }
- }
-}
diff --git a/pom.xml b/pom.xml
index f947628c6c4..5a7d122f09c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -241,6 +241,7 @@
1.7.0.Final
1.3.0.Final
1.0.3.Final
+ 1.0.0.Beta1
8.0.2.Final
2.2.5.Final
2.2.2.Final
@@ -283,7 +284,6 @@
installation-manager
io
jmx
- launcher
model-test
network
patching
@@ -1547,11 +1547,6 @@
wildfly-jmx
${project.version}