- java.lang.Object
-
- org.wildfly.core.launcher.Launcher
-
public class Launcher extends Object
Builds aprocess
to launch a standalone or domain server based on thecommand builder
. The process is only created by the launcher and not managed. It's the responsibility of the consumer to manage the process.- Author:
- James R. Perkins
-
-
Constructor Summary
Constructors Constructor Description Launcher(CommandBuilder builder)
Creates a new launcher.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Launcher
addEnvironmentVariable(String key, String value)
Adds an environment variable to the process being created.Launcher
addEnvironmentVariables(Map<String,String> env)
Adds the environment variables to the process being created.Launcher
inherit()
Sets the output and error streams to inherit the output and error streams from it's parent process.Process
launch()
Launches a new process based on the commands from thebuilder
.static Launcher
of(CommandBuilder builder)
Creates a new launcher to create aprocess
based on the command builder.Launcher
redirectError(File file)
Redirects the error stream of the process to a file.Launcher
redirectError(ProcessBuilder.Redirect destination)
Redirects the error stream of the process to the destination provided.Launcher
redirectOutput(File file)
Redirects the output of the process to a file.Launcher
redirectOutput(ProcessBuilder.Redirect destination)
Redirects the output of the process to the destination provided.Launcher
redirectOutput(Path path)
Redirects the output of the process to a file.Launcher
setDirectory(File dir)
Sets the working directory for the process created.Launcher
setDirectory(String dir)
Sets the working directory for the process created.Launcher
setDirectory(Path path)
Sets the working directory for the process created.Launcher
setRedirectErrorStream(boolean redirectErrorStream)
Set totrue
if the error stream should be redirected to the output stream.
-
-
-
Constructor Detail
-
Launcher
public Launcher(CommandBuilder builder)
Creates a new launcher.- Parameters:
builder
- the builder to build the list of commands
-
-
Method Detail
-
of
public static Launcher of(CommandBuilder builder)
Creates a new launcher to create aprocess
based on the command builder.- Parameters:
builder
- the builder used to launch the process- Returns:
- the newly created launcher
-
inherit
public Launcher inherit()
Sets the output and error streams to inherit the output and error streams from it's parent process.- Returns:
- the launcher
-
setRedirectErrorStream
public Launcher setRedirectErrorStream(boolean redirectErrorStream)
Set totrue
if the error stream should be redirected to the output stream.- Parameters:
redirectErrorStream
-true
to merge the error stream into the output stream, otherwisefalse
to keep the streams separate- Returns:
- the launcher
-
redirectOutput
public Launcher redirectOutput(File file)
Redirects the output of the process to a file.- Parameters:
file
- the file to redirect the output to- Returns:
- the launcher
- See Also:
ProcessBuilder.Redirect.to(java.io.File)
-
redirectOutput
public Launcher redirectOutput(Path path)
Redirects the output of the process to a file.- Parameters:
path
- the path to redirect the output to- Returns:
- the launcher
- See Also:
ProcessBuilder.Redirect.to(java.io.File)
-
redirectOutput
public Launcher redirectOutput(ProcessBuilder.Redirect destination)
Redirects the output of the process to the destination provided.- Parameters:
destination
- the output destination- Returns:
- the launcher
- See Also:
ProcessBuilder.redirectOutput(java.lang.ProcessBuilder.Redirect)
-
redirectError
public Launcher redirectError(File file)
Redirects the error stream of the process to a file.- Parameters:
file
- the file to redirect the error stream to- Returns:
- the launcher
- See Also:
ProcessBuilder.Redirect.to(java.io.File)
-
redirectError
public Launcher redirectError(ProcessBuilder.Redirect destination)
Redirects the error stream of the process to the destination provided.- Parameters:
destination
- the error stream destination- Returns:
- the launcher
- See Also:
ProcessBuilder.redirectError(java.lang.ProcessBuilder.Redirect)
-
setDirectory
public Launcher setDirectory(Path path)
Sets the working directory for the process created.- Parameters:
path
- the path to the working directory- Returns:
- the launcher
- See Also:
ProcessBuilder.directory(java.io.File)
-
setDirectory
public Launcher setDirectory(File dir)
Sets the working directory for the process created.- Parameters:
dir
- the working directory- Returns:
- the launcher
- See Also:
ProcessBuilder.directory(java.io.File)
-
setDirectory
public Launcher setDirectory(String dir)
Sets the working directory for the process created.- Parameters:
dir
- the working directory- Returns:
- the launcher
- See Also:
ProcessBuilder.directory(java.io.File)
-
addEnvironmentVariable
public Launcher addEnvironmentVariable(String key, String value)
Adds an environment variable to the process being created. If the key or value isnull
, the environment variable will not be added.- Parameters:
key
- they key for the variablevalue
- the value for the variable- Returns:
- the launcher
- See Also:
ProcessBuilder.environment()
-
addEnvironmentVariables
public Launcher addEnvironmentVariables(Map<String,String> env)
Adds the environment variables to the process being created. Note thatnull
keys or values will not be added.- Parameters:
env
- the environment variables to add- Returns:
- the launcher
- See Also:
ProcessBuilder.environment()
-
launch
public Process launch() throws IOException
Launches a new process based on the commands from thebuilder
.- Returns:
- the newly created process
- Throws:
IOException
- if an error occurs launching the process
-
-