Class JkAbstractProcess<T extends JkAbstractProcess>
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
JkDocker,JkGit,JkJavaProcess,JkMvn,JkProcess
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds specified parameters to the command lineaddParams(Collection<String> parameters) Adds the specified parameters to the command line.addParamsAsCmdLine(String cmdLine, Object... tokens) Adds the specified parameters as a space separated args to the command line.addParamsAt(int index, String... parameters) Adds the specified parameters to the command line at the beginning of the list.addParamsAt(int index, Collection<String> parameters) Adds the specified parameters to the command line at the beginning of the list.addParamsIf(boolean condition, String... parameters) Adds specified parameters to the command line if the specified condition is true.protected Tcopy()protected voidModifies the command and its execution parameters.exec()Starts this process and wait for the process has finished prior returning.Executes the process asynchronously and returns aJkProcHandlerobject which can be used to interact with the running process.Executes a command with the specified parameters and returns the current instance.execCmdLine(String format, String... tokens) getParamAt(int index) Returns the command launched by this process.Returns the working directory of this process.Adds a param -lv=[DecoratorStyle] matching the current one.booleanReturnstrueif this process must throw an execption if the underlying process returns code different from 0.redirectErrorStream(boolean value) removeParam(String parameter) Removes specified parameter to the command linevoidrun()setCollectStderr(boolean collectStderr) Sets the flag to indicate whether the std err of the process should be collected.setCollectStdout(boolean collectStdout) Sets the flag to indicate whether the std out of the process should be collected.setDestroyAtJvmShutdown(boolean destroy) Sets the flag to destroy the process at JVM shutdown.Sets the value of the environment variable with the specified name.setFailOnError(boolean fail) Specifies if the running process should throw an Exception in case process returns with a code different to 0.setInheritIO(boolean value) Makes the process use the same streams as its parent.setLogCommand(boolean logCommand) If true, the command line will be outputed in the consolesetLogWithJekaDecorator(boolean logOutputWithLogDecorator) Set if the output streams of the process must be logged keeping the JkLog decorator.setParamAt(int index, String parameter) Specify the command to executesetWorkingDir(String workingDir) Sets the specified working directory to launch the process.setWorkingDir(Path workingDir) Sets the specified working directory to launch the process.toString()
-
Field Details
-
CURRENT_JAVA_DIR
-
-
Constructor Details
-
JkAbstractProcess
protected JkAbstractProcess() -
JkAbstractProcess
-
-
Method Details
-
copy
-
setParamAt
Specify the command to execute -
setCollectStdout
Sets the flag to indicate whether the std out of the process should be collected.This is mandatory to collect output if we want to get the get the
JkProcResult.getStdout()after process execution.Initial value is
false. -
setCollectStderr
Sets the flag to indicate whether the std err of the process should be collected.This is mandatory to collect output if we want to get the get the
JkProcResult.getStdout()after process execution.Initial value is
false. -
setDestroyAtJvmShutdown
Sets the flag to destroy the process at JVM shutdown. -
addParamsAsCmdLine
Adds the specified parameters as a space separated args to the command line. The string will be parsed in an array of parameters.- Parameters:
cmdLine- the parameters as a string (e.g '-X -e run').tokens- If command line contains tokens as '%s', they are replaced by these tokens.
-
addParams
Adds specified parameters to the command line -
removeParam
Removes specified parameter to the command line -
addParamsIf
Adds specified parameters to the command line if the specified condition is true. -
addParams
Adds the specified parameters to the command line.- See Also:
-
addParamsAt
Adds the specified parameters to the command line at the beginning of the list. Any null values in the parameters collection will be removed before adding. -
addParamsAt
Adds the specified parameters to the command line at the beginning of the list.- See Also:
-
setWorkingDir
Sets the specified working directory to launch the process. -
setWorkingDir
Sets the specified working directory to launch the process.- See Also:
-
setEnv
Sets the value of the environment variable with the specified name.- Parameters:
name- the name of the environment variablevalue- the value to be assigned to the environment variable
-
setFailOnError
Specifies if the running process should throw an Exception in case process returns with a code different to 0.Initial value is 'true'.
-
setLogCommand
If true, the command line will be outputed in the console -
setLogWithJekaDecorator
Set if the output streams of the process must be logged keeping the JkLog decorator.This may be desirable, as the output will honor the indentation and visibility set by JeKa log decorator. This implies a small extra resource costs that is acceptable in most of the situations.
Be aware that the stdout and stderr of the sub-process will be mixed in the
Process.getInputStream()as specified in this method Javadoc.Nevertheless, if you want to bypass this mechanism, you can specify to not using it. In this case, you may set up explicitly a mean to get the output streams. One solution consists in invoking
setInheritIO(true)Initial value is
true.. -
setInheritIO
Makes the process use the same streams as its parent.This can not be used in conjunction of
logWithJekaDecorator, so this one is disabled forcibly when invoking this method.
Initial value isfalse- See Also:
-
inheritJkLogOptions
Adds a param -lv=[DecoratorStyle] matching the current one. -
redirectErrorStream
Same asProcessBuilder.redirectErrorStream(boolean).Initial value is false.
-
getWorkingDir
Returns the working directory of this process. -
getParamAt
Returns the command launched by this process. -
getParams
-
isFailOnError
public boolean isFailOnError()Returnstrueif this process must throw an execption if the underlying process returns code different from 0. -
toString
-
customizeCommand
protected void customizeCommand()Modifies the command and its execution parameters.This method provides a way for subclasses to adjust the process before it is run.
-
run
public void run() -
exec
Starts this process and wait for the process has finished prior returning. The output of the created process will be redirected on the current output. -
execCmd
Executes a command with the specified parameters and returns the current instance. This method uses a clone of the current instance's configuration to execute a command.- Parameters:
commandParams- The parameters to be added to the command being executed.- Returns:
- The current instance after executing the command.
-
execCmdLine
- See Also:
-
execAsync
Executes the process asynchronously and returns aJkProcHandlerobject which can be used to interact with the running process.
-