org.netbeans.modules.extexecution/2 1.31

org.netbeans.api.extexecution
Class ProcessBuilder

java.lang.Object
  extended by org.netbeans.api.extexecution.ProcessBuilder
All Implemented Interfaces:
Callable<Process>

public final class ProcessBuilder
extends Object
implements Callable<Process>

Abstraction of process builders. You can freely configure the parameters and then create a process by calling the call() method. You can also (re)configure the builder and spawn a different process.

Note the API does not prescribe the actual meaning of Process. It may be local process, remote process or some other implementation.

You can use the default implementation returned by getLocal() for creating the local machine OS processes.

Thread safety of this class depends on thread safety of the ProcessBuilderImplementation the class is using. If it is thread safe (if possible the implementation should be even stateless) this class is thread safe as well.

Since:
1.28

Method Summary
 Process call()
          Creates the new Process based on the properties configured in this builder.
 String getDescription()
          Returns the human readable description of this builder.
static ProcessBuilder getLocal()
          Returns the ProcessBuilder creating the OS process on local machine.
 void setArguments(List<String> arguments)
          Sets the arguments passed to the process created by subsequent call of call().
 void setEnvironmentVariables(Map<String,String> envVariables)
          Sets the environment variables for the process created by subsequent call of call().
 void setExecutable(String executable)
          Sets the executable to run.
 void setPaths(List<String> paths)
          Sets the additional paths to be included in PATH environment variable for the process.
 void setRedirectErrorStream(boolean redirectErrorStream)
          Configures the error stream redirection.
 void setWorkingDirectory(String workingDirectory)
          Sets the working directory for the process created by subsequent call of call().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getLocal

public static ProcessBuilder getLocal()
Returns the ProcessBuilder creating the OS process on local machine. Returned implementation is thread safe.

Returns:
the ProcessBuilder creating the OS process on local machine

getDescription

@NonNull
public String getDescription()
Returns the human readable description of this builder.

Returns:
the human readable description of this builder

setExecutable

public void setExecutable(@NonNull
                          String executable)
Sets the executable to run. There is no default value. The call() methods throws IllegalStateException when there is no executable configured.

Parameters:
executable - the executable to run

setWorkingDirectory

public void setWorkingDirectory(@NullAllowed
                                String workingDirectory)
Sets the working directory for the process created by subsequent call of call(). The default value is implementation specific.

Parameters:
workingDirectory - the working directory of the process

setArguments

public void setArguments(@NonNull
                         List<String> arguments)
Sets the arguments passed to the process created by subsequent call of call(). By default there are no arguments.

Parameters:
arguments - the arguments passed to the process

setEnvironmentVariables

public void setEnvironmentVariables(@NonNull
                                    Map<String,String> envVariables)
Sets the environment variables for the process created by subsequent call of call(). By default there are no environment variables with exception of PATH possibly configured by setPaths(java.util.List).

Parameters:
envVariables - the environment variables for the process

setPaths

public void setPaths(@NonNull
                     List<String> paths)
Sets the additional paths to be included in PATH environment variable for the process.

Parameters:
paths - the additional paths to be included in PATH environment variable

setRedirectErrorStream

public void setRedirectErrorStream(boolean redirectErrorStream)
Configures the error stream redirection. If true the error stream of process created by subsequent call of call() method will be redirected to standard output stream.

Parameters:
redirectErrorStream - the error stream redirection

call

@NonNull
public Process call()
             throws IOException
Creates the new Process based on the properties configured in this builder.

Actual behavior depends on the builder implementation, but it should respect all the properties configured on this builder.

Specified by:
call in interface Callable<Process>
Returns:
the new Process based on the properties configured in this builder
Throws:
IOException - if the process could not be created
IllegalStateException - if there is no executable configured by setExecutable(java.lang.String)
See Also:
ProcessBuilderImplementation

org.netbeans.modules.extexecution/2 1.31

Built on May 22 2012.  |  Portions Copyright 1997-2012 Oracle. All rights reserved.