Perforce

com.perforce.api
Class Branch

java.lang.Object
  extended by com.perforce.api.SourceControlObject
      extended by com.perforce.api.Mapping
          extended by com.perforce.api.Branch
All Implemented Interfaces:
Cacheable, Comparable

public class Branch
extends Mapping

Representation of a source control branch. There are static class methods that can be used to list all P4 branches or to get a particular branch.

Version:
$Date: 2008/08/06 $ $Revision: #10 $
Author:
David Markley, Sivananda Poreddy

Constructor Summary
Branch()
          Default no-argument constructor.
Branch(String name)
          Constructor that is passed the branch name.
 
Method Summary
static boolean canIntegrate(Env env, String source, String target, StringBuffer sb)
          Check for the integration feasibility on the named branch.
 void commit()
          Stores this object back into Perforce, creating it if it didn't already exist.
static Branch getBranch(Env env, String name, boolean force)
          Returns a Branch with the specified name, or null if not found.
static Branch getBranch(String name)
          Returns a Branch with the specified name, or null if not found.
static Enumeration getBranches(Env env)
           
static Iterator getBranchIterator(Env env)
           
static Enumeration getBranchNames(Env env)
          Returns list of all branch names.
 HashDecay getCache()
          Returns the HashDecay instance for this class
static Change integrate(Env env, String source, String target, StringBuffer sb, Change c)
          Integrate a set of files using the named branch.
static Change integrate(Env env, Vector fents, String branch, StringBuffer sb, Change c)
          Integrate a set of files using the named branch.
static Change integrate(Env env, Vector fents, String branch, StringBuffer sb, String description)
          Integrate a set of files using the named branch.
 Change integrate(String source, StringBuffer sb, Change c)
          Class method for integrating using the instantiated Branch.
static boolean integrated(Env env, String source, String target, StringBuffer sb)
          Check for the integration history on the named branch.
static void loadBranches()
          Loads the list of branches using the default environment.
static void loadBranches(Env env)
          Loads a list of all the branches into an internal class HashDecay.
static Enumeration lookupBranches(String prefix)
          Returns a list of branches that begin with the specified prefix.
 void sync()
          Brings this object back into sync with Perforce.
 void sync(String name)
          Synchronizes the Branch with the latest information from P4.
 String toXML()
          Returns a string containing the object in XML form.
 
Methods inherited from class com.perforce.api.Mapping
addView, addView, compareTo, getDescription, getName, getOwner, getView, getViews, lookupMappings, setDescription, setName, setOwner, toString
 
Methods inherited from class com.perforce.api.SourceControlObject
clearCache, getEnv, getSyncTime, getUpdateTime, inSync, invalidate, outOfSync, refreshUpdateTime, setEnv
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Branch

public Branch()
Default no-argument constructor.


Branch

public Branch(String name)
Constructor that is passed the branch name.

Method Detail

canIntegrate

public static boolean canIntegrate(Env env,
                                   String source,
                                   String target,
                                   StringBuffer sb)
                            throws PerforceException
Check for the integration feasibility on the named branch.

Parameters:
env - environment to use when working with P4.
source - source files to integrate from.
target - target path to integrate the file to
sb - buffer that will contain a log of the integration.
Returns:
boolean to indicate the integration done or not
Throws:
PerforceException

commit

public void commit()
            throws CommitException
Description copied from class: SourceControlObject
Stores this object back into Perforce, creating it if it didn't already exist.

Specified by:
commit in interface Cacheable
Specified by:
commit in class Mapping
Throws:
CommitException

getBranch

public static Branch getBranch(Env env,
                               String name,
                               boolean force)
Returns a Branch with the specified name, or null if not found.

Parameters:
env - Environment to use when working with P4.
name - Name of the branch to find.
force - Indicates that the Branch should be sync'd.

getBranch

public static Branch getBranch(String name)
Returns a Branch with the specified name, or null if not found.

Parameters:
name - Name of the branch to find.

getBranches

public static Enumeration getBranches(Env env)
Parameters:
env - Source control environment.
Returns:
Enumeration of Branches.

getBranchIterator

public static Iterator getBranchIterator(Env env)
Parameters:
env - Source control environment.
Returns:
Iterator of Branches.

