net.sf.statsvn.util
Class SvnInfoUtils

java.lang.Object
  extended by net.sf.statsvn.util.SvnInfoUtils
All Implemented Interfaces:
ISvnInfoProcessor
Direct Known Subclasses:
SvnKitInfo

public class SvnInfoUtils
extends java.lang.Object
implements ISvnInfoProcessor

Utilities class that manages calls to svn info. Used to find repository information, latest revision numbers, and directories.

 

Nested Class Summary
protected static class SvnInfoUtils.SvnInfoHandler
          SAX parser for the svn info --xml command.
 
Field Summary
protected  java.util.HashMap HM_REVISIONS
           
protected  java.util.HashSet HS_DIRECTORIES
           
protected  ISvnProcessor processor
           
protected static java.lang.String SVN_REPO_ROOT_NOTFOUND
           
 
Constructor Summary
SvnInfoUtils(ISvnProcessor processor)
          Invokes info using the svn info command line.
 
Method Summary
 java.lang.String absolutePathToUrl(java.lang.String absolute)
          Converts an absolute path in the repository to a URL, using the repository URL
 java.lang.String absoluteToRelativePath(java.lang.String absolute)
          Converts an absolute path in the repository to a path relative to the working folder root.
 void addDirectory(java.lang.String relativePath)
          Adds a directory to the list of known directories.
 void checkRepoRootAvailable()
          Verifies that the "svn info" command can return the repository root (info available in svn >= 1.3.0)
protected  void clearCache()
           
 boolean existsInWorkingCopy(java.lang.String relativePath)
          Returns true if the file exists in the working copy (according to the svn metadata, and not file system checks).
 java.lang.String getModuleName()
          Assumes #loadInfo(String) has been called.
protected  ISvnProcessor getProcessor()
           
 java.lang.String getRepositoryUrl()
          Assumes #loadInfo() has been invoked.
 java.lang.String getRepositoryUuid()
          Assumes #loadInfo() has been invoked.
 java.lang.String getRevisionNumber(java.lang.String relativePath)
          Returns the revision number of the file in the working copy.
 java.lang.String getRootRevisionNumber()
          Assumes #loadInfo() has been invoked.
 java.lang.String getRootUrl()
          Assumes #loadInfo() has been invoked.
protected  ProcessUtils getSvnInfo(boolean bRootOnly)
          Invokes svn info.
 boolean isDirectory(java.lang.String relativePath)
          Returns true if the path has been identified as a directory.
protected  boolean isQueryNeeded(boolean bRootOnly)
          Do we need to re-invoke svn info?
 void loadInfo()
          Initializes our representation of the repository.
protected  void loadInfo(boolean bRootOnly)
          Loads the information from svn info if needed.
 void loadInfo(java.io.InputStream stream)
          Loads the information from svn info if needed.
 java.lang.String relativePathToUrl(java.lang.String relative)
          Converts a relative path in the working folder to a URL, using the working folder's root URL
 java.lang.String relativeToAbsolutePath(java.lang.String relative)
          Converts a relative path in the working folder to an absolute path in the repository.
protected  void setRepositoryUrl(java.lang.String repositoryUrl)
          Sets the project's repository URL.
protected  void setRepositoryUuid(java.lang.String repositoryUuid)
           
protected  void setRootUrl(java.lang.String rootUrl)
          Sets the project's root URL.
 java.lang.String urlToAbsolutePath(java.lang.String url)
          Converts a url to an absolute path in the repository.
 java.lang.String urlToRelativePath(java.lang.String url)
          Converts a url to a relative path in the repository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SVN_REPO_ROOT_NOTFOUND

protected static final java.lang.String SVN_REPO_ROOT_NOTFOUND
See Also:
Constant Field Values

processor

protected ISvnProcessor processor

HM_REVISIONS

protected final java.util.HashMap HM_REVISIONS

HS_DIRECTORIES

protected final java.util.HashSet HS_DIRECTORIES
Constructor Detail

SvnInfoUtils

public SvnInfoUtils(ISvnProcessor processor)
Invokes info using the svn info command line.

Method Detail

getProcessor

