use of org.wildfly.core.launcher.Launcher in project wildfly-maven-plugin by wildfly.
the class RunMojo method startContainer.
private Process startContainer(final CommandBuilder commandBuilder) throws IOException, InterruptedException, TimeoutException {
final Launcher launcher = Launcher.of(commandBuilder).inherit();
if (env != null) {
launcher.addEnvironmentVariables(env);
}
final Process process = launcher.launch();
try (ModelControllerClient client = createClient()) {
ServerHelper.waitForStandalone(process, client, startupTimeout);
}
return process;
}
use of org.wildfly.core.launcher.Launcher in project wildfly-maven-plugin by wildfly.
the class StartMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
final Log log = getLog();
if (skip) {
log.debug("Skipping server start");
return;
}
MavenRepositoriesEnricher.enrich(mavenSession, project, repositories);
mavenRepoManager = new MavenArtifactRepositoryManager(repoSystem, session, repositories);
// Validate the environment
final Path jbossHome = provisionIfRequired(targetDir.toPath().resolve(provisioningDir));
if (!ServerHelper.isValidHomeDirectory(jbossHome)) {
throw new MojoExecutionException(String.format("JBOSS_HOME '%s' is not a valid directory.", jbossHome));
}
// Determine how stdout should be consumed
try {
final StandardOutput out = StandardOutput.parse(stdout, true);
// the maven process may have been finished
try (ModelControllerClient client = createClient()) {
if (ServerHelper.isStandaloneRunning(client) || ServerHelper.isDomainRunning(client)) {
throw new MojoExecutionException(String.format("%s server is already running?", serverType));
}
final CommandBuilder commandBuilder = createCommandBuilder(jbossHome);
log.info(String.format("%s server is starting up.", serverType));
final Launcher launcher = Launcher.of(commandBuilder).setRedirectErrorStream(true);
if (env != null) {
launcher.addEnvironmentVariables(env);
}
out.getRedirect().ifPresent(launcher::redirectOutput);
final Process process = launcher.launch();
// Note that if this thread is started and no shutdown goal is executed this stop the stdout and stderr
// from being logged any longer. The user was warned in the documentation.
out.startConsumer(process);
if (serverType == ServerType.DOMAIN) {
ServerHelper.waitForDomain(process, DomainClient.Factory.create(client), startupTimeout);
} else {
ServerHelper.waitForStandalone(process, client, startupTimeout);
}
if (!process.isAlive()) {
throw new MojoExecutionException("The process has been terminated before the start goal has completed.");
}
}
} catch (MojoExecutionException e) {
throw e;
} catch (Exception e) {
throw new MojoExecutionException("The server failed to start", e);
}
}
use of org.wildfly.core.launcher.Launcher in project wildfly-maven-plugin by wildfly.
the class AbstractCommandExecutor method launchProcess.
protected int launchProcess(CliCommandBuilder builder, final T config, final StandardOutput stdout) throws MojoExecutionException, IOException {
final Logger log = getLogger();
final Launcher launcher = Launcher.of(builder).addEnvironmentVariable("JBOSS_HOME", config.getJBossHome().toString()).setRedirectErrorStream(true);
stdout.getRedirect().ifPresent(launcher::redirectOutput);
final Process process = launcher.launch();
final Optional<Thread> consoleConsumer = stdout.startConsumer(process);
try {
return process.waitFor();
} catch (InterruptedException e) {
throw new MojoExecutionException("Failed to run goal execute-commands in forked process.", e);
} finally {
// Be safe and destroy the process to ensure we don't leave rouge processes running
if (process.isAlive()) {
process.destroyForcibly();
}
consoleConsumer.ifPresent(Thread::interrupt);
}
}
Aggregations