All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.openhft.chronicle.testframework.process.ProcessRunner Maven / Gradle / Ivy

There is a newer version: 2.26ea0
Show newest version
package net.openhft.chronicle.testframework.process;

import net.openhft.chronicle.testframework.internal.process.InternalProcessRunner;

import java.io.IOException;

import static java.util.Objects.requireNonNull;

public final class ProcessRunner {

    private ProcessRunner() {
        // Suppresses default constructor, ensuring non-instantiability.
    }

    /**
     * Spawn a process running the main method of a specified class
     *
     * @param clazz The class to execute
     * @param args  Any arguments to pass to the process
     * @return the Process spawned
     * @throws IOException if there is an error starting the process
     */
    public static Process runClass(Class clazz, String... args) throws IOException {
        requireNonNull(clazz);
        requireNonNull(args);
        return runClass(clazz, new String[]{}, args);
    }

    /**
     * Spawn a process running the main method of a specified class with custom JVM args
     *
     * @param clazz       The class to execute
     * @param jvmArgs     Any JVM arguments to pass to the process
     * @param programArgs Any arguments to pass to the process
     * @return the Process spawned
     * @throws IOException if there is an error starting the process
     */
    public static Process runClass(Class clazz, String[] jvmArgs, String[] programArgs) throws IOException {
        requireNonNull(clazz);
        requireNonNull(jvmArgs);
        requireNonNull(programArgs);
        return InternalProcessRunner.runClass(clazz, jvmArgs, programArgs, null);
    }

    /**
     * Spawn a process running the main method of a specified class with custom JVM args and classpath
     *
     * @param clazz       The class to execute
     * @param jvmArgs     Any JVM arguments to pass to the process
     * @param programArgs Any arguments to pass to the process
     * @param classPath   Classpath entries for the process
     * @return the Process spawned
     * @throws IOException if there is an error starting the process
     */
    public static Process runClass(Class clazz, String[] jvmArgs, String[] programArgs, String[] classPath) throws IOException {
        requireNonNull(clazz);
        requireNonNull(jvmArgs);
        requireNonNull(programArgs);
        requireNonNull(classPath);
        return InternalProcessRunner.runClass(clazz, jvmArgs, programArgs, classPath);
    }

    /**
     * Log stdout and stderr for a process
     * 

* ProcessBuilder.inheritIO() didn't play nicely with Maven failsafe plugin *

* https://maven.apache.org/surefire/maven-failsafe-plugin/faq.html#corruptedstream */ public static void printProcessOutput(String processName, Process process) { requireNonNull(processName); requireNonNull(process); InternalProcessRunner.printProcessOutput(processName, process); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy