|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.microsoft.tfs.core.clients.versioncontrol.path.LocalPath
public abstract class LocalPath
Static methods to process local (disk) paths.
Field Summary | |
---|---|
static java.util.Comparator<java.lang.String> |
BOTTOM_UP_COMPARATOR
Compares well-formed local path strings in a bottom-up fashion (children sort before their parents). |
static java.lang.String |
GENERAL_LOCAL_PATH_SEPARATOR
|
static char |
TFS_PREFERRED_LOCAL_PATH_SEPARATOR
|
static java.util.Comparator<java.lang.String> |
TOP_DOWN_COMPARATOR
Compares well-formed local path strings in a top-down fashion (parents sort before their children). |
Constructor Summary | |
---|---|
LocalPath()
|
Method Summary | |
---|---|
static java.lang.String |
addTrailingSeparator(java.lang.String path)
Returns the given path string with a trailing separator (as specified by File.separator). |
static java.lang.String |
canonicalize(java.lang.String path)
Gets the canonical form of the given path. |
static void |
check8Dot3Aliases(java.lang.String item)
Checks whether the given item contains any 8.3 aliases and throws if it does. |
static void |
checkForIllegalDollarInPath(java.lang.String path)
This method throws an InvalidPathException if there is a dollar sign ('$') that follows a path separator ('/' or '\') since no part of a path is allowed to start with a dollar sign. |
static ItemValidationError |
checkLocalItem(java.lang.String item,
java.lang.String parameterName,
boolean allowNull,
boolean allowWildcards,
boolean allow8Dot3Paths,
boolean checkReservedCharacters)
|
static java.lang.String |
combine(java.lang.String parent,
java.lang.String relative)
Combines the two given paths into one path string, using this platform's preferred path separator character. |
static int |
compareBottomUp(java.lang.String pathA,
java.lang.String pathB)
Compares two server paths (ordinal character comparison) placing parents after their children. |
static int |
compareTopDown(java.lang.String pathA,
java.lang.String pathB)
Compares two local paths (ordinal character comparison) placing children after their parents. |
static boolean |
endsWith(java.lang.String path,
java.lang.String suffix)
|
static boolean |
equals(java.lang.String path1,
java.lang.String path2)
Compares two local paths for equality. |
static boolean |
equals(java.lang.String path1,
java.lang.String path2,
boolean forceIgnoreCase)
Compares two local paths for equality, optionally forcing the comparison to ignore character case. |
static boolean |
exists(java.lang.String filePath)
Helper method to check whether a file/dir exists |
protected static java.lang.String |
expandTildeToHome(java.lang.String pathString)
Expands any "~user" or "~" sequences in the given local path string to the absolute paths to those directories, preserving any trailing path parts. |
static java.lang.String |
getCommonPathPrefix(java.lang.String path1,
java.lang.String path2)
Given two canonicalized paths (that never end with a filesystem separator except for a drive letter root on Windows), returns the longest path prefix which is common to both paths. |
static java.lang.String |
getCurrentWorkingDirectory()
Gets the full path to the current working directory. |
static java.lang.String |
getDirectory(java.lang.String path)
Returns the directory part of the local path. |
static java.lang.String |
getFileExtension(java.lang.String localPath)
Gets the extension of the given local path -- everything from the last '.' of the file part (including the '.'). |
static java.lang.String |
getFileName(java.lang.String localPath)
Gets just the file part of the given local path, which is all of the string after the last path component. |
static int |
getFolderDepth(java.lang.String localPath)
Calls getFolderDepth(String, Platform) with
Platform.getCurrentPlatform() as the Platform argument. |
static int |
getFolderDepth(java.lang.String localPath,
com.microsoft.tfs.util.Platform platform)
Returns the depth of the item described by path, where the root folder is depth 0, items in root are 1, items below that are 2, etc. |
static java.lang.String[] |
getHierarchy(java.lang.String path)
Returns all directories leading up to (and including) the given path, from the root of the local filesystem. |
static java.lang.String[] |
getHierarchy(java.lang.String fromPath,
java.lang.String toPath)
Get file hierarchy from fromPath to toPath e.g. |
static java.lang.String |
getLastComponent(java.lang.String path)
Return the the last path component in the supplied path. |
static java.lang.String |
getParent(java.lang.String path)
Returns the parent directory name of the given local path. |
static java.lang.String |
getPathRoot(java.lang.String path)
Returns the root portion of the given path. |
protected static java.lang.String |
getPathRoot(java.lang.String path,
com.microsoft.tfs.util.Platform platform)
|
protected static int |
getRootLength(java.lang.String path)
|
protected static int |
getRootLength(java.lang.String path,
com.microsoft.tfs.util.Platform platform)
Gets the length of the root DirectoryInfo or whatever DirectoryInfo markers are specified for the first part of the DirectoryInfo name. |
static int |
hashCode(java.lang.String localPath)
Returns a hash code for the given local path. |
static boolean |
hasVersionControlReservedCharacter(java.lang.String path,
java.util.concurrent.atomic.AtomicReference<java.lang.Character> c)
Returns true if the path contains any character which is a version control reserved character. |
static boolean |
isChild(java.lang.String parentPath,
java.lang.String possibleChild)
Tests the given paths for a parent-child relationship. |
static boolean |
isDirectChild(java.lang.String parentPath,
java.lang.String possibleChild)
Tests whether one path is a direct child of another path (which would be the parent). |
static boolean |
isDirectoryEmpty(java.lang.String localPath)
Tests whether a directory is empty (contains no files or directories). |
static boolean |
isPathRooted(java.lang.String path)
Tests whether the given path starts with a drive root prefix. |
static boolean |
isWildcard(java.lang.String localPath)
Tests whether the given local path contains wildcard characters in its final path element. |
static boolean |
lastPartEqualsCaseSensitive(java.lang.String path1,
java.lang.String path2)
Compare two file paths in a platform-default-case-sensitivity fashion on every portion of the path except for the last item in the path. |
static java.lang.String |
makeRelative(java.lang.String localPath,
java.lang.String relativeTo)
Returns a new string describing the first given path made relative to the second given path. |
static java.lang.String |
makeServer(java.lang.String localPath,
java.lang.String relativeToLocalPath,
java.lang.String serverRoot)
Maps a local path to a server path, given a parent local path of the path to be mapped, and a server path that corresponds to the parent. |
static boolean |
matchesWildcard(java.lang.String firstItemPath,
java.lang.String secondItemFolderPath,
java.lang.String secondItemWildcardPattern,
boolean recursive)
Matches one item against a wildcard tuple (item path and wildcard pattern to apply to that item path), optionally allowing recursive matches. |
static java.lang.String |
nativeToTFS(java.lang.String localPath)
Converts this platform's file path to TFS's preferred separator (backslash) and roots it in a DOS-style drive letter if not already rooted in one. |
static java.lang.String |
removeTrailingSeparators(java.lang.String path)
Returns the given path string without trailing separators (as specified by File.separator). |
static boolean |
startsWith(java.lang.String path,
java.lang.String prefix)
|
static java.lang.String |
tfsToNative(java.lang.String localPath)
Converts a TFS-style path into this platform's pathstyle. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final char TFS_PREFERRED_LOCAL_PATH_SEPARATOR
92
public static final java.lang.String GENERAL_LOCAL_PATH_SEPARATOR
"/"
public static final java.util.Comparator<java.lang.String> TOP_DOWN_COMPARATOR
public static final java.util.Comparator<java.lang.String> BOTTOM_UP_COMPARATOR
Constructor Detail |
---|
public LocalPath()
Method Detail |
---|
public static final java.lang.String getCurrentWorkingDirectory()
public static final boolean equals(java.lang.String path1, java.lang.String path2)
Compares two local paths for equality. Character case is honored when the
operating system is case-sensitive (
FileHelpers.doesFileSystemIgnoreCase()
). Paths are not normalized
(".." segments removed) before comparison.
Two null paths are equal, but a null path does not equal a non-null path.
path1
- the first local path (may be null
)path2
- the second local path (may be null
)
public static final boolean equals(java.lang.String path1, java.lang.String path2, boolean forceIgnoreCase)
Compares two local paths for equality, optionally forcing the comparison to ignore character case. Paths are not normalized (".." segments removed) before comparison.
Two null paths are equal, but a null path does not equal a non-null path.
path1
- the first local path (may be null
)path2
- the second local path (may be null
)forceIgnoreCase
- if true
, case is always ignored in the comparison. If
false
, case is only ignored if
FileHelpers.doesFileSystemIgnoreCase()
returns
true
hashCode(String)
public static final boolean startsWith(java.lang.String path, java.lang.String prefix)
public static final boolean endsWith(java.lang.String path, java.lang.String suffix)
public static final boolean lastPartEqualsCaseSensitive(java.lang.String path1, java.lang.String path2)
path1
- the first local path (must not be null
)path2
- the second local path (must not be null
)
FileHelpers.doesFileSystemIgnoreCase()
public static final int hashCode(java.lang.String localPath)
equals(String, String)
is
used to test for equality so the case-sensitivity behavior matches (and
the hashCode/equals contract is maintained).
localPath
- the local path to compute the hash code for (must not be
null
)
public static boolean isDirectChild(java.lang.String parentPath, java.lang.String possibleChild)
parentPath
- the path to the parent folder (must not be null
)possibleChild
- the path of the possible child item (must not be null
)
public static final boolean isChild(java.lang.String parentPath, java.lang.String possibleChild)
Tests the given paths for a parent-child relationship. A path is a child of another if the object it describes would reside below the object described by the parent path in the local filesystem. Case is respected on a per-platform basis.
A possible child that is equivalent to the parent path (both refer to the same object) is considered a child. This is compatible with Visual Studio's behavior.
The given paths are not canonicalized before testing.
The given paths must be in the OS's native path format.
parentPath
- the local path to the parent item (not null).possibleChild
- the local path of the possible child item (not null).
public static final boolean isDirectoryEmpty(java.lang.String localPath)
localPath
- the local directory path to test (must not be null
)
public static final java.lang.String tfsToNative(java.lang.String localPath)
localPath
- the TFS-style local path string to convert. If null, null is
returned.
public static final java.lang.String nativeToTFS(java.lang.String localPath)
localPath
- the absolute local path string to convert to TFS-style separators.
If null, null is returned.
public static int getFolderDepth(java.lang.String localPath)
getFolderDepth(String, Platform)
with
Platform.getCurrentPlatform()
as the Platform
argument.
getFolderDepth(String, Platform)
public static int getFolderDepth(java.lang.String localPath, com.microsoft.tfs.util.Platform platform)
Returns the depth of the item described by path, where the root folder is depth 0, items in root are 1, items below that are 2, etc. UNC paths are supported on Windows, but are not supported on other platforms (an exception is thrown). The path must be absolute, well-formed, and must not contain . or .. segments.
On Windows, UNC paths and drive letters are supported. In this case a
string like "\\server\share\" is the root path (depth 0). If the share
name part is not specified, IllegalArgumentException
is thrown.
On non-Windows platforms, parsing UNC and drive letter paths is undefined because those paths would not be valid absolute local paths (all absolute paths must start with "/" and UNC and drive letters do not).
Safe for remote paths. Does not access the local disk or network shares.
localPath
- the local path to test (not null
or empty)platform
- the Platform
whose path conventions should be used (must
not be null
)
java.lang.IllegalArgumentException
- if the path is not absolute, or is in an invalid format, or
another argument requirement was not satisfiedpublic static final java.lang.String combine(java.lang.String parent, java.lang.String relative)
parent
- the first (left-side) path component (must not be
null
)relative
- the second (right-side) path component (must not be
null
)public static java.lang.String[] getHierarchy(java.lang.String path)
path
- the path to get parent paths for (must not be null
)
public static java.lang.String[] getHierarchy(java.lang.String fromPath, java.lang.String toPath)
fromPath
- Path
-
public static java.lang.String getParent(java.lang.String path)
getDirectory(String)
in that it will always return
the parent path, regardless of whether path is a file or folder.
path
- the local path (file or directory) to get the parent directory of
(must not be null
)
public static java.lang.String getDirectory(java.lang.String path)
path
- the local path (file or directory) to get the directory part of
(must not be null
)
public static java.lang.String getFileName(java.lang.String localPath)
localPath
- the local path from which to parse the file part (must not be
null
)
public static java.lang.String getFileExtension(java.lang.String localPath)
localPath
- the local path to parse the extension from (must not be
null
)
public static final java.lang.String getLastComponent(java.lang.String path)
path
- the path string to examine (must not be null
)
public static final int compareTopDown(java.lang.String pathA, java.lang.String pathB)
If sorting paths for display to the user, better to use a
Collator
-based comparison instead of this one.
pathA
- the first path to compare (must not be null
)pathB
- the second path to compare (must not be null
)
Comparable.compareTo(Object)
FileHelpers.doesFileSystemIgnoreCase()
public static final int compareBottomUp(java.lang.String pathA, java.lang.String pathB)
If sorting paths for display to the user, better to use a
Collator
-based comparison instead of this one.
pathA
- the first path to compare (must not be null
)pathB
- the second path to compare (must not be null
)
Comparable.compareTo(Object)
FileHelpers.doesFileSystemIgnoreCase()
public static final java.lang.String canonicalize(java.lang.String path)
Gets the canonical form of the given path. On Unix platforms (including Mac OS X), a path that begins with "~" or "~user", where user is a user name on this host, is expanded to the full path to the absolute path to the user's home directory (and any other path components, of course).
On case-preserving but case-insensitive filesystems, this implementation
differs from Java's File.getCanonicalPath()
in one important way:
if the given path string refers to a filesystem object (file or
directory) that exists on disk but has a name (not path) that differs
only in character case, the path is still made canonical according to
File.getCanonicalPath()
but the character case of the final path
element (object's name) is taken from the given path. If the given path
does not exist on disk, or does exist but the final elements have
matching character case, the path returned by
File.getCanonicalPath()
is returned. This behavior allows us to
make a relative path string "canonical" (in the LocalPath
way)
and support the case-changing rename case (where only the case of the
file changes).
On case-sensitive filesystems (most Unixes, not Mac OS X) this method
behaves exactly like Java's File.getCanonicalPath()
.
path
- the path to canonicalize. If null is given, null is returned.
public static boolean isWildcard(java.lang.String localPath)
Tests whether the given local path contains wildcard characters in its final path element. Wildcards in initial path elements (intermediate directories) are ignored.
Character case is ignored during wildcard matching.
localPath
- the local path to test for wildcards (in last element only). Not
null.
public static final boolean matchesWildcard(java.lang.String firstItemPath, java.lang.String secondItemFolderPath, java.lang.String secondItemWildcardPattern, boolean recursive)
Matches one item against a wildcard tuple (item path and wildcard pattern to apply to that item path), optionally allowing recursive matches.
Character case is ignored during wildcard matching.
firstItemPath
- the item to test against the wildcard pattern. This is a full path
(must not be null
)secondItemFolderPath
- a path where the wildcard pattern will be applied to find the item
described by firstItemPath. If this parameter is a child of
firstItemPath, there wildcard pattern will never match. If this
parameter is a direct parent of firstItemPath, the wildcard can
match. If this parameter is a grandparent (or greater), the
pattern can only match if the recursive parameter is true. If this
parameter is null, false is returned.secondItemWildcardPattern
- the wildcard pattern to apply to secondItemFolderPath.recursive
- if true, the wildcard pattern will apply to secondItemFolderPath
and all its possible children. If false, the wildcard pattern will
only match direct children of secondItemFolderPath.
public static java.lang.String makeRelative(java.lang.String localPath, java.lang.String relativeTo)
Returns a new string describing the first given path made relative to the second given path.
Character case is ignored during string comparison, so strings with mismatched-in-case common elements will still succeed in being made relative.
Paths are not normalized (for ending separators, case, etc.). It is the caller's responsibility to make sure the relativeTo path can be matched.
localPath
- the path to the local item to describe (must not be
null
)relativeTo
- the path that the first parameter will be described relative to
(must not be null
)
public static java.lang.String makeServer(java.lang.String localPath, java.lang.String relativeToLocalPath, java.lang.String serverRoot)
Maps a local path to a server path, given a parent local path of the path to be mapped, and a server path that corresponds to the parent.
Character case is ignored during string comparison, so strings with mismatched-in-case common elements will still succeed in being made relative.
Paths are not normalized (for ending separators, case, etc.). It is the caller's responsibility to make sure the relativeToLocalPath path can be matched.
localPath
- the local path to convert to a server path (must not be
null
)relativeToLocalPath
- the parent local path (must not be null
and must be a
parent of localPath
)serverRoot
- the server path that corresponds to
relativeToLocalPath
(must not be null
)
null
)public static java.lang.String removeTrailingSeparators(java.lang.String path)
path
- the string to strip trailing separators from.
public static java.lang.String addTrailingSeparator(java.lang.String path)
path
- the string to add a trailing separator.
protected static java.lang.String expandTildeToHome(java.lang.String pathString)
Expands any "~user" or "~" sequences in the given local path string to the absolute paths to those directories, preserving any trailing path parts. The JNI home directory lookup is only performed if this platform is not Windows and the "~user" format is encountered.
Also, leading whitespace is always removed from the given path string.
pathString
- the path string to expand for tildes (must not be
null
)
public static ItemValidationError checkLocalItem(java.lang.String item, java.lang.String parameterName, boolean allowNull, boolean allowWildcards, boolean allow8Dot3Paths, boolean checkReservedCharacters)
public static boolean hasVersionControlReservedCharacter(java.lang.String path, java.util.concurrent.atomic.AtomicReference<java.lang.Character> c)
path
- the string to check for invalid characters (must not be
null
)c
- a reference to a Character
where the invalid detected
character will be stored if the method returns true
(no character is stored if the method returns false
)
(may be null
)
public static void check8Dot3Aliases(java.lang.String item)
public static boolean isPathRooted(java.lang.String path)
path
- the local path to test (may be null
)
null
or empty)public static java.lang.String getPathRoot(java.lang.String path)
null
if path is null
.
path
- the path to get the root for (may be null
)
null
if a
null
path was given)protected static java.lang.String getPathRoot(java.lang.String path, com.microsoft.tfs.util.Platform platform)
protected static int getRootLength(java.lang.String path)
getRootLength(String, Platform)
protected static int getRootLength(java.lang.String path, com.microsoft.tfs.util.Platform platform)
path
- the local path to get the root length for (must not be
null
)platform
- the Platform
whose path conventions should be used (must
not be null
)public static void checkForIllegalDollarInPath(java.lang.String path)
path
- the path to check (path must already be canonicalized)public static java.lang.String getCommonPathPrefix(java.lang.String path1, java.lang.String path2)
null
prefix for files that reside on the same drive: the
drive letter and a trailing backslash and possibly more directory parts.null
in this case since these
paths do have a common parent, so "/" is returned.
path1
- the first path (must not be null
or empty)path2
- the second path (must not be null
or empty)
null
if
the paths have nothing in commonpublic static boolean exists(java.lang.String filePath)
filePath
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |