public final class JkProcess
extends java.lang.Object
implements java.lang.Runnable
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 and Type | Method and Description |
---|---|
JkProcess |
andParams(java.util.Collection<java.lang.String> parameters) |
JkProcess |
andParams(java.lang.String... parameters)
Returns a
JkProcess identical to this one but with the
specified extra parameters. |
JkProcess |
andParamsIf(boolean conditional,
java.lang.String... parameters)
Returns a
JkProcess identical to this one but with the
specified extra parameters if the conditional is true . |
java.lang.String |
getCommand()
Returns the command launched by this process.
|
java.nio.file.Path |
getWorkingDir()
Returns the working directory of this process.
|
JkProcess |
minusParam(java.lang.String parameter)
Returns a
JkProcess identical to this one but minus the
specified parameter. |
static JkProcess |
of(java.lang.String command,
java.lang.String... parameters)
Defines a
JkProcess using the specified command and
parameters. |
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 |
ofWinOrUx(java.lang.String windowsCommand,
java.lang.String unixCommand,
java.lang.String... parameters)
Defines a
JkProcess using the specified command and
parameters. |
void |
run() |
java.util.List<java.lang.String> |
runAndReturnOutputAsLines() |
int |
runSync()
Starts this process and wait for the process has finished prior
returning.
|
void |
runSyncIf(boolean condition)
Same as
runSync() but only effective if the specified condition is true . |
java.lang.String |
toString() |
JkProcess |
withFailOnError(boolean fail)
Returns a
JkProcess identical to this one but with the
specified behavior if the the underlying process does not exit with 0
code. |
JkProcess |
withLogCommand(boolean logCommand)
Returns a
JkProcess identical to this one but with the specified logging command behavior. |
JkProcess |
withLogOutput(boolean logOutput)
Returns a
JkProcess identical to this one but with the specified logging output behavior. |
JkProcess |
withParams(java.lang.String... parameters)
Returns a
JkProcess identical to this one but with the
specified parameters in place of this parameters. |
JkProcess |
withParamsIf(boolean condition,
java.lang.String... parameters)
Same as
withParams(String...) but only effective if the
specified conditional is true. |
JkProcess |
withWorkingDir(java.nio.file.Path workingDir)
Returns a
JkProcess identical to this one but using the
specified directory as the working directory. |
JkProcess |
withWorkingDir(java.lang.String workingDir)
Returns a
JkProcess identical to this one but using the
specified directory as the working directory. |
public static JkProcess of(java.lang.String command, java.lang.String... parameters)
JkProcess
using the specified command and
parameters.public static 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 JkProcess andParams(java.lang.String... parameters)
JkProcess
identical to this one but with the
specified extra parameters.public JkProcess minusParam(java.lang.String parameter)
JkProcess
identical to this one but minus the
specified parameter.public JkProcess andParamsIf(boolean conditional, java.lang.String... parameters)
JkProcess
identical to this one but with the
specified extra parameters if the conditional is true
.
Returns this
otherwise.public JkProcess andParams(java.util.Collection<java.lang.String> parameters)
andParams(String...)
public JkProcess withParams(java.lang.String... parameters)
JkProcess
identical to this one but with the
specified parameters in place of this parameters. Contrary to
andParams(String...)
, this method replaces this parameters
by the specified ones (not adding).public JkProcess withParamsIf(boolean condition, java.lang.String... parameters)
withParams(String...)
but only effective if the
specified conditional is true.public JkProcess withWorkingDir(java.nio.file.Path workingDir)
JkProcess
identical to this one but using the
specified directory as the working directory.public JkProcess withWorkingDir(java.lang.String workingDir)
JkProcess
identical to this one but using the
specified directory as the working directory.public JkProcess withFailOnError(boolean fail)
JkProcess
identical to this one but with the
specified behavior if the the underlying process does not exit with 0
code. In case of fail flag is true
and the underlying
process exit with a non 0 value, the runSync()
method witll
throw a IllegalStateException
.public JkProcess withLogCommand(boolean logCommand)
JkProcess
identical to this one but with the specified logging command behavior.
If parameter is true
, a process execution will be wrapped in a log showing start and end of
the execution showing details about the command to be executed and execution duration.public JkProcess withLogOutput(boolean logOutput)
JkProcess
identical to this one but with the specified logging output behavior.
If parameter is true
, a process output will be redirected to JkLog.public void runSyncIf(boolean condition)
runSync()
but only effective if the specified condition is true
.public int runSync()
public java.util.List<java.lang.String> runAndReturnOutputAsLines()
public void run()
run
in interface java.lang.Runnable
public java.nio.file.Path getWorkingDir()
public java.lang.String getCommand()
public java.lang.String toString()
toString
in class java.lang.Object