Class FileBasedConfig
- java.lang.Object
-
- org.eclipse.jgit.lib.Config
-
- org.eclipse.jgit.lib.StoredConfig
-
- org.eclipse.jgit.storage.file.FileBasedConfig
-
public class FileBasedConfig extends StoredConfig
The configuration file that is stored in the file of the file system.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jgit.lib.Config
Config.ConfigEnum, Config.SectionParser<T>
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.File
configFile
private FS
fs
private ObjectId
hash
private static org.slf4j.Logger
LOG
private FileSnapshot
snapshot
private boolean
utf8Bom
-
Constructor Summary
Constructors Constructor Description FileBasedConfig(java.io.File cfgLocation, FS fs)
Create a configuration with no default fallback.FileBasedConfig(Config base, java.io.File cfgLocation, FS fs)
The constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear the configuration filejava.io.File
getFile()
Get location of the configuration file on diskprivate static ObjectId
hash(byte[] rawText)
boolean
isOutdated()
Whether the currently loaded configuration file is outdatedvoid
load()
Load the configuration from the persistent store.protected boolean
notifyUponTransientChanges()
Determine whether to issue change events for transient changes.protected byte[]
readIncludedConfig(java.lang.String relPath)
Read the included config from the specified (possibly) relative pathvoid
save()
Save the configuration to the persistent store.java.lang.String
toString()
-
Methods inherited from class org.eclipse.jgit.lib.Config
addChangeListener, fireConfigChangedEvent, fromText, get, getBaseConfig, getBoolean, getBoolean, getEnum, getEnum, getInt, getInt, getLong, getLong, getNames, getNames, getNames, getNames, getPath, getRefSpecs, getSections, getString, getStringList, getSubsections, getTimeUnit, isMissing, isUtf8, setBoolean, setEnum, setInt, setLong, setString, setStringList, setTypedConfigGetter, toText, uncache, unset, unsetSection
-
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
configFile
private final java.io.File configFile
-
fs
private final FS fs
-
utf8Bom
private boolean utf8Bom
-
snapshot
private volatile FileSnapshot snapshot
-
hash
private volatile ObjectId hash
-
-
Constructor Detail
-
FileBasedConfig
public FileBasedConfig(java.io.File cfgLocation, FS fs)
Create a configuration with no default fallback.- Parameters:
cfgLocation
- the location of the configuration file on the file systemfs
- the file system abstraction which will be necessary to perform certain file system operations.
-
FileBasedConfig
public FileBasedConfig(Config base, java.io.File cfgLocation, FS fs)
The constructor- Parameters:
base
- the base configuration filecfgLocation
- the location of the configuration file on the file systemfs
- the file system abstraction which will be necessary to perform certain file system operations.
-
-
Method Detail
-
notifyUponTransientChanges
protected boolean notifyUponTransientChanges()
Determine whether to issue change events for transient changes.If
true
is returned (which is the default behavior),Config.fireConfigChangedEvent()
will be called upon each change.Subclasses that override this to return
false
are responsible for issuingConfig.fireConfigChangedEvent()
calls themselves.- Overrides:
notifyUponTransientChanges
in classConfig
- Returns:
-
getFile
public final java.io.File getFile()
Get location of the configuration file on disk- Returns:
- location of the configuration file on disk
-
load
public void load() throws java.io.IOException, ConfigInvalidException
Load the configuration from the persistent store.If the configuration does not exist, this configuration is cleared, and thus behaves the same as though the backing store exists, but is empty.
Load the configuration as a Git text style configuration file.
If the file does not exist, this configuration is cleared, and thus behaves the same as though the file exists, but is empty.
- Specified by:
load
in classStoredConfig
- Throws:
java.io.IOException
- the configuration could not be read (but does exist).ConfigInvalidException
- the configuration is not properly formatted.
-
save
public void save() throws java.io.IOException
Save the configuration to the persistent store.Save the configuration as a Git text style configuration file.
Warning: Although this method uses the traditional Git file locking approach to protect against concurrent writes of the configuration file, it does not ensure that the file has not been modified since the last read, which means updates performed by other objects accessing the same backing file may be lost.
- Specified by:
save
in classStoredConfig
- Throws:
java.io.IOException
- the configuration could not be written.
-
clear
public void clear()
Clear the configuration file- Overrides:
clear
in classStoredConfig
-
hash
private static ObjectId hash(byte[] rawText)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isOutdated
public boolean isOutdated()
Whether the currently loaded configuration file is outdated- Returns:
- returns true if the currently loaded configuration file is older than the file on disk
-
readIncludedConfig
protected byte[] readIncludedConfig(java.lang.String relPath) throws ConfigInvalidException
Read the included config from the specified (possibly) relative path- Overrides:
readIncludedConfig
in classConfig
- Parameters:
relPath
- possibly relative path to the included config, as specified in this config- Returns:
- the read bytes, or null if the included config should be ignored
- Throws:
ConfigInvalidException
- if something went wrong while reading the config- Since:
- 4.10
-
-