getBranchNames

public static Enumeration getBranchNames(Env env)
Returns list of all branch names.

Returns:
Enumeration of Strings containing branch names.

getCache

public HashDecay getCache()
Description copied from class: SourceControlObject
Returns the HashDecay instance for this class

Specified by:
getCache in interface Cacheable
Specified by:
getCache in class SourceControlObject

integrate

public static Change integrate(Env env,
                               String source,
                               String target,
                               StringBuffer sb,
                               Change c)
                        throws PerforceException
Integrate a set of files using the named branch. Uses the Change passed in to contain the integraed files. The change will be *PENDING* after this completes.

Parameters:
env - environment to use when working with P4.
source - source files to integrate from.
target - target path to integrate the file to
sb - buffer that will contain a log of the integration.
c - Change to be used to contain the integrated files.
Returns:
Change containing the files integrated.
Throws:
PerforceException
See Also:
Change

integrate

public static Change integrate(Env env,
                               Vector fents,
                               String branch,
                               StringBuffer sb,
                               Change c)
                        throws PerforceException
Integrate a set of files using the named branch. Uses the Change passed in to contain the integraed files. The change will be *PENDING* after this completes.

Parameters:
env - environment to use when working with P4.
fents - list of FileEntries to be integrated.
branch - name of the branch to integrate with.
sb - buffer that will contain a log of the integration.
c - Change to be used to contain the integrated files.
Returns:
Change containing the files integrated.
Throws:
PerforceException
See Also:
Change

integrate

public static Change integrate(Env env,
                               Vector fents,
                               String branch,
                               StringBuffer sb,
                               String description)
                        throws CommitException,
                               PerforceException
Integrate a set of files using the named branch. Creates a Change that contains the integraed files. The change will be *PENDING* after this completes.

Parameters:
env - environment to use when working with P4.
fents - list of FileEntries to be integrated.
branch - name of the branch to integrate with.
sb - buffer that will contain a log of the integration.
description - description to be used for the Change created.
Returns:
Change containing the files integrated.
Throws:
CommitException
PerforceException
See Also:
Change

integrate

public Change integrate(String source,
                        StringBuffer sb,
                        Change c)
                 throws PerforceException
Class method for integrating using the instantiated Branch.

Parameters:
source - source files to integrate from.
sb - buffer that will contain a log of the integration.
c - Change to be used to contain the integrated files.
Throws:
PerforceException
See Also:
integrate(Env,String,String,StringBuffer,Change)

integrated

public static boolean integrated(Env env,
                                 String source,
                                 String target,
                                 StringBuffer sb)
                          throws PerforceException
Check for the integration history on the named branch.

Parameters:
env - environment to use when working with P4.
source - source files to integrate from.
target - target path to integrate the file to
sb - buffer that will contain a log of the integration.
Returns:
boolean to indicate the integration done or not
Throws:
PerforceException

loadBranches

public static void loadBranches()
Loads the list of branches using the default environment.

See Also:
Env

loadBranches

public static void loadBranches(Env env)
Loads a list of all the branches into an internal class HashDecay. This method will only be called by the class itself if the HashDecay is empty. Users should call this method if they believe the p4 branch information needs to be brought up to date.

Parameters:
env - Environment to use when working with P4
See Also:
HashDecay

lookupBranches

public static Enumeration lookupBranches(String prefix)
Returns a list of branches that begin with the specified prefix.

Parameters:
prefix - Prefix for all branches to be returned
Returns:
List of branches matching the prefix.

sync

public void sync()
Description copied from class: SourceControlObject
Brings this object back into sync with Perforce. This also sets the sets the update and sync time for this object.

Specified by:
sync in interface Cacheable
Specified by:
sync in class SourceControlObject

sync

public void sync(String name)
Synchronizes the Branch with the latest information from P4. This method forces the Branch to contain the latest, correct information if it didn't already.

Specified by:
sync in class Mapping
Parameters:
name - Name of the Branch to synchronize.

toXML

public String toXML()
Description copied from class: SourceControlObject
Returns a string containing the object in XML form.

Overrides:
toXML in class Mapping

Perforce

Copyright © 2008, Perforce Software, All rights reserved.