Perforce

com.perforce.api
Class FileEntry

java.lang.Object
  |
  +--com.perforce.api.SourceControlObject
        |
        +--com.perforce.api.FileEntry
All Implemented Interfaces:
Cacheable

public final class FileEntry
extends SourceControlObject

Representation of a source control file.

Version:
$Date: 2003/12/02 $ $Revision: #1 $
Author:
David Markley
See Also:
Hashtable

Constructor Summary
FileEntry()
          Default no-argument constructor.
FileEntry(Env env)
          Constructs a file entry using the environment.
FileEntry(Env env, String p)
          Constructs a file entry using the environment and path.
FileEntry(String p)
          Constructs a file entry using the path.
 
Method Summary
static FileEntry checkIn(Env env, String path, String description)
          Checks in a file that has already been opened on the client using the description given.
 void commit()
          No-op.
static String customizePath(String str, char from_char, char to_char)
          Returns the path after converting characters.
static String depotizePath(String path)
          Returns the path in depot format.
 HashDecay getCache()
          Returns the HashDecay instance for this class
 String getClientPath()
          Returns the client path for this file.
 String getDepotPath()
          Returns the depot path for this file.
 String getDescription()
          Returns the decription for this file
static FileEntry getFile(String p)
          Gets the file information for the specified path.
 String getFileContents()
          Returns a String that contains this file's contents.
 String getFileContents(Env env, String path)
          Returns a String that contains this file's contents.
static Vector getFileLog(Env env, String path)
          Returns a list of FileEntry objects that represent the history of the specified file.
static Vector getFiles(Env env, String path)
          Returns the list of files for the path.
 int getHaveRev()
          Returns the revision number the client has for this file.
 String getHeadAction()
          Returns the head revision action for this file.
 int getHeadChange()
          Returns the head revision change number for this file.
 String getHeadDate()
          Returns a String representation of date for the head revsision of the file.
 int getHeadRev()
          Returns the head revision number for this file.
 long getHeadTime()
          Returns the head revision time for this file.
 String getHeadTimeString()
          Returns the head revision time as a String for this file.
 String getHeadType()
          Returns the head revision type for this file.
 String getName()
          Returns the file name.
static Vector getOpened()
          Returns a list of files that are open for edit or add.
static Vector getOpened(Env env, boolean stat)
          Returns a list of files that are open for edit or add.
static Vector getOpened(Env env, boolean stat, boolean all, int changelist, Vector files)
          Returns a list of files that are open for edit or add.
 String getOwner()
          Returns the owner for this file
 FileEntry getSource()
          Returns the source file entry associated with this file.
static String localizePath(String path)
          Returns the path in local format.
 void obtainLock()
          Obtains the lock for this file.
 void openForAdd()
          Opens this file for addition.
 void openForAdd(Change chng)
          Opens this file for addition.
static FileEntry openForAdd(Env env, String path, Change chng)
          Opens the file on the path for add under the change.
 void openForEdit()
          Opens this file for edit.
 void openForEdit(boolean force, boolean lock)
          Opens this file for edit.
 void openForEdit(boolean force, boolean lock, Change chng)
          Opens this file for edit.
static FileEntry openForEdit(Env env, String path, boolean sync, boolean force, boolean lock, Change chng)
          Opens the file on the path for edit under the change.
 void reopen(String type, Change chng)
          Reopens the file with the new type or in the new change list.
 String resolve(boolean force)
          Resolves this file.
static String resolveAll(Env env, String flags, String path)
          Resolves all the files in the path.
static String resolveAT(Env env, Enumeration en)
          Forces a resolve on a set of files.
 boolean revert()
          Reverts this file.
 void setClientPath(String p)
          Sets the client path for this file.
 void setDepotPath(String p)
          Sets the depot path for this file.
 void setDescription(String d)
          Sets the decription for this file
 void setHaveRev(int rev)
          Sets the revision number the client has for this file.
 void setHeadAction(String action)
          Sets the head revision action for this file.
 void setHeadChange(int change)
          Sets the head revision change number for this file.
 void setHeadDate(String date)
          Sets the head date for this file.
 void setHeadRev(int rev)
          Sets the head revision number for this file.
 void setHeadTime(long time)
          Sets the head revision time for this file.
 void setHeadType(String type)
          Sets the head revision type for this file.
 void setOwner(String o)
          Sets the owner for this file
 void setSource(FileEntry fent)
          Sets the source file entry associated with this file.
 void setTimeFormat(String format)
          Sets the format used by the getHeadTimeString method.
 void sync()
          Brings this object back into sync with Perforce.
static Vector synchronizeWorkspace(Env env, String path)
          Returns a Vector of FileEntry objects that reflect what files were changed by the sync process.
static String syncWorkspace(Env env, String path)
          Synchronizes the workspace.
 String toString()
           
 String toXML()
          Returns a string containing the object in XML form.
 
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

