org.eclipse.jgit.util
Class SystemReader

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

public abstract class SystemReader
extends Object

Interface to read values from the system.

When writing unit tests, extending this interface with a custom class permits to simulate an access to a system variable or property and permits to control the user's global configuration.


Constructor Summary
SystemReader()
           
 
Method Summary
abstract  long getCurrentTime()
           
 DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
          Returns a date/time format instance for the given styles.
abstract  String getenv(String variable)
           
abstract  String getHostname()
          Gets the hostname of the local host.
static SystemReader getInstance()
           
 Locale getLocale()
           
abstract  String getProperty(String key)
           
 SimpleDateFormat getSimpleDateFormat(String pattern)
          Returns a simple date format instance as specified by the given pattern.
 TimeZone getTimeZone()
           
abstract  int getTimezone(long when)
           
abstract  FileBasedConfig openSystemConfig(Config parent, FS fs)
           
abstract  FileBasedConfig openUserConfig(Config parent, FS fs)
           
static void setInstance(SystemReader newReader)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SystemReader

public SystemReader()
Method Detail

getInstance

public static SystemReader getInstance()
Returns:
the live instance to read system properties.

setInstance

public static void setInstance(SystemReader newReader)
Parameters:
newReader - the new instance to use when accessing properties.

getHostname

public abstract String getHostname()
Gets the hostname of the local host. If no hostname can be found, the hostname is set to the default value "localhost".

Returns:
the canonical hostname

getenv

public abstract String getenv(String variable)
Parameters:
variable - system variable to read
Returns:
value of the system variable

getProperty

public abstract String getProperty(String key)
Parameters:
key - of the system property to read
Returns:
value of the system property

openUserConfig

public abstract FileBasedConfig openUserConfig(Config parent,
                                               FS fs)
Parameters:
parent - a config with values not found directly in the returned config
fs - the file system abstraction which will be necessary to perform certain file system operations.
Returns:
the git configuration found in the user home

openSystemConfig

public abstract FileBasedConfig openSystemConfig(Config parent,
                                                 FS fs)
Parameters:
parent - a config with values not found directly in the returned config. Null is a reasonable value here.
fs - the file system abstraction which will be necessary to perform certain file system operations.
Returns:
the gitonfig configuration found in the system-wide "etc" directory

getCurrentTime

public abstract long getCurrentTime()
Returns:
the current system time

getTimezone

public abstract int getTimezone(long when)
Parameters:
when - TODO
Returns:
the local time zone

getTimeZone

public TimeZone getTimeZone()
Returns:
system time zone, possibly mocked for testing
Since:
1.2

getLocale

public Locale getLocale()
Returns:
the locale to use
Since:
1.2

getSimpleDateFormat

public SimpleDateFormat getSimpleDateFormat(String pattern)
Returns a simple date format instance as specified by the given pattern.

Parameters:
pattern - the pattern as defined in SimpleDateFormat.SimpleDateFormat(String)
Returns:
the simple date format
Since:
2.0

getDateTimeInstance

public DateFormat getDateTimeInstance(int dateStyle,
                                      int timeStyle)
Returns a date/time format instance for the given styles.

Parameters:
dateStyle - the date style as specified in DateFormat.getDateTimeInstance(int, int)
timeStyle - the time style as specified in DateFormat.getDateTimeInstance(int, int)
Returns:
the date format
Since:
2.0


Copyright © 2012. All Rights Reserved.