Package org.owasp.dependencycheck.utils
Class Settings
- java.lang.Object
-
- org.owasp.dependencycheck.utils.Settings
-
public final class Settings extends java.lang.ObjectA simple settings container that wraps the dependencycheck.properties file.- Version:
- $Id: $Id
- Author:
- Jeremy Long
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSettings.KEYSThe collection of keys used within the properties file.
-
Constructor Summary
Constructors Constructor Description Settings()Initialize the settings object.Settings(@NotNull java.lang.String propertiesFilePath)Initialize the settings object using the given properties file.Settings(java.util.Properties properties)Initialize the settings object using the given properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanup()Cleans up resources to prevent memory leaks.voidcleanup(boolean deleteTemporary)Cleans up resources to prevent memory leaks.java.lang.String[]getArray(@NotNull java.lang.String key)Returns a list with the given key.booleangetBoolean(@NotNull java.lang.String key)Returns a boolean value from the properties file.booleangetBoolean(@NotNull java.lang.String key, boolean defaultValue)Returns a boolean value from the properties file.java.lang.StringgetConnectionString(java.lang.String connectionStringKey, java.lang.String dbFileNameKey)Returns a connection string from the configured properties.java.io.FilegetDataDirectory()Retrieves the primary data directory that is used for caching web content.@Nullable java.io.FilegetFile(@NotNull java.lang.String key)Returns a value from the properties file as a File object.floatgetFloat(@NotNull java.lang.String key, float defaultValue)Returns a float value from the properties file.java.io.FilegetH2DataDirectory()Retrieves the H2 data directory - if the database has been moved to the temp directory this method will return the temp directory.intgetInt(@NotNull java.lang.String key)Returns an int value from the properties file.intgetInt(@NotNull java.lang.String key, int defaultValue)Returns an int value from the properties file.longgetLong(@NotNull java.lang.String key)Returns a long value from the properties file.java.lang.StringgetString(@NotNull java.lang.String key)Returns a value from the properties file.java.lang.StringgetString(@NotNull java.lang.String key, @Nullable java.lang.String defaultValue)Returns a value from the properties file.java.io.FilegetTempDirectory()Returns the temporary directory.java.io.FilegetTempFile(@NotNull java.lang.String prefix, @NotNull java.lang.String extension)Generates a new temporary file name that is guaranteed to be unique.voidmergeProperties(@NotNull java.io.File filePath)Merges a new properties file into the current properties.voidmergeProperties(@NotNull java.io.InputStream stream)Merges a new properties file into the current properties.voidmergeProperties(@NotNull java.lang.String filePath)Merges a new properties file into the current properties.voidremoveProperty(@NotNull java.lang.String key)Removes a property from the local properties collection.voidsetArrayIfNotEmpty(@NotNull java.lang.String key, @Nullable java.lang.String[] value)Sets a property value only if the array value is not null and not empty.voidsetArrayIfNotEmpty(@NotNull java.lang.String key, @Nullable java.util.List<java.lang.String> value)Sets a property value only if the array value is not null and not empty.voidsetBoolean(@NotNull java.lang.String key, boolean value)Sets a property value.voidsetBooleanIfNotNull(@NotNull java.lang.String key, @Nullable java.lang.Boolean value)Sets a property value only if the value is not null.voidsetFloat(@NotNull java.lang.String key, float value)Sets a float property value.voidsetInt(@NotNull java.lang.String key, int value)Sets a property value.voidsetIntIfNotNull(@NotNull java.lang.String key, @Nullable java.lang.Integer value)Sets a property value only if the value is not null.voidsetString(@NotNull java.lang.String key, @NotNull java.lang.String value)Sets a property value.voidsetStringIfNotEmpty(@NotNull java.lang.String key, @Nullable java.lang.String value)Sets a property value only if the value is not null and not empty.voidsetStringIfNotNull(@NotNull java.lang.String key, @Nullable java.lang.String value)Sets a property value only if the value is not null.
-
-
-
Constructor Detail
-
Settings
public Settings()
Initialize the settings object.
-
Settings
public Settings(java.util.Properties properties)
Initialize the settings object using the given properties.- Parameters:
properties- the properties to be used with this Settings instance- Since:
- 4.0.3
-
Settings
public Settings(@NotNull @NotNull java.lang.String propertiesFilePath)Initialize the settings object using the given properties file.- Parameters:
propertiesFilePath- the path to the base properties file to load
-
-
Method Detail
-
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
public void setString(@NotNull @NotNull java.lang.String key, @NotNull @NotNull java.lang.String value)Sets a property value.- Parameters:
key- the key for the propertyvalue- the value for the property
-
setStringIfNotNull
public void setStringIfNotNull(@NotNull @NotNull java.lang.String key, @Nullable @Nullable java.lang.String value)Sets a property value only if the value is not null.- Parameters:
key- the key for the propertyvalue- the value for the property
-
setStringIfNotEmpty
public void setStringIfNotEmpty(@NotNull @NotNull java.lang.String key, @Nullable @Nullable java.lang.String value)Sets a property value only if the value is not null and not empty.- Parameters:
key- the key for the propertyvalue- the value for the property
-
setArrayIfNotEmpty
public void setArrayIfNotEmpty(@NotNull @NotNull java.lang.String key, @Nullable @Nullable java.lang.String[] value)Sets a property value only if the array value is not null and not empty.- Parameters:
key- the key for the propertyvalue- the value for the property
-
setArrayIfNotEmpty
public void setArrayIfNotEmpty(@NotNull @NotNull java.lang.String key, @Nullable @Nullable java.util.List<java.lang.String> value)Sets a property value only if the array value is not null and not empty.- Parameters:
key- the key for the propertyvalue- the value for the property
-
setBoolean
public void setBoolean(@NotNull @NotNull java.lang.String key, boolean value)Sets a property value.- Parameters:
key- the key for the propertyvalue- the value for the property
-
setBooleanIfNotNull
public void setBooleanIfNotNull(@NotNull @NotNull java.lang.String key, @Nullable @Nullable java.lang.Boolean value)Sets a property value only if the value is not null.- Parameters:
key- the key for the propertyvalue- the value for the property
-
setFloat
public void setFloat(@NotNull @NotNull java.lang.String key, float value)Sets a float property value.- Parameters:
key- the key for the propertyvalue- the value for the property
-
setInt
public void setInt(@NotNull @NotNull java.lang.String key, int value)Sets a property value.- Parameters:
key- the key for the propertyvalue- the value for the property
-
setIntIfNotNull
public void setIntIfNotNull(@NotNull @NotNull java.lang.String key, @Nullable @Nullable java.lang.Integer value)Sets a property value only if the value is not null.- Parameters:
key- the key for the propertyvalue- the value for the property
-
mergeProperties
public void mergeProperties(@NotNull @NotNull java.io.File filePath) throws java.io.FileNotFoundException, java.io.IOExceptionMerges 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:
java.io.FileNotFoundException- is thrown when the filePath points to a non-existent filejava.io.IOException- is thrown when there is an exception loading/merging the properties
-
mergeProperties
public void mergeProperties(@NotNull @NotNull java.lang.String filePath) throws java.io.FileNotFoundException, java.io.IOExceptionMerges 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:
java.io.FileNotFoundException- is thrown when the filePath points to a non-existent filejava.io.IOException- is thrown when there is an exception loading/merging the properties
-
mergeProperties
public void mergeProperties(@NotNull @NotNull java.io.InputStream stream) throws java.io.IOExceptionMerges 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:
java.io.IOException- is thrown when there is an exception loading/merging the properties
-
getFile
@Nullable public @Nullable java.io.File getFile(@NotNull @NotNull java.lang.String key)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
public java.lang.String getString(@NotNull @NotNull java.lang.String key, @Nullable @Nullable java.lang.String defaultValue)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
public java.io.File getTempDirectory() throws java.io.IOExceptionReturns the temporary directory.- Returns:
- the temporary directory
- Throws:
java.io.IOException- if any.
-
getString
public java.lang.String getString(@NotNull @NotNull java.lang.String key)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
public java.lang.String[] getArray(@NotNull @NotNull java.lang.String key)Returns a list with the given key.If the property is not set then
nullwill be returned.- Parameters:
key- the key to get from thisSettings.- Returns:
- the list or
nullif the key wasn't present.
-
removeProperty
public void removeProperty(@NotNull @NotNull java.lang.String key)Removes a property from the local properties collection. This is mainly used in test cases.- Parameters:
key- the property key to remove
-
getInt
public int getInt(@NotNull @NotNull java.lang.String key) throws InvalidSettingExceptionReturns 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
public int getInt(@NotNull @NotNull java.lang.String key, int defaultValue)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
public long getLong(@NotNull @NotNull java.lang.String key) throws InvalidSettingExceptionReturns 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
-
getBoolean
public boolean getBoolean(@NotNull @NotNull java.lang.String key) throws InvalidSettingExceptionReturns 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
public boolean getBoolean(@NotNull @NotNull java.lang.String key, boolean defaultValue)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
public float getFloat(@NotNull @NotNull java.lang.String key, float defaultValue)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 java.lang.String getConnectionString(java.lang.String connectionStringKey, java.lang.String dbFileNameKey) throws java.io.IOException, InvalidSettingExceptionReturns 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:
java.io.IOException- thrown the data directory cannot be createdInvalidSettingException- thrown if there is an invalid setting
-
getDataDirectory
public java.io.File getDataDirectory() throws java.io.IOExceptionRetrieves the primary data directory that is used for caching web content.- Returns:
- the data directory to store data files
- Throws:
java.io.IOException- is thrown if an java.io.IOException occurs of course...
-
getH2DataDirectory
public java.io.File getH2DataDirectory() throws java.io.IOExceptionRetrieves 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:
java.io.IOException- is thrown if an java.io.IOException occurs of course...
-
getTempFile
public java.io.File getTempFile(@NotNull @NotNull java.lang.String prefix, @NotNull @NotNull java.lang.String extension) throws java.io.IOExceptionGenerates 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:
java.io.IOException- if any.
-
-