protected ISvnProcessor getProcessor()

absoluteToRelativePath

public java.lang.String absoluteToRelativePath(java.lang.String absolute)
Description copied from interface: ISvnInfoProcessor
Converts an absolute path in the repository to a path relative to the working folder root. Will return null if absolute path does not start with getModuleName();

Specified by:
absoluteToRelativePath in interface ISvnInfoProcessor
Parameters:
absolute - Example (assume getModuleName() returns /trunk/statsvn) /trunk/statsvn/package.html
Returns:
Example: package.html

absolutePathToUrl

public java.lang.String absolutePathToUrl(java.lang.String absolute)
Description copied from interface: ISvnInfoProcessor
Converts an absolute path in the repository to a URL, using the repository URL

Specified by:
absolutePathToUrl in interface ISvnInfoProcessor
Parameters:
absolute - Example: /trunk/statsvn/package.html
Returns:
Example: svn://svn.statsvn.org/statsvn/trunk/statsvn/package.html

relativePathToUrl

public java.lang.String relativePathToUrl(java.lang.String relative)
Description copied from interface: ISvnInfoProcessor
Converts a relative path in the working folder to a URL, using the working folder's root URL

Specified by:
relativePathToUrl in interface ISvnInfoProcessor
Parameters:
relative - Example: src/Messages.java
Returns:
Example: svn://svn.statsvn.org/statsvn/trunk/statsvn/src/Messages.java

relativeToAbsolutePath

public java.lang.String relativeToAbsolutePath(java.lang.String relative)
Description copied from interface: ISvnInfoProcessor
Converts a relative path in the working folder to an absolute path in the repository.

Specified by:
relativeToAbsolutePath in interface ISvnInfoProcessor
Parameters:
relative - Example: src/Messages.java
Returns:
Example: /trunk/statsvn/src/Messages.java

existsInWorkingCopy

public boolean existsInWorkingCopy(java.lang.String relativePath)
Description copied from interface: ISvnInfoProcessor
Returns true if the file exists in the working copy (according to the svn metadata, and not file system checks).

Specified by:
existsInWorkingCopy in interface ISvnInfoProcessor
Parameters:
relativePath - the path
Returns:
true if it exists

getModuleName

public java.lang.String getModuleName()
Description copied from interface: ISvnInfoProcessor
Assumes #loadInfo(String) has been called. Never ends with /, might be empty.

Specified by:
getModuleName in interface ISvnInfoProcessor
Returns:
The absolute path of the root of the working folder in the repository.

getRevisionNumber

public java.lang.String getRevisionNumber(java.lang.String relativePath)
Description copied from interface: ISvnInfoProcessor
Returns the revision number of the file in the working copy.

Specified by:
getRevisionNumber in interface ISvnInfoProcessor
Parameters:
relativePath - the filename
Returns:
the revision number if it exists in the working copy, null otherwise.

getRootRevisionNumber

public java.lang.String getRootRevisionNumber()
Description copied from interface: ISvnInfoProcessor
Assumes #loadInfo() has been invoked.

Specified by:
getRootRevisionNumber in interface ISvnInfoProcessor
Returns:
the root of the working folder's revision number (last checked out revision number)

getRootUrl

public java.lang.String getRootUrl()
Description copied from interface: ISvnInfoProcessor
Assumes #loadInfo() has been invoked.

Specified by:
getRootUrl in interface ISvnInfoProcessor
Returns:
the root of the working folder's url (example: svn://svn.statsvn.org/statsvn/trunk/statsvn)

getRepositoryUuid

public java.lang.String getRepositoryUuid()
Description copied from interface: ISvnInfoProcessor
Assumes #loadInfo() has been invoked.

Specified by:
getRepositoryUuid in interface ISvnInfoProcessor
Returns:
the uuid of the repository

getRepositoryUrl

public java.lang.String getRepositoryUrl()
Description copied from interface: ISvnInfoProcessor
Assumes #loadInfo() has been invoked.

