public class JkProcess<T extends JkProcess>
extends java.lang.Object
implements java.lang.Runnable, java.lang.Cloneable
Parameters of the command are passed as array (and not as single string
representing several parameter separated with whitespace).
So for example, if you want to create a Maven process, then you should write
JkProcess.of("mvn", "deleteArtifacts", "install")
instead of
JkProcess.of("mvn", "deleteArtifacts install")
or
JkProcess.of("mvn deleteArtifacts install")
Modifier | Constructor and Description |
---|---|
protected |
JkProcess(java.lang.String command,
java.lang.String... parameters) |
Modifier and Type | Method and Description |
---|---|
T |
addParams(java.util.Collection<java.lang.String> parameters) |
T |
addParams(java.lang.String... parameters)
Adds specified parameters to the command line
|
T |
addParamsFirst(java.util.Collection<java.lang.String> parameters) |
T |
addParamsFirst(java.lang.String... parameters) |
T |
addParamsIf(boolean condition,
java.lang.String... parameters)
Adds specified parameters to the command line if the specified condition is true.
|
T |
clone() |
int |
exec(java.lang.String... extraParams)
Starts this process and wait for the process has finished prior
returning.
|
java.util.List<java.lang.String> |
execAndReturnOutput(java.lang.String... extraParams) |
void |
execIf(boolean condition,
java.lang.String... extraParams)
Same as
exec(String...) ()} but only effective if the specified condition is true . |
java.lang.String |
getCommand()
Returns the command launched by this process.
|
java.util.List<java.lang.String> |
getParams() |
java.nio.file.Path |
getWorkingDir()
Returns the working directory of this process.
|
T |
inheritJkLogOptions()
Adds a param -lv=[DecoratorStyle] matching the current one.
|
boolean |
isFailOnError()
Returns
true if this process must throw an execption if the underlying process returns
code different than 0. |
static JkProcess<JkProcess> |
of(java.lang.String command,
java.lang.String... parameters)
Defines a
JkProcess using the specified command and
parameters. |
static JkProcess<JkProcess> |
ofCmdLine(java.lang.String commandLine) |
static JkProcess |
ofJavaTool(java.lang.String javaTool,
java.lang.String... parameters)
Defines a
JkProcess using the specified tool of the JDK and
parameters. |
static JkProcess<JkProcess> |
ofWinOrUx(java.lang.String windowsCommand,
java.lang.String unixCommand,
java.lang.String... parameters)
Defines a
JkProcess using the specified command and
parameters. |
T |
removeParam(java.lang.String parameter)
Removes specified parameter to the command line
|
void |
run() |
T |
setCommand(java.lang.String command)
Specify the command to execute
|
T |
setEnv(java.lang.String name,
java.lang.String value) |
T |
setFailOnError(boolean fail)
Specify if the running process should throw a Java Excption in case process returns with a
code different to 0.
|
T |
setLogCommand(boolean logCommand)
If true, the command line will be outputed in the console
|
T |
setLogOutput(boolean logOutput)
If logOutput parameter is
true , the process output will be redirected to JkLog. |
T |
setWorkingDir(java.nio.file.Path workingDir)
Sets the specified working directory to launch the process.
|
T |
setWorkingDir(java.lang.String workingDir) |
java.lang.String |
toString() |
protected JkProcess(java.lang.String command, java.lang.String... parameters)
public static JkProcess<JkProcess> of(java.lang.String command, java.lang.String... parameters)
JkProcess
using the specified command and
parameters.public static JkProcess<JkProcess> ofWinOrUx(java.lang.String windowsCommand, java.lang.String unixCommand, java.lang.String... parameters)
JkProcess
using the specified command and
parameters.public static JkProcess ofJavaTool(java.lang.String javaTool, java.lang.String... parameters)
JkProcess
using the specified tool of the JDK and
parameters. An example of JDK tool is 'javac'.public T clone()
clone
in class java.lang.Object
public T setCommand(java.lang.String command)
public T addParams(java.lang.String... parameters)
public T removeParam(java.lang.String parameter)
public T addParamsIf(boolean condition, java.lang.String... parameters)
public T addParams(java.util.Collection<java.lang.String> parameters)
addParams(String...)
public T addParamsFirst(java.util.Collection<java.lang.String> parameters)
public T addParamsFirst(java.lang.String... parameters)
public T setWorkingDir(java.nio.file.Path workingDir)
public T setEnv(java.lang.String name, java.lang.String value)
public T setFailOnError(boolean fail)
public T setLogCommand(boolean logCommand)
public T setLogOutput(boolean logOutput)
true
, the process output will be redirected to JkLog.public T inheritJkLogOptions()
public void execIf(boolean condition, java.lang.String... extraParams)
exec(String...)
()} but only effective if the specified condition is true
.public int exec(java.lang.String... extraParams)
public java.util.List<java.lang.String> execAndReturnOutput(java.lang.String... extraParams)
public void run()
run
in interface java.lang.Runnable
public java.nio.file.Path getWorkingDir()
public java.lang.String getCommand()
public java.util.List<java.lang.String> getParams()
public boolean isFailOnError()
true
if this process must throw an execption if the underlying process returns
code different than 0.public java.lang.String toString()
toString
in class java.lang.Object