Class Settings
java.lang.Object
org.owasp.dependencycheck.utils.Settings
A simple settings container that wraps the dependencycheck.properties file.
- Version:
- $Id: $Id
- Author:
- Jeremy Long
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe collection of keys used within the properties file. -
Constructor Summary
ConstructorsConstructorDescriptionSettings()Initialize the settings object.Initialize the settings object using the given properties file.Settings(Properties properties) Initialize the settings object using the given properties. -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanup()Cleans up resources to prevent memory leaks.voidcleanup(boolean deleteTemporary) Cleans up resources to prevent memory leaks.String[]Returns a list with the given key.booleangetBoolean(@NonNull String key) Returns a boolean value from the properties file.booleangetBoolean(@NonNull String key, boolean defaultValue) Returns a boolean value from the properties file.getConnectionString(String connectionStringKey, String dbFileNameKey) Returns a connection string from the configured properties.Retrieves the primary data directory that is used for caching web content.@Nullable FileReturns a value from the properties file as a File object.floatReturns a float value from the properties file.Retrieves the H2 data directory - if the database has been moved to the temp directory this method will return the temp directory.intReturns an int value from the properties file.intReturns an int value from the properties file.longReturns a long value from the properties file.longReturns a long value from the properties file.Returns a value from the properties file.Returns a value from the properties file.Returns the temporary directory.getTempFile(@NonNull String prefix, @NonNull String extension) Generates a new temporary file name that is guaranteed to be unique.voidmergeProperties(@NonNull File filePath) Merges a new properties file into the current properties.voidmergeProperties(@NonNull InputStream stream) Merges a new properties file into the current properties.voidmergeProperties(@NonNull String filePath) Merges a new properties file into the current properties.voidremoveProperty(@NonNull String key) Removes a property from the local properties collection.voidsetArrayIfNotEmpty(@NonNull String key, @Nullable String[] value) Sets a property value only if the array value is not null and not empty.voidsetArrayIfNotEmpty(@NonNull String key, @Nullable List<String> value) Sets a property value only if the array value is not null and not empty.voidsetBoolean(@NonNull String key, boolean value) Sets a property value.voidsetBooleanIfNotNull(@NonNull String key, @Nullable Boolean value) Sets a property value only if the value is not null.voidSets a float property value.voidSets a property value.voidsetIntIfNotNull(@NonNull String key, @Nullable Integer value) Sets a property value only if the value is not null.voidSets a property value.voidsetStringIfNotEmpty(@NonNull String key, @Nullable String value) Sets a property value only if the value is not null and not empty.voidsetStringIfNotNull(@NonNull String key, @Nullable String value) Sets a property value only if the value is not null.
-
Constructor Details
-
Settings
public Settings()Initialize the settings object. -
Settings
Initialize the settings object using the given properties.- Parameters:
properties- the properties to be used with this Settings instance- Since:
- 4.0.3
-
Settings
Initialize the settings object using the given properties file.- Parameters:
propertiesFilePath- the path to the base properties file to load
-
-
Method Details
-
cleanup
public void cleanup()Cleans up resources to prevent memory leaks. -
cleanup
public void cleanup(boolean deleteTemporary) Cleans up resources to prevent memory leaks.- Parameters:
deleteTemporary- flag indicating whether any temporary directories generated should be removed
-
setString
-
setStringIfNotNull
-
setStringIfNotEmpty
-
setArrayIfNotEmpty
-
setArrayIfNotEmpty
-
setBoolean
Sets a property value.- Parameters:
key- the key for the propertyvalue- the value for the property
-
setBooleanIfNotNull
-
setFloat
Sets a float property value.- Parameters:
key- the key for the propertyvalue- the value for the property
-
setInt
Sets a property value.- Parameters:
key- the key for the propertyvalue- the value for the property
-
setIntIfNotNull
-
mergeProperties
Merges a new properties file into the current properties. This method allows for the loading of a user provided properties file.
Note: even if using this method - system properties will be loaded before properties loaded from files.- Parameters:
filePath- the path to the properties file to merge.- Throws:
FileNotFoundException- is thrown when the filePath points to a non-existent fileIOException- is thrown when there is an exception loading/merging the properties
-
mergeProperties
Merges a new properties file into the current properties. This method allows for the loading of a user provided properties file.
Note: even if using this method - system properties will be loaded before properties loaded from files.- Parameters:
filePath- the path to the properties file to merge.- Throws:
FileNotFoundException- is thrown when the filePath points to a non-existent fileIOException- is thrown when there is an exception loading/merging the properties
-
mergeProperties
Merges a new properties file into the current properties. This method allows for the loading of a user provided properties file.
Note: even if using this method - system properties will be loaded before properties loaded from files.- Parameters:
stream- an Input Stream pointing at a properties file to merge- Throws:
IOException- is thrown when there is an exception loading/merging the properties
-
getFile
Returns a value from the properties file as a File object. If the value was specified as a system property or passed in via the -Dprop=value argument - this method will return the value from the system properties before the values in the contained configuration file.- Parameters:
key- the key to lookup within the properties file- Returns:
- the property from the properties file converted to a File object
-
getString
Returns a value from the properties file. If the value was specified as a system property or passed in via the -Dprop=value argument - this method will return the value from the system properties before the values in the contained configuration file.- Parameters:
key- the key to lookup within the properties filedefaultValue- the default value for the requested property- Returns:
- the property from the properties file
-
getTempDirectory
Returns the temporary directory.- Returns:
- the temporary directory
- Throws:
IOException- if any.
-
getString
Returns a value from the properties file. If the value was specified as a system property or passed in via the -Dprop=value argument - this method will return the value from the system properties before the values in the contained configuration file.- Parameters:
key- the key to lookup within the properties file- Returns:
- the property from the properties file
-
getArray
-
removeProperty
Removes a property from the local properties collection. This is mainly used in test cases.- Parameters:
key- the property key to remove
-
getInt
Returns an int value from the properties file. If the value was specified as a system property or passed in via the -Dprop=value argument - this method will return the value from the system properties before the values in the contained configuration file.- Parameters:
key- the key to lookup within the properties file- Returns:
- the property from the properties file
- Throws:
InvalidSettingException- is thrown if there is an error retrieving the setting
-
getInt
Returns an int value from the properties file. If the value was specified as a system property or passed in via the -Dprop=value argument - this method will return the value from the system properties before the values in the contained configuration file.- Parameters:
key- the key to lookup within the properties filedefaultValue- the default value to return- Returns:
- the property from the properties file or the defaultValue if the property does not exist or cannot be converted to an integer
-
getLong
Returns a long value from the properties file. If the value was specified as a system property or passed in via the -Dprop=value argument - this method will return the value from the system properties before the values in the contained configuration file.- Parameters:
key- the key to lookup within the properties file- Returns:
- the property from the properties file
- Throws:
InvalidSettingException- is thrown if there is an error retrieving the setting
-
getLong
Returns a long value from the properties file. If the value was specified as a system property or passed in via the -Dprop=value argument - this method will return the value from the system properties before the values in the contained configuration file.- Parameters:
key- the key to lookup within the properties filedefaultValue- the default value to return- Returns:
- the property from the properties file or the defaultValue if the property does not exist or cannot be converted to an integer
-
getBoolean
Returns a boolean value from the properties file. If the value was specified as a system property or passed in via the-Dprop=valueargument this method will return the value from the system properties before the values in the contained configuration file.- Parameters:
key- the key to lookup within the properties file- Returns:
- the property from the properties file
- Throws:
InvalidSettingException- is thrown if there is an error retrieving the setting
-
getBoolean
Returns a boolean value from the properties file. If the value was specified as a system property or passed in via the-Dprop=valueargument this method will return the value from the system properties before the values in the contained configuration file.- Parameters:
key- the key to lookup within the properties filedefaultValue- the default value to return if the setting does not exist- Returns:
- the property from the properties file
-
getFloat
Returns a float value from the properties file. If the value was specified as a system property or passed in via the-Dprop=valueargument this method will return the value from the system properties before the values in the contained configuration file.- Parameters:
key- the key to lookup within the properties filedefaultValue- the default value to return if the setting does not exist- Returns:
- the property from the properties file
-
getConnectionString
public String getConnectionString(String connectionStringKey, String dbFileNameKey) throws IOException, InvalidSettingException Returns a connection string from the configured properties. If the connection string contains a %s, this method will determine the 'data' directory and replace the %s with the path to the data directory. If the data directory does not exist it will be created.- Parameters:
connectionStringKey- the property file key for the connection stringdbFileNameKey- the settings key for the db filename- Returns:
- the connection string
- Throws:
IOException- thrown the data directory cannot be createdInvalidSettingException- thrown if there is an invalid setting
-
getDataDirectory
Retrieves the primary data directory that is used for caching web content.- Returns:
- the data directory to store data files
- Throws:
IOException- is thrown if an java.io.IOException occurs of course...
-
getH2DataDirectory
Retrieves the H2 data directory - if the database has been moved to the temp directory this method will return the temp directory.- Returns:
- the data directory to store data files
- Throws:
IOException- is thrown if an java.io.IOException occurs of course...
-
getTempFile
Generates a new temporary file name that is guaranteed to be unique.- Parameters:
prefix- the prefix for the file name to generateextension- the extension of the generated file name- Returns:
- a temporary File
- Throws:
IOException- if any.
-