FileEntry

public FileEntry()
Default no-argument constructor.

FileEntry

public FileEntry(Env env)
Constructs a file entry using the environment.
Parameters:
env - Source control environement to use.

FileEntry

public FileEntry(Env env,
                 String p)
Constructs a file entry using the environment and path.
Parameters:
env - Source control environement to use.
p - Path to the file.

FileEntry

public FileEntry(String p)
Constructs a file entry using the path.
Parameters:
p - Path to the file.
Method Detail

checkIn

public static FileEntry checkIn(Env env,
                                String path,
                                String description)
                         throws PerforceException
Checks in a file that has already been opened on the client using the description given. A new changelist is created and used for this submission. The returned FileEntry contains the latest information for the checked-in file.

commit

public void commit()
No-op. This makes no sense for a FileEntry.
Overrides:
commit in class SourceControlObject

customizePath

public static String customizePath(String str,
                                   char from_char,
                                   char to_char)
Returns the path after converting characters.
Parameters:
str - String to convert.
from_char - Character to be changed from.
to_char - Character to be changed to.

depotizePath

public static String depotizePath(String path)
Returns the path in depot format. Uses the depot delimeter: '/'.

getCache

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

getClientPath

public String getClientPath()
Returns the client path for this file.

getDepotPath

public String getDepotPath()
Returns the depot path for this file.

getDescription

public String getDescription()
Returns the decription for this file

getFile

public static FileEntry getFile(String p)
Gets the file information for the specified path.
Parameters:
p - Path of the file to gather information about.

getFileContents

public String getFileContents()
Returns a String that contains this file's contents. This only works well for text files.

getFileContents

public String getFileContents(Env env,
                              String path)
Returns a String that contains this file's contents. This only works well for text files.
Parameters:
env - Source control environment.
path - Path to the file. Must be specific. No wildcards.

getFileLog

public static Vector getFileLog(Env env,
                                String path)
Returns a list of FileEntry objects that represent the history of the specified file.
Parameters:
env - Source control environment to use.
path - Path to the file. Must be specific. No wildcards.

getFiles

public static Vector getFiles(Env env,
                              String path)
Returns the list of files for the path. The path may include wildcards.
Parameters:
env - Source control environment to use.
path - Path for set of files.

getHaveRev

public int getHaveRev()
Returns the revision number the client has for this file.

getHeadAction

public String getHeadAction()
Returns the head revision action for this file.

getHeadChange

public int getHeadChange()
Returns the head revision change number for this file.

getHeadDate

public String getHeadDate()
Returns a String representation of date for the head revsision of the file. The format is yyyy/MM/dd.

getHeadRev

public int getHeadRev()
Returns the head revision number for this file.

getHeadTime

public long getHeadTime()
Returns the head revision time for this file.

getHeadTimeString

public String getHeadTimeString()
Returns the head revision time as a String for this file.

getHeadType

public String getHeadType()
Returns the head revision type for this file.

getName

public String getName()
Returns the file name.

getOpened

public static Vector getOpened()
Returns a list of files that are open for edit or add. The list is a Vectore of FileEntry objects. The only information that is valid for the object will be the path, until the sync method is called.

getOpened

public static Vector getOpened(Env env,
                               boolean stat)
Returns a list of files that are open for edit or add. The list is a Vectore of FileEntry objects.

Getting the stats for each FileEntry is a more expensive operation. By default, this is not done. What this means is that the only information that is valid for the object will be the path, until the sync method is called.

Parameters:
env - Source control environment to use.
stat - Indicates that file statistics should be gathered.

getOpened

public static Vector getOpened(Env env,
                               boolean stat,
                               boolean all,
                               int changelist,
                               Vector files)
Returns a list of files that are open for edit or add. The list is a Vector of FileEntry objects.

Getting the stats for each FileEntry is a more expensive operation. By default, this is not done. What this means is that the only information that is valid for the object will be the path, until the sync method is called.

If changelist is 0, all the changes in the default changelist are returned. If it is less than 0, all opened files are returned.

Parameters:
env - Source control environment to use.
stat - Indicates that file statistics should be gathered.
all - Indicates that all open files should be returned.
changelist - If non-zero, show files open in this changelist.
files - If non-null, show files open in this Vector of FileEntry objects.

getOwner

public String getOwner()
Returns the owner for this file

getSource

public FileEntry getSource()
Returns the source file entry associated with this file.

localizePath

public static String localizePath(String path)
Returns the path in local format. Uses the local path delimeter.

obtainLock

public void obtainLock()
                throws Exception
Obtains the lock for this file. The file must have been opened for edit prior to this method being called.

openForAdd

public void openForAdd()
                throws Exception
Opens this file for addition.
See Also:
openForAdd(Env, String, Change)

openForAdd

public void openForAdd(Change chng)
                throws Exception
