org.eclipse.jgit.util
Class FS

java.lang.Object
  extended by org.eclipse.jgit.util.FS

public abstract class FS
extends Object

Abstraction to support various file system operations not in Java.


Field Summary
static FS DETECTED
          The auto-detected implementation selected for this operating system and JRE.
 
Constructor Summary
protected FS()
          Constructs a file system abstraction.
protected FS(FS src)
          Initialize this FS using another's current settings.
 
Method Summary
abstract  boolean canExecute(File f)
          Determine if the file is executable (or not).
static FS detect()
          Auto-detect the appropriate file system abstraction.
static FS detect(Boolean cygwinUsed)
          Auto-detect the appropriate file system abstraction, taking into account the presence of a Cygwin installation on the system.
protected abstract  File discoverGitPrefix()
           
 File gitPrefix()
           
abstract  FS newInstance()
           
protected static String readPipe(File dir, String[] command, String encoding)
          Execute a command and return a single line of output as a String
 File resolve(File dir, String name)
          Resolve this file to its actual path name that the JRE can use.
abstract  boolean retryFailedLockFileCommit()
          Does this file system have problems with atomic renames?
abstract  ProcessBuilder runInShell(String cmd, String[] args)
          Initialize a ProcesssBuilder to run a command using the system shell.
abstract  boolean setExecute(File f, boolean canExec)
          Set a file to be executable by the user.
 FS setGitPrefix(File path)
          Set the $prefix directory C Git uses.
 FS setUserHome(File path)
          Set the user's home directory location.
abstract  boolean supportsExecute()
          Does this operating system and JRE support the execute flag on files?
 File userHome()
          Determine the user's home directory (location where preferences are).
protected  File userHomeImpl()
          Determine the user's home directory (location where preferences are).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DETECTED

public static final FS DETECTED
The auto-detected implementation selected for this operating system and JRE.

Constructor Detail

FS

protected FS()
Constructs a file system abstraction.


FS

protected FS(FS src)
Initialize this FS using another's current settings.

Parameters:
src - the source FS to copy from.
Method Detail

detect

public static FS detect()
Auto-detect the appropriate file system abstraction.

Returns:
detected file system abstraction

detect

public static FS detect(Boolean cygwinUsed)
Auto-detect the appropriate file system abstraction, taking into account the presence of a Cygwin installation on the system. Using jgit in combination with Cygwin requires a more elaborate (and possibly slower) resolution of file system paths.

Parameters:
cygwinUsed -
  • Boolean.TRUE to assume that Cygwin is used in combination with jgit
  • Boolean.FALSE to assume that Cygwin is not used with jgit
  • null to auto-detect whether a Cygwin installation is present on the system and in this case assume that Cygwin is used
Note: this parameter is only relevant on Windows.
Returns:
detected file system abstraction

newInstance

public abstract FS newInstance()
Returns:
a new instance of the same type of FS.

supportsExecute

public abstract boolean supportsExecute()
Does this operating system and JRE support the execute flag on files?

Returns:
true if this implementation can provide reasonably accurate executable bit information; false otherwise.

canExecute

public abstract boolean canExecute(File f)
Determine if the file is executable (or not).

Not all platforms and JREs support executable flags on files. If the feature is unsupported this method will always return false.

Parameters:
f - abstract path to test.
Returns:
true if the file is believed to be executable by the user.

setExecute

public abstract boolean setExecute(File f,
                                   boolean canExec)
Set a file to be executable by the user.

Not all platforms and JREs support executable flags on files. If the feature is unsupported this method will always return false and no changes will be made to the file specified.

Parameters:
f - path to modify the executable status of.
canExec - true to enable execution; false to disable it.
Returns:
true if the change succeeded; false otherwise.

resolve

public File resolve(File dir,
                    String name)
Resolve this file to its actual path name that the JRE can use.

This method can be relatively expensive. Computing a translation may require forking an external process per path name translated. Callers should try to minimize the number of translations necessary by caching the results.

Not all platforms and JREs require path name translation. Currently only Cygwin on Win32 require translation for Cygwin based paths.

Parameters:
dir - directory relative to which the path name is.
name - path name to translate.
Returns:
the translated path. new File(dir,name) if this platform does not require path name translation.

userHome

public File userHome()
Determine the user's home directory (location where preferences are).

This method can be expensive on the first invocation if path name translation is required. Subsequent invocations return a cached result.

Not all platforms and JREs require path name translation. Currently only Cygwin on Win32 requires translation of the Cygwin HOME directory.

Returns:
the user's home directory; null if the user does not have one.

setUserHome

public FS setUserHome(File path)
Set the user's home directory location.

Parameters:
path - the location of the user's preferences; null if there is no home directory for the current user.
Returns:
this.

retryFailedLockFileCommit

public abstract boolean retryFailedLockFileCommit()
Does this file system have problems with atomic renames?

Returns:
true if the caller should retry a failed rename of a lock file.

userHomeImpl

protected File userHomeImpl()
Determine the user's home directory (location where preferences are).

Returns:
the user's home directory; null if the user does not have one.

readPipe

protected static String readPipe(File dir,
                                 String[] command,
                                 String encoding)
Execute a command and return a single line of output as a String

Parameters:
dir - Working directory for the command
command - as component array
encoding -
Returns:
the one-line output of the command

gitPrefix

public File gitPrefix()
Returns:
the $prefix directory C Git would use.

discoverGitPrefix

protected abstract File discoverGitPrefix()
Returns:
the $prefix directory C Git would use.

setGitPrefix

public FS setGitPrefix(File path)
Set the $prefix directory C Git uses.

Parameters:
path - the directory. Null if C Git is not installed.
Returns:
this

runInShell

public abstract ProcessBuilder runInShell(String cmd,
                                          String[] args)
Initialize a ProcesssBuilder to run a command using the system shell.

Parameters:
cmd - command to execute. This string should originate from the end-user, and thus is platform specific.
args - arguments to pass to command. These should be protected from shell evaluation.
Returns:
a partially completed process builder. Caller should finish populating directory, environment, and then start the process.


Copyright © 2012. All Rights Reserved.