launchType(final ModelControllerClient client) {
* }
*
*
- * @param commandBuilder the command builder used to start the server
- * @param configuration the configuration used for starting and managing the server
+ * @param configuration the configuration used for starting and managing the server
*
* @return the server manager
*
* @throws ServerStartException if an error occurs starting the server
*/
- static StandaloneManager start(final StandaloneCommandBuilder commandBuilder,
- final Configuration configuration) throws ServerStartException {
- final Launcher launcher = Launcher.of(commandBuilder)
- .inherit();
+ static StandaloneManager start(final StandaloneConfiguration configuration) throws ServerStartException {
Process process = null;
try {
- process = launcher.launch();
- return new Builder(configuration).process(process).standalone();
- } catch (Throwable t) {
- if (process != null) {
- process.destroyForcibly();
+ process = configuration.launcher().launch();
+ if (configuration.consumeStderr()) {
+ ConsoleConsumer.start(process.getErrorStream(), System.err);
+ }
+ if (configuration.consumeStdout()) {
+ ConsoleConsumer.start(process.getInputStream(), System.out);
}
- throw new ServerStartException(commandBuilder, t);
- }
- }
-
- /**
- * Starts a standalone server based on the {@link BootableJarCommandBuilder command builder} and waits until the
- * server is started.
- *
- *
- * final ServerManager serverManager = ServerManager.start(BootableJarCommandBuilder.of("web-app-bootable.jar"));
- * if (!serverManager.waitFor(10L, TimeUnit.SECONDS)) {
- * serverManager.kill();
- * throw new RuntimeException("Failed to start bootable JAR");
- * }
- *
- *
- * @param commandBuilder the command builder used to start the server
- * @param configuration the configuration used for starting and managing the server
- *
- * @return the server manager
- *
- * @throws ServerStartException if an error occurs starting the server
- */
- static StandaloneManager start(final BootableJarCommandBuilder commandBuilder,
- final Configuration configuration) throws ServerStartException {
- final Launcher launcher = Launcher.of(commandBuilder)
- .inherit();
- Process process = null;
- try {
- process = launcher.launch();
return new Builder(configuration).process(process).standalone();
} catch (Throwable t) {
if (process != null) {
process.destroyForcibly();
}
- throw new ServerStartException(commandBuilder, t);
+ throw new ServerStartException(configuration, t);
}
}
@@ -394,26 +360,29 @@ static StandaloneManager start(final BootableJarCommandBuilder commandBuilder,
* }
*
*
- * @param commandBuilder the command builder used to start the server
- * @param configuration the configuration used for starting and managing the server
+ * @param configuration the configuration used for starting and managing the server
*
* @return the server manager
*
* @throws ServerStartException if an error occurs starting the server
*/
- static DomainManager start(final DomainCommandBuilder commandBuilder, final Configuration configuration)
+ static DomainManager start(final DomainConfiguration configuration)
throws ServerStartException {
- final Launcher launcher = Launcher.of(commandBuilder)
- .inherit();
Process process = null;
try {
- process = launcher.launch();
+ process = configuration.launcher().launch();
+ if (configuration.consumeStderr()) {
+ ConsoleConsumer.start(process.getErrorStream(), System.err);
+ }
+ if (configuration.consumeStdout()) {
+ ConsoleConsumer.start(process.getInputStream(), System.out);
+ }
return new Builder(configuration).process(process).domain();
} catch (Throwable t) {
if (process != null) {
process.destroyForcibly();
}
- throw new ServerStartException(commandBuilder, t);
+ throw new ServerStartException(configuration, t);
}
}
diff --git a/src/main/java/org/wildfly/plugin/tools/server/ServerStartException.java b/src/main/java/org/wildfly/plugin/tools/server/ServerStartException.java
index 53bb603..75a82cb 100644
--- a/src/main/java/org/wildfly/plugin/tools/server/ServerStartException.java
+++ b/src/main/java/org/wildfly/plugin/tools/server/ServerStartException.java
@@ -5,27 +5,21 @@
package org.wildfly.plugin.tools.server;
-import org.wildfly.core.launcher.CommandBuilder;
-
/**
* Represents a failure when attempting to start a server.
*
* @author James R. Perkins
*/
public class ServerStartException extends RuntimeException {
- private final CommandBuilder commandBuilder;
- ServerStartException(final CommandBuilder commandBuilder, final Throwable cause) {
- super("Failed to start server with command: " + commandBuilder.buildArguments(), cause);
- this.commandBuilder = commandBuilder;
+ ServerStartException(final Configuration configuration, final Throwable cause) {
+ super(createMessage(configuration), cause);
}
- /**
- * The command builder used which caused a boot failure.
- *
- * @return the command builder which failed to boot
- */
- public CommandBuilder getCommandBuilder() {
- return commandBuilder;
+ private static String createMessage(final Configuration configuration) {
+ if (configuration.commandBuilder() != null) {
+ return "Failed to start server with command: " + configuration.commandBuilder().build();
+ }
+ return String.format("Failed to start %s server.", configuration.launchType().name().toLowerCase());
}
}
diff --git a/src/main/java/org/wildfly/plugin/tools/server/StandaloneConfiguration.java b/src/main/java/org/wildfly/plugin/tools/server/StandaloneConfiguration.java
new file mode 100644
index 0000000..9a8b034
--- /dev/null
+++ b/src/main/java/org/wildfly/plugin/tools/server/StandaloneConfiguration.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright The WildFly Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.wildfly.plugin.tools.server;
+
+import org.wildfly.core.launcher.CommandBuilder;
+
+/**
+ * Represents the configuration used to boot a standalone server.
+ *
+ * @author James R. Perkins
+ */
+public class StandaloneConfiguration extends Configuration {
+ protected StandaloneConfiguration(final CommandBuilder commandBuilder) {
+ super(commandBuilder);
+ }
+
+ @Override
+ protected LaunchType launchType() {
+ return LaunchType.STANDALONE;
+ }
+
+ @Override
+ protected StandaloneConfiguration self() {
+ return this;
+ }
+}
diff --git a/src/test/java/org/wildfly/plugin/tools/Environment.java b/src/test/java/org/wildfly/plugin/tools/Environment.java
index 8614f22..c07adbd 100644
--- a/src/test/java/org/wildfly/plugin/tools/Environment.java
+++ b/src/test/java/org/wildfly/plugin/tools/Environment.java
@@ -151,8 +151,8 @@ public static StandaloneManager launchStandalone() {
}
public static StandaloneManager launchStandalone(final boolean shutdownOnClose) {
- final StandaloneManager serverManager = ServerManager.start(StandaloneCommandBuilder.of(Environment.WILDFLY_HOME),
- Configuration.create()
+ final StandaloneManager serverManager = ServerManager
+ .start(Configuration.create(StandaloneCommandBuilder.of(Environment.WILDFLY_HOME))
.shutdownOnClose(shutdownOnClose)
.managementAddress(HOSTNAME)
.managementPort(PORT));
@@ -168,8 +168,8 @@ public static StandaloneManager launchStandalone(final boolean shutdownOnClose)
}
public static DomainManager launchDomain() {
- final DomainManager serverManager = ServerManager.start(DomainCommandBuilder.of(Environment.WILDFLY_HOME),
- Configuration.create()
+ final DomainManager serverManager = ServerManager
+ .start(Configuration.create(DomainCommandBuilder.of(Environment.WILDFLY_HOME))
.shutdownOnClose(true)
.managementAddress(HOSTNAME)
.managementPort(PORT));