From 6b303410d13e4bcf562e815c4ff478d7d8094e63 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Wed, 21 May 2014 06:42:43 -0400 Subject: [PATCH] added a new initialize method that accepts a properties file path to load to make the class more versatile Former-commit-id: b6bee9569b075380b656faf9d2f1bf1c9aae849a --- .../owasp/dependencycheck/utils/Settings.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java index 0af35de4e..ac80536e8 100644 --- a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java +++ b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java @@ -30,7 +30,6 @@ import java.util.Enumeration; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; -import org.owasp.dependencycheck.utils.FileUtils; /** * A simple settings container that wraps the dependencycheck.properties file. @@ -216,12 +215,14 @@ public final class Settings { /** * Private constructor for the Settings class. This class loads the properties files. + * + * @param propertiesFilePath the path to the base properties file to load */ - private Settings() { + private Settings(String propertiesFilePath) { InputStream in = null; props = new Properties(); try { - in = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILE); + in = this.getClass().getClassLoader().getResourceAsStream(propertiesFilePath); props.load(in); } catch (IOException ex) { LOGGER.log(Level.SEVERE, "Unable to load default settings."); @@ -243,7 +244,17 @@ public final class Settings { * However, you must also call Settings.cleanup() to properly release resources. */ public static void initialize() { - localSettings.set(new Settings()); + localSettings.set(new Settings(PROPERTIES_FILE)); + } + + /** + * Initializes the thread local settings object. Note, to use the settings object you must call this method. + * However, you must also call Settings.cleanup() to properly release resources. + * + * @param propertiesFilePath the path to the base properties file to load + */ + public static void initialize(String propertiesFilePath) { + localSettings.set(new Settings(propertiesFilePath)); } /**