Search in sources :

Example 21 with Executor

use of org.apache.commons.exec.Executor in project project-build-plugin by axonivy.

the class EngineControl method start.

public Executor start() throws Exception {
    CommandLine startCmd = toEngineCommand(Command.start);
    context.log.info("Start Axon Ivy Engine in folder: " + context.engineDirectory);
    Executor executor = createEngineExecutor();
    executor.setStreamHandler(createEngineLogStreamForwarder(logLine -> findStartEngineUrl(logLine)));
    executor.setWatchdog(new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT));
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
    executor.execute(startCmd, asynchExecutionHandler());
    waitForEngineStart(executor);
    return executor;
}
Also used : Executor(org.apache.commons.exec.Executor) ExecuteWatchdog(org.apache.commons.exec.ExecuteWatchdog) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BodyHandlers(java.net.http.HttpResponse.BodyHandlers) LineOrientedOutputStreamRedirector(ch.ivyteam.ivy.maven.util.stream.LineOrientedOutputStreamRedirector) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CommandLine(org.apache.commons.exec.CommandLine) Supplier(java.util.function.Supplier) StringUtils(org.apache.commons.lang3.StringUtils) HttpRequest(java.net.http.HttpRequest) ShutdownHookProcessDestroyer(org.apache.commons.exec.ShutdownHookProcessDestroyer) HttpClient(java.net.http.HttpClient) URI(java.net.URI) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) ExecuteException(org.apache.commons.exec.ExecuteException) HttpResponse(java.net.http.HttpResponse) OutputStream(java.io.OutputStream) StartTestEngineMojo(ch.ivyteam.ivy.maven.test.StartTestEngineMojo) Redirect(java.net.http.HttpClient.Redirect) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) OsgiDir(ch.ivyteam.ivy.maven.engine.EngineClassLoaderFactory.OsgiDir) StopWatch(org.apache.commons.lang3.time.StopWatch) ExecuteResultHandler(org.apache.commons.exec.ExecuteResultHandler) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) PumpStreamHandler(org.apache.commons.exec.PumpStreamHandler) IOUtils(org.apache.commons.io.IOUtils) CommandLine(org.apache.commons.exec.CommandLine) Executor(org.apache.commons.exec.Executor) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) ExecuteWatchdog(org.apache.commons.exec.ExecuteWatchdog) ShutdownHookProcessDestroyer(org.apache.commons.exec.ShutdownHookProcessDestroyer)

Example 22 with Executor

use of org.apache.commons.exec.Executor in project project-build-plugin by axonivy.

the class TestDeployToRunningEngine method deployIarRemoteAndAssert.

private void deployIarRemoteAndAssert() throws Exception, MojoExecutionException, MojoFailureException {
    deployMojo.deployToEngineApplication = "test";
    deployMojo.deployMethod = DeployMethod.HTTP;
    Executor startedProcess = null;
    try {
        System.setOut(originalOut);
        startedProcess = mojo.startEngine();
        deployMojo.deployEngineUrl = (String) rule.project.getProperties().get(EngineControl.Property.TEST_ENGINE_URL);
        System.setOut(new PrintStream(outContent));
        deployMojo.execute();
        assertThat(outContent.toString()).contains("Start deploying project(s) of file").contains("Application: test").contains("Deploying users ...").doesNotContain("deployDirectory is set but will not be used for HTTP Deployment.");
    } finally {
        kill(startedProcess);
    }
}
Also used : PrintStream(java.io.PrintStream) Executor(org.apache.commons.exec.Executor)

Example 23 with Executor

use of org.apache.commons.exec.Executor in project project-build-plugin by axonivy.

the class TestDeployToRunningEngine method canDeployIar.

