public class SpincastProcessUtilsDefault extends Object implements SpincastProcessUtils
| Modifier and Type | Field and Description |
|---|---|
protected static org.slf4j.Logger |
logger |
| Constructor and Description |
|---|
SpincastProcessUtilsDefault(SpincastConfig spincastConfig,
SpincastUtils spincastUtils,
TemplatingEngine templatingEngine) |
| Modifier and Type | Method and Description |
|---|---|
protected ProcessBuilder |
configureStreams(ProcessBuilder pb)
Configure input/output streams
|
void |
executeAsync(ProcessExecutionHandler handler,
List<String> cmdArgs)
Execute an external program asynchronously.
|
void |
executeAsync(ProcessExecutionHandler handler,
long timeoutAmount,
TimeUnit timeoutUnit,
List<String> cmdArgs)
Execute an external program asynchronously.
|
void |
executeAsync(ProcessExecutionHandler handler,
long timeoutAmount,
TimeUnit timeoutUnit,
String... cmdArgs)
Execute an external program asynchronously.
|
void |
executeAsync(ProcessExecutionHandler handler,
String... cmdArgs)
Execute an external program asynchronously.
|
File |
executeGoalOnExternalMavenProject(ResourceInfo projectRootInfo,
MavenProjectGoal mavenGoal)
Execute the specified
goal on an external
Maven project. |
File |
executeGoalOnExternalMavenProject(ResourceInfo projectRootInfo,
MavenProjectGoal mavenGoal,
Map<String,Object> pomParams)
Execute the specified
goal on an external
Maven project. |
SyncExecutionResult |
executeSync(long timeoutAmount,
TimeUnit timeoutUnit,
ExecutionOutputStrategy executionOutputStrategy,
List<String> cmdArgs)
Execute an external program synchronously.
|
SyncExecutionResult |
executeSync(long timeoutAmount,
TimeUnit timeoutUnit,
ExecutionOutputStrategy executionOutputStrategy,
String... cmdArgs)
Execute an external program synchronously.
|
SyncExecutionResult |
executeSync(long timeoutAmount,
TimeUnit timeoutUnit,
List<String> cmdArgs)
Execute an external program synchronously.
|
SyncExecutionResult |
executeSync(long timeoutAmount,
TimeUnit timeoutUnit,
String... cmdArgs)
Execute an external program synchronously.
|
protected SpincastConfig |
getSpincastConfig() |
protected SpincastUtils |
getSpincastUtils() |
protected TemplatingEngine |
getTemplatingEngine() |
protected void |
killProcess(Process process) |
protected void |
startSystemErrReader(Process process,
ProcessExecutionHandler handler) |
protected void |
startSystemOutReader(Process process,
ProcessExecutionHandler handler) |
protected void |
waitForStreamsToBeEmpty(Thread systemOutReaderThread,
Thread systemErrReaderThread) |
@Inject public SpincastProcessUtilsDefault(SpincastConfig spincastConfig, SpincastUtils spincastUtils, TemplatingEngine templatingEngine)
protected SpincastConfig getSpincastConfig()
protected SpincastUtils getSpincastUtils()
protected TemplatingEngine getTemplatingEngine()
public File executeGoalOnExternalMavenProject(ResourceInfo projectRootInfo, MavenProjectGoal mavenGoal)
SpincastProcessUtilsgoal on an external
Maven project.
If the project is located on the classpath, it first copies it to the file system (in a temp folder).
executeGoalOnExternalMavenProject in interface SpincastProcessUtilspublic File executeGoalOnExternalMavenProject(ResourceInfo projectRootInfo, MavenProjectGoal mavenGoal, Map<String,Object> pomParams)
SpincastProcessUtilsgoal on an external
Maven project.
If the project is located on the classpath, it first copies it to the file system (in a temp folder).
executeGoalOnExternalMavenProject in interface SpincastProcessUtilspomParams - Before executing the goal, those parameters
are used to replace placeholders in the project's pom.xml
using Spincast's TemplatingEngine.public void executeAsync(ProcessExecutionHandler handler, String... cmdArgs)
SpincastProcessUtilsThe method will only return when the process is actually created or if an exception occured when trying to do so.
If this creates a process that is not made to exit automatically (for example it starts an HTTP server), you must kill the process by yourself!:
ProcessExecutionHandlerDefault handler = new ProcessExecutionHandlerDefault();
{
// override some methods...
};
getSpincastProcessUtils().executeAsync(handler,
"java",
"-jar",
jarFile.getAbsolutePath());
try {
//...
} finally {
handler.killProcess();
}
executeAsync in interface SpincastProcessUtilshandler - to get information from the created process
and to be able to kill it.public void executeAsync(ProcessExecutionHandler handler, long timeoutAmount, TimeUnit timeoutUnit, String... cmdArgs)
SpincastProcessUtilsThe method will only return when the process is actually created or if an exception occured when trying to do so.
If this creates a process that is not made to exit automatically (for example it starts an HTTP server), you must kill the process by yourself!:
ProcessExecutionHandlerDefault handler = new ProcessExecutionHandlerDefault();
{
// override some methods...
};();
getSpincastProcessUtils().executeAsync(handler,
"java",
"-jar",
jarFile.getAbsolutePath());
try {
//...
} finally {
handler.killProcess();
}
executeAsync in interface SpincastProcessUtilshandler - to get information from the created process
and to be able to kill it.timeoutAmount - the amount of time the external program
is allowed to run before a timeout occurs. When the timeout occurs:
onTimeoutException() is called
onExit() will not be called
if a timeout occurs!timeoutUnit - the timeout unit.public void executeAsync(ProcessExecutionHandler handler, List<String> cmdArgs)
SpincastProcessUtilsThe method will only return when the process is actually created or if an exception occured when trying to do so.
If this creates a process that is not made to exit automatically (for example it starts an HTTP server), you must kill the process by yourself!:
ProcessExecutionHandlerDefault handler = new ProcessExecutionHandlerDefault();
{
// override some methods...
};
getSpincastProcessUtils().executeAsync(handler,
"java",
"-jar",
jarFile.getAbsolutePath());
try {
//...
} finally {
handler.killProcess();
}
executeAsync in interface SpincastProcessUtilshandler - to get information from the created process
and to be able to kill it.public void executeAsync(ProcessExecutionHandler handler, long timeoutAmount, TimeUnit timeoutUnit, List<String> cmdArgs)
SpincastProcessUtilsThe method will only return when the process is actually created or if an exception occured when trying to do so.
If this creates a process that is not made to exit automatically (for example it starts an HTTP server), you must kill the process by yourself!:
ProcessExecutionHandlerDefault handler = new ProcessExecutionHandlerDefault();
{
// override some methods...
};
getSpincastProcessUtils().executeAsync(handler,
"java",
"-jar",
jarFile.getAbsolutePath());
try {
//...
} finally {
handler.killProcess();
}
executeAsync in interface SpincastProcessUtilshandler - to get information from the created process
and to be able to kill it.timeoutAmount - the amount of time the external program
is allowed to run before a timeout occurs. When the timeout occurs:
onTimeoutException() is called
onExit() will not be called
if a timeout occurs!timeoutUnit - the timeout unit.protected void killProcess(Process process)
protected ProcessBuilder configureStreams(ProcessBuilder pb)
protected void startSystemOutReader(Process process, ProcessExecutionHandler handler)
protected void startSystemErrReader(Process process, ProcessExecutionHandler handler)
protected void waitForStreamsToBeEmpty(Thread systemOutReaderThread, Thread systemErrReaderThread)
public SyncExecutionResult executeSync(long timeoutAmount, TimeUnit timeoutUnit, String... cmdArgs) throws LaunchException, TimeoutException
SpincastProcessUtils
By default SYSTEM is
used as the output strategy so it is printed to
System.out and System.err.
executeSync in interface SpincastProcessUtilstimeoutAmount - the amount of time the external program
is allowed to run before a timeout occurs. When the timeout occurs:
TimeoutException exception is thrown.
timeoutUnit - the timeout unit.LaunchException - if the program can't be launched properly.TimeoutException - if the specified timeout is
exceeded.public SyncExecutionResult executeSync(long timeoutAmount, TimeUnit timeoutUnit, List<String> cmdArgs) throws LaunchException, TimeoutException
SpincastProcessUtils
By default SYSTEM is
used as the output strategy so it is printed to
System.out and System.err.
executeSync in interface SpincastProcessUtilstimeoutAmount - the amount of time the external program
is allowed to run before a timeout occurs. When the timeout occurs:
TimeoutException exception is thrown.
timeoutUnit - the timeout unit.LaunchException - if the program can't be launched properly.TimeoutException - if the specified timeout is
exceeded.public SyncExecutionResult executeSync(long timeoutAmount, TimeUnit timeoutUnit, ExecutionOutputStrategy executionOutputStrategy, String... cmdArgs) throws LaunchException, TimeoutException
SpincastProcessUtils
By default SYSTEM is
used as the output strategy so it is printed to
System.out and System.err.
executeSync in interface SpincastProcessUtilstimeoutAmount - the amount of time the external program
is allowed to run before a timeout occurs. When the timeout occurs:
TimeoutException exception is thrown.
timeoutUnit - the timeout unit.executionOutputStrategy - what should be done with the
output of the executed program?LaunchException - if the program can't be launched properly.TimeoutException - if the specified timeout is
exceeded.public SyncExecutionResult executeSync(long timeoutAmount, TimeUnit timeoutUnit, ExecutionOutputStrategy executionOutputStrategy, List<String> cmdArgs) throws LaunchException, TimeoutException
SpincastProcessUtils
By default SYSTEM is
used as the output strategy so it is printed to
System.out and System.err.
executeSync in interface SpincastProcessUtilstimeoutAmount - the amount of time the external program
is allowed to run before a timeout occurs. When the timeout occurs:
TimeoutException exception is thrown.
timeoutUnit - the timeout unit.executionOutputStrategy - what should be done with the
output of the executed program?LaunchException - if the program can't be launched properly.TimeoutException - if the specified timeout is
exceeded.Copyright © 2019. All rights reserved.