Perforce

com.perforce.api
Class P4Process

java.lang.Object
  |
  +--com.perforce.api.P4Process

public class P4Process
extends 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/08/05 $ $Revision: #7 $
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(PrintStream out)
          Waits for the process to exit and closes out the process.
 void exec(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.
 void outClose()
          Flushes and closes the output stream to the process.
 void print(String line)
          Writes line to the standard input of the process.
 void println(String line)
          Writes line to the standard input of the process.
 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.
 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

close

public int close()
          throws 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.
See Also:
System

close

public int close(PrintStream out)
          throws 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.

exec

public void exec(String[] cmd)
          throws 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).

flush

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

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

getEnv

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

getExitCode

public int getExitCode()
Returns the exit code returned when the underlying process exits.
Returns:
Typical UNIX style return code.

getRawMode

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

getServerTimeout

public long getServerTimeout()
Return the server timeout threshold.

outClose

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

print

public void print(String line)
           throws IOException
Writes line to the standard input of the process.
Parameters:
line - Line to be written.

println

public void println(String line)
             throws IOException
Writes line to the standard input of the process. A newline is appended to the output.
Parameters:
line - Line to be written.

readLine

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

setBase

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

setEnv

public void setEnv(Env e)
Sets the environment to use.
Parameters:
e - Source control environment.

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.

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.

setServerTimeout

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

toString

public String toString()
Overrides:
toString in class Object

Perforce

Copyright © 2001, Perforce Software, All rights reserved.