Search in sources :

Example 6 with Executor

use of org.apache.commons.exec.Executor in project ddf by codice.

the class VideoThumbnailPlugin method executeFFmpeg.

private DefaultExecuteResultHandler executeFFmpeg(final CommandLine command, final int timeoutSeconds, final PumpStreamHandler streamHandler) throws IOException {
    final ExecuteWatchdog watchdog = new ExecuteWatchdog(timeoutSeconds * 1000L);
    final Executor executor = new DefaultExecutor();
    final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
    if (streamHandler != null) {
        executor.setStreamHandler(streamHandler);
    }
    executor.setWatchdog(watchdog);
    executeWithPrivilege(command, executor, resultHandler);
    return resultHandler;
}
Also used : Executor(org.apache.commons.exec.Executor) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) DefaultExecuteResultHandler(org.apache.commons.exec.DefaultExecuteResultHandler) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) ExecuteWatchdog(org.apache.commons.exec.ExecuteWatchdog)

Example 7 with Executor

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

the class EngineControl method executeSynch.

/**
 * Run a short living engine command where we expect a process failure as the engine invokes <code>System.exit(-1)</code>.
 * @param statusCmd
 * @return the output of the engine command.
 */
@SuppressWarnings("deprecation")
private String executeSynch(CommandLine statusCmd) {
    String engineOutput = null;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, System.err);
    Executor executor = createEngineExecutor();
    executor.setStreamHandler(streamHandler);
    executor.setExitValue(-1);
    try {
        executor.execute(statusCmd);
    } catch (IOException ex) {
    // expected!
    } finally {
        engineOutput = outputStream.toString();
        IOUtils.closeQuietly(outputStream);
    }
    return engineOutput;
}
Also used : PumpStreamHandler(org.apache.commons.exec.PumpStreamHandler) Executor(org.apache.commons.exec.Executor) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 8 with Executor

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

the class TestStartEngine method startEngine_copiedEngine_executable.

@Test
public void startEngine_copiedEngine_executable() throws Exception {
    StartTestEngineMojo mojo = rule.getMojo();
    mojo.testEngine = TestEngineLocation.COPY_FROM_TEMPLATE;
    Executor startedProcess = null;
    try {
        File cacheEngine = mojo.engineDirectory;
        assertFileExecutable(new File(cacheEngine, "elasticsearch/bin/elasticsearch"));
        assertFileExecutable(new File(cacheEngine, "elasticsearch/bin/elasticsearch.bat"));
        startedProcess = mojo.startEngine();
        File engineTarget = mojo.getEngineDir(mojo.project);
        assertFileExecutable(new File(engineTarget, "elasticsearch/bin/elasticsearch"));
        assertFileExecutable(new File(engineTarget, "elasticsearch/bin/elasticsearch.bat"));
    } finally {
        kill(startedProcess);
    }
}
Also used : Executor(org.apache.commons.exec.Executor) File(java.io.File) BaseEngineProjectMojoTest(ch.ivyteam.ivy.maven.BaseEngineProjectMojoTest) Test(org.junit.Test)

Example 9 with Executor

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

the class TestStartEngine method startEngine_copyEngineToTarget.

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

Example 10 with Executor

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

the class TestStartEngine method testKillEngineOnVmExit.

@Test
public void testKillEngineOnVmExit() throws Exception {
    StartTestEngineMojo mojo = rule.getMojo();
    Executor startedProcess = null;
    try {
        startedProcess = mojo.startEngine();
        assertThat(startedProcess.getProcessDestroyer()).isInstanceOf(ShutdownHookProcessDestroyer.class);
        ShutdownHookProcessDestroyer jvmShutdownHoock = (ShutdownHookProcessDestroyer) startedProcess.getProcessDestroyer();
        assertThat(jvmShutdownHoock.size()).as("One started engine process must be killed on VM end.").isEqualTo(1);
    } finally {
        kill(startedProcess);
    }
}
Also used : Executor(org.apache.commons.exec.Executor) ShutdownHookProcessDestroyer(org.apache.commons.exec.ShutdownHookProcessDestroyer) BaseEngineProjectMojoTest(ch.ivyteam.ivy.maven.BaseEngineProjectMojoTest) Test(org.junit.Test)

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