From c7c85ac6760f4f713f91ab4b80d9a5becbe7887f Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Tue, 26 Nov 2013 05:35:40 -0500 Subject: [PATCH] renamed getFile to getDataFile and added a no frills getFile function Former-commit-id: 73c2b4d2f5c153bd49873b153e4bbd31ea8b66f8 --- .../owasp/dependencycheck/utils/Settings.java | 22 ++++++++++++++++--- .../dependencycheck/utils/SettingsTest.java | 8 +++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java index 76dde19da..9e1643353 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java @@ -260,13 +260,29 @@ public final class Settings { * argument - this method will return the value from the system properties * before the values in the contained configuration file. * - * This method will also replace a leading "[JAR]\" sequence with the path - * to the folder containing the JAR file containing this class. - * * @param key the key to lookup within the properties file * @return the property from the properties file converted to a File object */ public static File getFile(String key) { + final String file = getString(key); + return new File(file); + } + + /** + * 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. + * + * This method will check the configured base directory and will use this as + * the base of the file path. Additionally, if the base directory begins + * with a leading "[JAR]\" sequence with the path to the folder containing + * the JAR file containing this class. + * + * @param key the key to lookup within the properties file + * @return the property from the properties file converted to a File object + */ + public static File getDataFile(String key) { final String file = getString(key); final String baseDir = getString(Settings.KEYS.DATA_DIRECTORY); if (baseDir != null) { diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/utils/SettingsTest.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/utils/SettingsTest.java index aa738e793..2fd5c39dd 100644 --- a/dependency-check-core/src/test/java/org/owasp/dependencycheck/utils/SettingsTest.java +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/utils/SettingsTest.java @@ -64,16 +64,16 @@ public class SettingsTest { } /** - * Test of getFile method, of class Settings. + * Test of getDataFile method, of class Settings. */ @Test - public void testGetFile() throws IOException { + public void testGetDataFile() throws IOException { String key = Settings.KEYS.CVE_DATA_DIRECTORY; String expResult = "data" + File.separator + "cve"; - File result = Settings.getFile(key); + File result = Settings.getDataFile(key); Assert.assertTrue(result.getAbsolutePath().endsWith(expResult)); - result = Settings.getFile(Settings.KEYS.DATA_DIRECTORY); + result = Settings.getDataFile(Settings.KEYS.DATA_DIRECTORY); String path = result.getPath(); Assert.assertTrue(path.endsWith("data") || path.endsWith("data" + File.separator)); }