Search in sources :

Example 1 with Launcher

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;
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) Launcher(org.wildfly.core.launcher.Launcher)

Example 2 with Launcher

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);
    }
}
Also used : Path(java.nio.file.Path) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) Log(org.apache.maven.plugin.logging.Log) MavenArtifactRepositoryManager(org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager) Launcher(org.wildfly.core.launcher.Launcher) StandardOutput(org.wildfly.plugin.common.StandardOutput) DomainCommandBuilder(org.wildfly.core.launcher.DomainCommandBuilder) StandaloneCommandBuilder(org.wildfly.core.launcher.StandaloneCommandBuilder) CommandBuilder(org.wildfly.core.launcher.CommandBuilder) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 3 with Launcher

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Launcher(org.wildfly.core.launcher.Launcher) Logger(org.codehaus.plexus.logging.Logger)

Aggregations

Launcher (org.wildfly.core.launcher.Launcher)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 Log (org.apache.maven.plugin.logging.Log)1 Logger (org.codehaus.plexus.logging.Logger)1 ProvisioningException (org.jboss.galleon.ProvisioningException)1 MavenArtifactRepositoryManager (org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager)1 CommandBuilder (org.wildfly.core.launcher.CommandBuilder)1 DomainCommandBuilder (org.wildfly.core.launcher.DomainCommandBuilder)1 StandaloneCommandBuilder (org.wildfly.core.launcher.StandaloneCommandBuilder)1 StandardOutput (org.wildfly.plugin.common.StandardOutput)1