java.lang.Object
org.eclipse.jgit.util.SystemReader
- Direct Known Subclasses:
SystemReader.Delegate
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.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckPath(byte[] path) Check tree path entry for validity.voidCheck tree path entry for validity.civilNow()Get "now" as civil time, in the System timezonegetClock()Get clock instance preferred by this system.abstract longDeprecated.getDateTimeInstance(int dateStyle, int timeStyle) Returns a date/time format instance for the given styles.Retrieves the defaultCharsetdepending on the system locale.abstract StringGet value of the system variableabstract StringGets the hostname of the local host.static SystemReaderGet the current SystemReader instanceGet the jgit configuration located at $XDG_CONFIG_HOME/jgit/config.Get the locale to useabstract StringgetProperty(String key) Get value of the system propertygetSimpleDateFormat(String pattern) Returns a simple date format instance as specified by the given pattern.getSimpleDateFormat(String pattern, Locale locale) Returns a simple date format instance as specified by the given pattern.Get the gitconfig configuration found in the system-wide "etc" directory.abstract intgetTimezone(long when) Deprecated.UsegetTimeZoneAt(Instant)instead.Deprecated.UsegetTimeZoneId()getTimeZoneAt(Instant when) Get the local time zone offset at "when" timeGet system time zone, possibly mocked for testingGet the git configuration found in the user home.getXdgCacheDirectory(FS fileSystem) Gets the directory denoted by environment variable XDG_CACHE_HOME.getXdgConfigDirectory(FS fileSystem) Gets the directory denoted by environment variable XDG_CONFIG_HOME.booleanisLinux()Whether we are running on Linux.booleanisMacOS()Whether we are running on Mac OS XbooleanWhether performance trace is enabledbooleanWhether we are running on Windows.now()Get the current system timeabstract FileBasedConfigopenJGitConfig(Config parent, FS fs) Open the jgit configuration located at $XDG_CONFIG_HOME/jgit/config.abstract FileBasedConfigopenSystemConfig(Config parent, FS fs) Open the gitconfig configuration found in the system-wide "etc" directory.abstract FileBasedConfigopenUserConfig(Config parent, FS fs) Open the git configuration found in the user home.static voidsetInstance(SystemReader newReader) Set a new SystemReader instance to use when accessing properties.protected final voidShould be used in tests when the platform is explicitly changed.
-
Constructor Details
-
SystemReader
public SystemReader()
-
-
Method Details
-
getInstance
Get the current SystemReader instance- Returns:
- the current SystemReader instance.
-
setInstance
Set a new SystemReader instance to use when accessing properties.- 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
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
Get value of the system variable- Parameters:
variable- system variable to read- Returns:
- value of the system variable
-
getProperty
Get value of the system property- Parameters:
key- of the system property to read- Returns:
- value of the system property
-
openUserConfig
Open the git configuration found in the user home. UsegetUserConfig()to get the current git configuration in the user home since it manages automatic reloading when the gitconfig file was modified and avoids unnecessary reloads.- 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
Open the gitconfig configuration found in the system-wide "etc" directory. UsegetSystemConfig()to get the current system-wide git configuration since it manages automatic reloading when the gitconfig file was modified and avoids unnecessary reloads.- 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 gitconfig configuration found in the system-wide "etc" directory
-
openJGitConfig
Open the jgit configuration located at $XDG_CONFIG_HOME/jgit/config. UsegetJGitConfig()to get the current jgit configuration in the user home since it manages automatic reloading when the jgit config file was modified and avoids unnecessary reloads.- 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 jgit configuration located at $XDG_CONFIG_HOME/jgit/config
- Since:
- 5.5.2
-
getUserConfig
Get the git configuration found in the user home. The configuration will be reloaded automatically if the configuration file was modified. Also reloads the system config if the system config file was modified. If the configuration file wasn't modified returns the cached configuration.- Returns:
- the git configuration found in the user home
- Throws:
ConfigInvalidException- if configuration is invalidIOException- if something went wrong when reading files- Since:
- 5.1.9
-
getJGitConfig
Get the jgit configuration located at $XDG_CONFIG_HOME/jgit/config. The configuration will be reloaded automatically if the configuration file was modified. If the configuration file wasn't modified returns the cached configuration.- Returns:
- the jgit configuration located at $XDG_CONFIG_HOME/jgit/config
- Throws:
ConfigInvalidException- if configuration is invalidIOException- if something went wrong when reading files- Since:
- 5.5.2
-
getSystemConfig
Get the gitconfig configuration found in the system-wide "etc" directory. The configuration will be reloaded automatically if the configuration file was modified otherwise returns the cached system level config.- Returns:
- the gitconfig configuration found in the system-wide "etc" directory
- Throws:
ConfigInvalidException- if configuration is invalidIOException- if something went wrong when reading files- Since:
- 5.1.9
-
getXdgConfigDirectory
Gets the directory denoted by environment variable XDG_CONFIG_HOME. If the variable is not set or empty, return a path for$HOME/.config. -
getXdgCacheDirectory
Gets the directory denoted by environment variable XDG_CACHE_HOME. If the variable is not set or empty, return a path for$HOME/.cache. -
getCurrentTime
Deprecated.Usenow()Get the current system time- Returns:
- the current system time
-
now
Get the current system time- Returns:
- the current system time
- Since:
- 7.1
-
civilNow
Get "now" as civil time, in the System timezone- Returns:
- the current system time
- Since:
- 7.1
-
getClock
Get clock instance preferred by this system.- Returns:
- clock instance preferred by this system.
- Since:
- 4.6
-
getTimezone
Deprecated.UsegetTimeZoneAt(Instant)instead.Get the local time zone- Parameters:
when- a system timestamp- Returns:
- the local time zone
-
getTimeZoneAt
Get the local time zone offset at "when" time- Parameters:
when- a system timestamp- Returns:
- the local time zone
- Since:
- 7.1
-
getTimeZone
Deprecated.UsegetTimeZoneId()Get system time zone, possibly mocked for testing- Returns:
- system time zone, possibly mocked for testing
- Since:
- 1.2
-
getTimeZoneId
Get system time zone, possibly mocked for testing- Returns:
- system time zone, possibly mocked for testing
- Since:
- 7.1
-
getLocale
Get the locale to use- Returns:
- the locale to use
- Since:
- 1.2
-
getDefaultCharset
Retrieves the defaultCharsetdepending on the system locale. -
getSimpleDateFormat
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
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
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()Whether we are running on Windows.- Returns:
- true if we are running on Windows.
-
isMacOS
public boolean isMacOS()Whether we are running on Mac OS X- Returns:
- true if we are running on Mac OS X
-
isLinux
public boolean isLinux()Whether we are running on Linux.- Returns:
- true if we are running on Linux.
- Since:
- 6.3
-
isPerformanceTraceEnabled
public boolean isPerformanceTraceEnabled()Whether performance trace is enabled- Returns:
- whether performance trace is enabled
- Since:
- 6.5
-
checkPath
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
-
checkPath
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:
- 4.2
-
now()