com.perforce.api
Class P4Process

java.lang.Object
  extended by com.perforce.api.P4Process

public class P4Process
extends java.lang.Object

Handles the execution of all perforce commands. This class can be used directly, but the preferred use of this API is through the SourceControlObject subclasses.

Example Usage:

 String l;
 Env env = new Env();
 String[] cmd = { "p4", "branches" };
 try {
        P4Process p = new P4Process(env);
        p.exec(cmd);
        while(null != (l = p.readLine())) {
                // Parse the output.
        }
        p.close();
 } catch(Exception ex) {
        throw new PerforceException(ex.getMessage());
 }
 

Version:
$Date: 2002/01/15 $ $Revision: #3 $
Author:
David Markley
See Also:
Env, SourceControlObject, Thread

Constructor Summary
P4Process()
          Default no-argument constructor.
P4Process(Env e)
          Constructor that specifies the source control environment.
 
Method Summary
 int close()
          Waits for the underlying process to exit and closes it down.
 int close(java.io.PrintStream out)
          Waits for the process to exit and closes out the process.
 void exec(java.lang.String[] cmd)
          Executes a p4 command.
 void flush()
          Flushes the output stream to the process.
static P4Process getBase()
          Returns the base process for this class.
 Env getEnv()
          Returns the environment in use by this process.
 int getExitCode()
          Returns the exit code returned when the underlying process exits.
 boolean getRawMode()
          Returns the status of raw mode for this process.
 long getServerTimeout()
          Return the server timeout threshold.
 java.io.Writer getWriter()
           
 void outClose()
          Flushes and closes the output stream to the process.
 void print(java.lang.String line)
          Writes line to the standard input of the process.
 void println(java.lang.String line)
          Writes line to the standard input of the process.
 java.lang.String readLine()
          Returns the next line from the process, or null if the command has completed its execution.
static void setBase(P4Process b)
          Sets the base process to be used when new processes are instantiated.
 void setEnv(Env e)
          Sets the environment to use.
 void setEventLog(EventLog log)
          Sets the event log.
 void setRawMode(boolean raw)
          In raw mode, the process will return the prefix added by the "-s" command line option.
 void setServerTimeout(long threshold)
          Set the server timeout threshold.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

P4Process

public P4Process()
Default no-argument constructor. If the runtime has not been established, this constructor will set it up. No environment is specified, so the base environment will be used if it exists.

See Also:
getBase()

P4Process

public P4Process(Env e)
Constructor that specifies the source control environment.

Parameters:
e - Source control environment to use.
Method Detail

setEnv

public void setEnv(Env e)
Sets the environment to use.

Parameters:
e - Source control environment.

getEnv

public Env getEnv()
Returns the environment in use by this process.

Returns:
Source control environment.

getBase

public static P4Process getBase()
Returns the base process for this class. The base process is set when this class is first instantiated. The base process is used when other P4Process are instantiated to share settings, including the source control environment.

Returns:
Source control environment.
See Also:
Env

setBase

public static void setBase(P4Process b)
Sets the base process to be used when new processes are instantiated.

See Also:
getBase()

getWriter

public java.io.Writer getWriter()

getExitCode

public int getExitCode()
Returns the exit code returned when the underlying process exits.

Returns:
Typical UNIX style return code.

setRawMode

public void setRawMode(boolean raw)
In raw mode, the process will return the prefix added by the "-s" command line option. The default is false.


getRawMode

public boolean getRawMode()
Returns the status of raw mode for this process.


exec

public void exec(java.lang.String[] cmd)
          throws java.io.IOException
Executes a p4 command. This uses the class environment information to execute the p4 command specified in the String array. This array contains all the command line arguments that will be specified for execution, including "p4" in the first position.

Parameters:
cmd - Array of command line arguments ("p4" must be first).
Throws:
java.io.IOException

setEventLog

public void setEventLog(EventLog log)
Sets the event log. Any events that should be logged will be logged through the EventLog specified here.

Parameters:
log - Log for all events.

print

public void print(java.lang.String line)
           throws java.io.IOException
Writes line to the standard input of the process.

Parameters:
line - Line to be written.
Throws:
java.io.IOException

println

public void println(java.lang.String line)
             throws java.io.IOException
Writes line to the standard input of the process. A newline is appended to the output.

Parameters:
line - Line to be written.
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flushes the output stream to the process.

Throws:
java.io.IOException

outClose

public void outClose()
              throws java.io.IOException
Flushes and closes the output stream to the process.

Throws:
java.io.IOException

readLine

public java.lang.String readLine()
Returns the next line from the process, or null if the command has completed its execution.


close

public int close(java.io.PrintStream out)
          throws java.io.IOException
Waits for the process to exit and closes out the process. This method should be called after the exec method in order to close things down properly.

Parameters:
out - The stream to which any errors should be sent.
Returns:
The exit value of the underlying process.
Throws:
java.io.IOException

close

public int close()
          throws java.io.IOException
Waits for the underlying process to exit and closes it down. This method should be called after the exec method in order to close things out properly. Errors are sent to System.err.

Returns:
The exit value of the underlying process.
Throws:
java.io.IOException
See Also:
System

setServerTimeout

public void setServerTimeout(long threshold)
Set the server timeout threshold.


getServerTimeout

public long getServerTimeout()
Return the server timeout threshold.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2010. All Rights Reserved.