class PathResolver extends java.lang.Object
Finds executable in the PATH Reproduces the native mechanisms that Windows and Unix-like systems use to find executable in the directories specified in the PATH variables. Java doesn't allow to overwrite the PATH variable of the current process, and we actually don't want to do that anyway, since it is used for the whole process and any new child processes. Theoretically, we could also use ProcessBuilder to start a CMD.EXE or bash process to force the system to resolve the PATH, but reproducing the system algorithms is probably easier to understand, test and debug. It also avoids an unnecessary process.
| Modifiers | Name | Description |
|---|---|---|
static enum |
PathResolver.OperatingSystem |
| Type | Name and description |
|---|---|
java.lang.Object |
PATHEXT |
PathResolver.OperatingSystem |
forcedOs |
java.lang.Object |
paths |
| Constructor and description |
|---|
PathResolver
(java.lang.String pathVariable)Creates a resolver from the given PATH variable value. |
PathResolver
(java.util.List<java.io.File> pathList)Creates a resolver from the given list of paths |
| Type Params | Return Type | Name and description |
|---|---|---|
|
java.io.File |
find(java.lang.String requestedName)Find a program based on it's name |
|
void |
forceOperatingSystem(PathResolver.OperatingSystem os)Force the resoler to assume the given OS. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Creates a resolver from the given PATH variable value.
pathVariable - list of directories to search separated by ";" (Windows) or ";" (Unix)Creates a resolver from the given list of paths
pathList - list of directories to searchFind a program based on it's name
requestedName - the program's nameForce the resoler to assume the given OS. Used for testing only.
os - the OS to assumeGroovy Documentation