Opens this file for addition.
See Also:
openForAdd(Env, String, Change)

openForAdd

public static FileEntry openForAdd(Env env,
                                   String path,
                                   Change chng)
                            throws Exception
Opens the file on the path for add under the change. If the change is null, the file is opened under the default changelist.
Parameters:
env - P4 Environment
path - Depot or client path to the file being opened for add.
chng - The change that the file will be opened for add in.

openForEdit

public void openForEdit()
                 throws Exception
Opens this file for edit.
See Also:
openForEdit(Env, String, boolean, boolean, boolean, Change)

openForEdit

public void openForEdit(boolean force,
                        boolean lock)
                 throws Exception
Opens this file for edit.
See Also:
openForEdit(Env, String, boolean, boolean, boolean, Change)

openForEdit

public void openForEdit(boolean force,
                        boolean lock,
                        Change chng)
                 throws Exception
Opens this file for edit.
See Also:
openForEdit(Env, String, boolean, boolean, boolean, Change)

openForEdit

public static FileEntry openForEdit(Env env,
                                    String path,
                                    boolean sync,
                                    boolean force,
                                    boolean lock,
                                    Change chng)
                             throws Exception
Opens the file on the path for edit under the change. If the change is null, the file is opened under the default changelist.
Parameters:
env - P4 Environment
path - Depot or client path to the file being opened for edit.
sync - If true, the file will be sync'd before opened for edit.
force - If true, the file will be opened for edit even if it isn't the most recent version.
lock - If true, the file will be locked once opened.
chng - The change that the file will be opened for edit in.

reopen

public void reopen(String type,
                   Change chng)
            throws PerforceException
Reopens the file with the new type or in the new change list.

resolve

public String resolve(boolean force)
               throws IOException
Resolves this file. If the force flag is false, and auto-resolve is attempted (p4 resolve -am). If the force flag is true, an "accept theirs" resolve is completed (p4 resolve -at).
Parameters:
force - Indicates whether the resolve should be forced.

resolveAll

public static String resolveAll(Env env,
                                String flags,
                                String path)
                         throws IOException
Resolves all the files in the path. The flags are used by the 'p4 resolve' command to resolve any files in the path. This is just a simple way to execute the 'p4 resolve' command.
Parameters:
env - Source control environment to use.
flags - 'p4 resolve' command flags.
path - Path over which to resolve. May include wildcards.

resolveAT

public static String resolveAT(Env env,
                               Enumeration en)
                        throws IOException
Forces a resolve on a set of files. The Enumeration contains the set of FileEntry objects that need resolved.
Parameters:
env - Source control environment to use.
en - Enumeration of FileEntry.

revert

public boolean revert()
Reverts this file.

setClientPath

public void setClientPath(String p)
Sets the client path for this file.
Parameters:
p - path for this file on the client system.

setDepotPath

public void setDepotPath(String p)
Sets the depot path for this file.
Parameters:
p - path for this file in the depot.

setDescription

public void setDescription(String d)
Sets the decription for this file

setHaveRev

public void setHaveRev(int rev)
Sets the revision number the client has for this file.

setHeadAction

public void setHeadAction(String action)
Sets the head revision action for this file.

setHeadChange

public void setHeadChange(int change)
Sets the head revision change number for this file.

setHeadDate

public void setHeadDate(String date)
Sets the head date for this file. The expected format for the date is yyyy/MM/dd. The time will default to 12:00:00 AM.

setHeadRev

public void setHeadRev(int rev)
Sets the head revision number for this file.

setHeadTime

public void setHeadTime(long time)
Sets the head revision time for this file.

setHeadType

public void setHeadType(String type)
Sets the head revision type for this file.

setOwner

public void setOwner(String o)
Sets the owner for this file

setSource

public void setSource(FileEntry fent)
Sets the source file entry associated with this file.

setTimeFormat

public void setTimeFormat(String format)
Sets the format used by the getHeadTimeString method. The format of this string is that of the SimpleDateFormat class.

An example format would be setTimeFormat("MM/dd HH:mm:ss");

See Also:
SimpleDateFormat

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.
Overrides:
sync in class SourceControlObject

synchronizeWorkspace

public static Vector synchronizeWorkspace(Env env,
                                          String path)
                                   throws IOException
Returns a Vector of FileEntry objects that reflect what files were changed by the sync process. If path is null, the entire workspace is synchronized to the head revision. The path may contain wildcard characters, as with the command line 'p4 sync' command.
Parameters:
env - Source control environment.
path - Path to synchronize. May include wildcards.

syncWorkspace

public static String syncWorkspace(Env env,
                                   String path)
                            throws IOException
Synchronizes the workspace.
Parameters:
env - Source control environment.
path - Path to synchronize. May include wildcards.

toString

public String toString()
Overrides:
toString in class Object

toXML

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

Perforce

Copyright © 2001, Perforce Software, All rights reserved.