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

[WFCORE-6635] Add a base JBossModulesCommandBuilder for launching oth… #5784

Merged
merged 1 commit into from
Jan 9, 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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,7 @@ public List<String> asList() {
void add(final Argument argument) {
if (argument != null) {
if (argument.multipleValuesAllowed()) {
Collection<Argument> arguments = map.get(argument.getKey());
if (arguments == null) {
arguments = new ArrayList<>();
map.put(argument.getKey(), arguments);
}
final Collection<Argument> arguments = map.computeIfAbsent(argument.getKey(), k -> new ArrayList<>());
arguments.add(argument);
} else {
set(argument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static org.wildfly.core.launcher.AbstractCommandBuilder.DEFAULT_VM_ARGUMENTS;
import static org.wildfly.core.launcher.JBossModulesCommandBuilder.DEFAULT_VM_ARGUMENTS;

import org.wildfly.core.launcher.Arguments.Argument;
import static org.wildfly.core.launcher.StandaloneCommandBuilder.DEBUG_FORMAT;
Expand All @@ -23,7 +23,7 @@
*
* @author <a href="mailto:[email protected]">JF Denise</a>
*/
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "UnusedReturnValue"})
public class BootableJarCommandBuilder implements CommandBuilder {

private final Arguments javaOpts;
Expand Down Expand Up @@ -430,10 +430,9 @@ public BootableJarCommandBuilder addSecurityProperties(final Map<String, String>

@Override
public List<String> buildArguments() {
final List<String> cmd = new ArrayList<>();
cmd.addAll(getJavaOptions());
final List<String> cmd = new ArrayList<>(getJavaOptions());
if (jvm.enhancedSecurityManagerAvailable()) {
cmd.add(AbstractCommandBuilder.SECURITY_MANAGER_PROP_WITH_ALLOW_VALUE);
cmd.add(JBossModulesCommandBuilder.SECURITY_MANAGER_PROP_WITH_ALLOW_VALUE);
}
if (modulesLocklessArg != null) {
cmd.add(modulesLocklessArg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
*
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "UnusedReturnValue"})
public class CliCommandBuilder implements CommandBuilder {

private static Path cliClientJar = Paths.get("bin").resolve("client").resolve("jboss-cli-client.jar");
private static final Path cliClientJar = Paths.get("bin").resolve("client").resolve("jboss-cli-client.jar");

enum CliArgument {
CONNECT("--connect", "-c"),
Expand Down Expand Up @@ -652,20 +652,19 @@ public Path getJavaHome() {

@Override
public List<String> buildArguments() {
final List<String> cmd = new ArrayList<>();
cmd.addAll(getJavaOptions());
final List<String> cmd = new ArrayList<>(getJavaOptions());
if (modularLauncher) {
if (environment.getJvm().isModular()) {
cmd.addAll(AbstractCommandBuilder.DEFAULT_MODULAR_VM_ARGUMENTS);
for (final String optionalModularArgument : AbstractCommandBuilder.OPTIONAL_DEFAULT_MODULAR_VM_ARGUMENTS) {
if (environment.getJvm().isPackageAvailable(environment.getJvm().getPath(), optionalModularArgument)) {
cmd.addAll(JBossModulesCommandBuilder.DEFAULT_MODULAR_VM_ARGUMENTS);
for (final String optionalModularArgument : JBossModulesCommandBuilder.OPTIONAL_DEFAULT_MODULAR_VM_ARGUMENTS) {
if (Jvm.isPackageAvailable(environment.getJvm().getPath(), optionalModularArgument)) {
cmd.add(optionalModularArgument);
}
}
}
}
if (environment.getJvm().enhancedSecurityManagerAvailable()) {
cmd.add(AbstractCommandBuilder.SECURITY_MANAGER_PROP_WITH_ALLOW_VALUE);
cmd.add(JBossModulesCommandBuilder.SECURITY_MANAGER_PROP_WITH_ALLOW_VALUE);
}
cmd.add("-jar");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
*
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "UnusedReturnValue"})
public class DomainCommandBuilder extends AbstractCommandBuilder<DomainCommandBuilder> implements CommandBuilder {

private static final String MODULE_NAME = "org.jboss.as.process-controller";
private static final String DOMAIN_BASE_DIR = "jboss.domain.base.dir";
private static final String DOMAIN_CONFIG_DIR = "jboss.domain.config.dir";
private static final String DOMAIN_LOG_DIR = "jboss.domain.log.dir";
Expand All @@ -45,7 +46,7 @@ public class DomainCommandBuilder extends AbstractCommandBuilder<DomainCommandBu
* @param jvm the default JVM
*/
private DomainCommandBuilder(final Path wildflyHome, final Jvm jvm) {
super(wildflyHome, jvm);
super(wildflyHome, jvm, MODULE_NAME);
hostControllerJavaOpts = new Arguments();
hostControllerJavaOpts.addAll(DEFAULT_VM_ARGUMENTS);
processControllerJavaOpts = new Arguments();
Expand Down Expand Up @@ -287,7 +288,7 @@ public DomainCommandBuilder setProcessControllerPort(final int port) {
* @return the builder
*/
public DomainCommandBuilder setBaseDirectory(final String baseDir) {
this.baseDir = validateAndNormalizeDir(baseDir, true);
this.baseDir = Environment.validateAndNormalizeDir(baseDir, true);
return this;
}

Expand All @@ -301,7 +302,7 @@ public DomainCommandBuilder setBaseDirectory(final String baseDir) {
* @return the builder
*/
public DomainCommandBuilder setBaseDirectory(final Path baseDir) {
this.baseDir = validateAndNormalizeDir(baseDir, true);
this.baseDir = Environment.validateAndNormalizeDir(baseDir, true);
return this;
}

Expand Down Expand Up @@ -711,7 +712,7 @@ public List<String> buildArguments() {
if (environment.getJvm().isModular()) {
cmd.addAll(DEFAULT_MODULAR_VM_ARGUMENTS);
for (final String optionalModularArgument : OPTIONAL_DEFAULT_MODULAR_VM_ARGUMENTS) {
if (environment.getJvm().isPackageAvailable(environment.getJvm().getPath(), optionalModularArgument)) {
if (Jvm.isPackageAvailable(environment.getJvm().getPath(), optionalModularArgument)) {
cmd.add(optionalModularArgument);
}
}
Expand All @@ -729,7 +730,7 @@ public List<String> buildArguments() {
}
cmd.add("-mp");
cmd.add(getModulePaths());
cmd.add("org.jboss.as.process-controller");
cmd.add(MODULE_NAME);
cmd.add("-jboss-home");
cmd.add(getWildFlyHome().toString());
cmd.add("-jvm");
Expand All @@ -747,7 +748,7 @@ public List<String> buildArguments() {
if (hostControllerJvm.isModular()) {
cmd.addAll(DEFAULT_MODULAR_VM_ARGUMENTS);
for (final String optionalModularArgument : OPTIONAL_DEFAULT_MODULAR_VM_ARGUMENTS) {
if (environment.getJvm().isPackageAvailable(environment.getJvm().getPath(), optionalModularArgument)) {
if (Jvm.isPackageAvailable(environment.getJvm().getPath(), optionalModularArgument)) {
cmd.add(optionalModularArgument);
}
}
Expand All @@ -767,14 +768,6 @@ public List<String> buildArguments() {
return cmd;
}

@Override
public List<String> build() {
final List<String> cmd = new ArrayList<>();
cmd.add(environment.getJvm().getCommand());
cmd.addAll(buildArguments());
return cmd;
}

@Override
public Path getJavaHome() {
return environment.getJvm().getPath();
Expand Down
23 changes: 21 additions & 2 deletions launcher/src/main/java/org/wildfly/core/launcher/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ static Path validateJar(final Path jarPath) {
if (Files.isDirectory(jarPath)) {
throw LauncherMessages.MESSAGES.pathNotAFile(jarPath);
}
final Path result = jarPath.toAbsolutePath().normalize();
return result;
return jarPath.toAbsolutePath().normalize();
}

static Path validateJar(final String jarPath) {
Expand All @@ -241,4 +240,24 @@ static Path validateJar(final String jarPath) {
}
return validateJar(Paths.get(jarPath));
}

@SuppressWarnings("SameParameterValue")
static Path validateAndNormalizeDir(final String path, final boolean allowNull) {
if (path == null) {
if (allowNull) return null;
throw LauncherMessages.MESSAGES.pathDoesNotExist(null);
}
return validateAndNormalizeDir(Paths.get(path), allowNull);
}

static Path validateAndNormalizeDir(final Path path, final boolean allowNull) {
if (allowNull && path == null) return null;
if (path == null || Files.notExists(path)) {
throw LauncherMessages.MESSAGES.pathDoesNotExist(path);
}
if (!Files.isDirectory(path)) {
throw LauncherMessages.MESSAGES.invalidDirectory(path);
}
return path.toAbsolutePath().normalize();
}
}
Loading