Specified by:
getRepositoryUrl in interface ISvnInfoProcessor
Returns:
the repository url (example: svn://svn.statsvn.org/statsvn)

getSvnInfo

protected ProcessUtils getSvnInfo(boolean bRootOnly)
Invokes svn info.

Parameters:
bRootOnly - true if should we check for the root only or false otherwise (recurse for all files)
Returns:
the response.

isDirectory

public boolean isDirectory(java.lang.String relativePath)
Description copied from interface: ISvnInfoProcessor
Returns true if the path has been identified as a directory.

Specified by:
isDirectory in interface ISvnInfoProcessor
Parameters:
relativePath - the path
Returns:
true if it is a known directory.

addDirectory

public void addDirectory(java.lang.String relativePath)
Description copied from interface: ISvnInfoProcessor
Adds a directory to the list of known directories. Used when inferring implicit actions on deleted paths.

Specified by:
addDirectory in interface ISvnInfoProcessor
Parameters:
relativePath - the relative path.

isQueryNeeded

protected boolean isQueryNeeded(boolean bRootOnly)
Do we need to re-invoke svn info?

Parameters:
bRootOnly - true if we need the root only
Returns:
true if we it needs to be re-invoked.

loadInfo

protected void loadInfo(boolean bRootOnly)
                 throws net.sf.statcvs.input.LogSyntaxException,
                        java.io.IOException
Loads the information from svn info if needed.

Throws:
net.sf.statcvs.input.LogSyntaxException - if the format of the svn info is invalid
java.io.IOException - if we can't read from the response stream.
Parameters:
bRootOnly - load only the root?

loadInfo

public void loadInfo(java.io.InputStream stream)
              throws net.sf.statcvs.input.LogSyntaxException,
                     java.io.IOException
Description copied from interface: ISvnInfoProcessor
Loads the information from svn info if needed.

Specified by:
loadInfo in interface ISvnInfoProcessor
Throws:
net.sf.statcvs.input.LogSyntaxException - if the format of the svn info is invalid
java.io.IOException - if we can't read from the response stream.
Parameters:
stream - the input stream representing an svn info command.

clearCache

protected void clearCache()

loadInfo

public void loadInfo()
              throws net.sf.statcvs.input.LogSyntaxException,
                     java.io.IOException
Description copied from interface: ISvnInfoProcessor
Initializes our representation of the repository.

Specified by:
loadInfo in interface ISvnInfoProcessor
Throws:
net.sf.statcvs.input.LogSyntaxException - if the svn info --xml is malformed
java.io.IOException - if there is an error reading from the stream

urlToAbsolutePath

public java.lang.String urlToAbsolutePath(java.lang.String url)
Description copied from interface: ISvnInfoProcessor
Converts a url to an absolute path in the repository.

Specified by:
urlToAbsolutePath in interface ISvnInfoProcessor
Parameters:
url - Examples: svn://svn.statsvn.org/statsvn/trunk/statsvn, svn://svn.statsvn.org/statsvn/trunk/statsvn/package.html
Returns:
Example: /trunk/statsvn, /trunk/statsvn/package.html

urlToRelativePath

public java.lang.String urlToRelativePath(java.lang.String url)
Description copied from interface: ISvnInfoProcessor
Converts a url to a relative path in the repository.

Specified by:
urlToRelativePath in interface ISvnInfoProcessor
Parameters:
url - Examples: svn://svn.statsvn.org/statsvn/trunk/statsvn, svn://svn.statsvn.org/statsvn/trunk/statsvn/package.html
Returns:
Example: ".", package.html

setRootUrl

protected void setRootUrl(java.lang.String rootUrl)
Sets the project's root URL.

Parameters:
rootUrl -

setRepositoryUrl

protected void setRepositoryUrl(java.lang.String repositoryUrl)
Sets the project's repository URL.

Parameters:
repositoryUrl -

setRepositoryUuid

protected void setRepositoryUuid(java.lang.String repositoryUuid)

checkRepoRootAvailable

public void checkRepoRootAvailable()
                            throws SvnVersionMismatchException
Verifies that the "svn info" command can return the repository root (info available in svn >= 1.3.0)

Specified by:
checkRepoRootAvailable in interface ISvnInfoProcessor
Throws:
SvnVersionMismatchException - if svn info failed to provide a non-empty repository root