@Test
public void canDeployIar() throws Exception {
    deployMojo.deployToEngineApplication = "Portal";
    File deployedIar = getTarget(deployMojo.deployFile, deployMojo);
    File deployedIarFlagFile = new File(deployedIar.getParent(), deployedIar.getName() + ".deployed");
    File deployedIarLogFile = new File(deployedIar.getParent(), deployedIar.getName() + ".deploymentLog");
    Executor startedProcess = null;
    try {
        startedProcess = mojo.startEngine();
        deployMojo.execute();
        assertThat(deployedIar).doesNotExist();
        assertThat(deployedIarFlagFile).exists();
        assertThat(deployedIarLogFile).exists();
        assertThat(linesOf(deployedIarLogFile)).haveAtLeast(1, new Condition<>(s -> s.contains("Deploying users ..."), ""));
    } finally {
        kill(startedProcess);
    }
}
Also used : PrintStream(java.io.PrintStream) Executor(org.apache.commons.exec.Executor) StartTestEngineMojo(ch.ivyteam.ivy.maven.test.StartTestEngineMojo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Server(org.apache.maven.settings.Server) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ProjectMojoRule(ch.ivyteam.ivy.maven.ProjectMojoRule) File(java.io.File) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Rule(org.junit.Rule) BaseEngineProjectMojoTest(ch.ivyteam.ivy.maven.BaseEngineProjectMojoTest) EngineControl(ch.ivyteam.ivy.maven.engine.EngineControl) After(org.junit.After) Condition(org.assertj.core.api.Condition) DeployMethod(ch.ivyteam.ivy.maven.deploy.DeployToEngineMojo.DeployMethod) Assertions.linesOf(org.assertj.core.api.Assertions.linesOf) Before(org.junit.Before) Executor(org.apache.commons.exec.Executor) File(java.io.File) Test(org.junit.Test) BaseEngineProjectMojoTest(ch.ivyteam.ivy.maven.BaseEngineProjectMojoTest)

Example 24 with Executor

use of org.apache.commons.exec.Executor in project project-build-plugin by axonivy.

the class TestStartEngine method startEngine_targetDirectoryNotClean.

@Test
public void startEngine_targetDirectoryNotClean() throws Exception {
    LogCollector log = new LogCollector();
    StartTestEngineMojo mojo = rule.getMojo();
    mojo.setLog(log);
    Executor startedProcess = null;
    try {
        File engineDirTarget = mojo.getEngineDir(mojo.project);
        assertThat(engineDirTarget.toString()).contains("/target/ivyEngine");
        assertThat(engineDirTarget).doesNotExist();
        assertThat(log.getWarnings().toString()).doesNotContain("Skipping copy");
        startedProcess = mojo.startEngine();
        assertThat(engineDirTarget).exists();
        assertThat(log.getWarnings().toString()).doesNotContain("Skipping copy");
        kill(startedProcess);
        startedProcess = mojo.startEngine();
        assertThat(engineDirTarget).exists();
        assertThat(log.getWarnings().toString()).contains("Skipping copy");
    } finally {
        kill(startedProcess);
    }
}
Also used : LogCollector(ch.ivyteam.ivy.maven.log.LogCollector) Executor(org.apache.commons.exec.Executor) File(java.io.File) BaseEngineProjectMojoTest(ch.ivyteam.ivy.maven.BaseEngineProjectMojoTest) Test(org.junit.Test)

Example 25 with Executor

use of org.apache.commons.exec.Executor in project oxCore by GluuFederation.

the class ProcessHelper method executeProgram.

/**
 * @param printJobTimeout
 *            the printJobTimeout (ms) before the watchdog terminates the print
 *            process
 * @param printInBackground
 *            printing done in the background or blocking
 * @param streamHandler
 * @return a print result handler (implementing a future)
 * @throws IOException
 *             the test failed
 */
public static PrintResultHandler executeProgram(CommandLine commandLine, String workingDirectory, long printJobTimeout, boolean printInBackground, int successExitValue, ExecuteStreamHandler streamHandler) throws IOException {
    ExecuteWatchdog watchdog = null;
    PrintResultHandler resultHandler;
    // Create the executor and consider the successExitValue as success
    Executor executor = new DefaultExecutor();
    executor.setExitValue(successExitValue);
    if (StringHelper.isNotEmpty(workingDirectory)) {
        executor.setWorkingDirectory(new File(workingDirectory));
    }
    // Redirect streams if needed
    if (streamHandler != null) {
        executor.setStreamHandler(streamHandler);
    }
    // Create a watchdog if requested
    if (printJobTimeout > 0) {
        watchdog = new ExecuteWatchdog(printJobTimeout);
        executor.setWatchdog(watchdog);
    }
    // Pass a "ExecuteResultHandler" when doing background printing
    if (printInBackground) {
        LOG.debug(String.format("Executing non-blocking process %s", commandLine.toString()));
        resultHandler = new PrintResultHandler(watchdog);
        executor.execute(commandLine, resultHandler);
    } else {
        LOG.debug(String.format("Executing blocking process %s", commandLine.toString()));
        successExitValue = executor.execute(commandLine);
        resultHandler = new PrintResultHandler(successExitValue);
    }
    return resultHandler;
}
Also used : Executor(org.apache.commons.exec.Executor) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) ExecuteWatchdog(org.apache.commons.exec.ExecuteWatchdog) File(java.io.File)

Aggregations

Executor (org.apache.commons.exec.Executor)27 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)16 File (java.io.File)12 CommandLine (org.apache.commons.exec.CommandLine)10 ExecuteWatchdog (org.apache.commons.exec.ExecuteWatchdog)10 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)10 Test (org.junit.Test)10 IOException (java.io.IOException)8 BaseEngineProjectMojoTest (ch.ivyteam.ivy.maven.BaseEngineProjectMojoTest)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DefaultExecuteResultHandler (org.apache.commons.exec.DefaultExecuteResultHandler)6 ExecuteException (org.apache.commons.exec.ExecuteException)6 ShutdownHookProcessDestroyer (org.apache.commons.exec.ShutdownHookProcessDestroyer)6 StartTestEngineMojo (ch.ivyteam.ivy.maven.test.StartTestEngineMojo)2 OutputStream (java.io.OutputStream)2 PrintStream (java.io.PrintStream)2 ExecuteResultHandler (org.apache.commons.exec.ExecuteResultHandler)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.linesOf (org.assertj.core.api.Assertions.linesOf)2