Package org.eclipse.jgit.util
Class SystemReader
- java.lang.Object
-
- 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
Constructors Constructor Description SystemReader()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcheckPath(String path)Check tree path entry for validity.abstract longgetCurrentTime()DateFormatgetDateTimeInstance(int dateStyle, int timeStyle)Returns a date/time format instance for the given styles.abstract Stringgetenv(String variable)abstract StringgetHostname()Gets the hostname of the local host.static SystemReadergetInstance()LocalegetLocale()abstract StringgetProperty(String key)SimpleDateFormatgetSimpleDateFormat(String pattern)Returns a simple date format instance as specified by the given pattern.SimpleDateFormatgetSimpleDateFormat(String pattern, Locale locale)Returns a simple date format instance as specified by the given pattern.abstract intgetTimezone(long when)TimeZonegetTimeZone()booleanisMacOS()booleanisWindows()abstract FileBasedConfigopenSystemConfig(Config parent, FS fs)abstract FileBasedConfigopenUserConfig(Config parent, FS fs)static voidsetInstance(SystemReader newReader)protected voidsetPlatformChecker()Should be used in tests when the platform is explicitly changed.
-
-
-
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, or null for the default instance.
-
setPlatformChecker
protected final void setPlatformChecker()
Should be used in tests when the platform is explicitly changed.- Since:
- 3.6
-
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 configfs- 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 inSimpleDateFormat(String)- Returns:
- the simple date format
- Since:
- 2.0
-
getSimpleDateFormat
public SimpleDateFormat getSimpleDateFormat(String pattern, Locale locale)
Returns a simple date format instance as specified by the given pattern.- Parameters:
pattern- the pattern as defined inSimpleDateFormat(String)locale- locale to be used for theSimpleDateFormat- Returns:
- the simple date format
- Since:
- 3.2
-
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 inDateFormat.getDateTimeInstance(int, int)timeStyle- the time style as specified inDateFormat.getDateTimeInstance(int, int)- Returns:
- the date format
- Since:
- 2.0
-
isWindows
public boolean isWindows()
- Returns:
- true if we are running on a Windows.
-
isMacOS
public boolean isMacOS()
- Returns:
- true if we are running on Mac OS X
-
checkPath
public void checkPath(String path) throws CorruptObjectException
Check tree path entry for validity.Scans a multi-directory path string such as
"src/main.c".- Parameters:
path- path string to scan.- Throws:
CorruptObjectException- path is invalid.- Since:
- 3.6
-
-