mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-21 16:49:43 +01:00
renamed getFile to getDataFile and added a no frills getFile function
Former-commit-id: 73c2b4d2f5c153bd49873b153e4bbd31ea8b66f8
This commit is contained in:
@@ -260,13 +260,29 @@ public final class Settings {
|
|||||||
* argument - this method will return the value from the system properties
|
* argument - this method will return the value from the system properties
|
||||||
* before the values in the contained configuration file.
|
* 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
|
* @param key the key to lookup within the properties file
|
||||||
* @return the property from the properties file converted to a File object
|
* @return the property from the properties file converted to a File object
|
||||||
*/
|
*/
|
||||||
public static File getFile(String key) {
|
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 file = getString(key);
|
||||||
final String baseDir = getString(Settings.KEYS.DATA_DIRECTORY);
|
final String baseDir = getString(Settings.KEYS.DATA_DIRECTORY);
|
||||||
if (baseDir != null) {
|
if (baseDir != null) {
|
||||||
|
|||||||
@@ -64,16 +64,16 @@ public class SettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of getFile method, of class Settings.
|
* Test of getDataFile method, of class Settings.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetFile() throws IOException {
|
public void testGetDataFile() throws IOException {
|
||||||
String key = Settings.KEYS.CVE_DATA_DIRECTORY;
|
String key = Settings.KEYS.CVE_DATA_DIRECTORY;
|
||||||
String expResult = "data" + File.separator + "cve";
|
String expResult = "data" + File.separator + "cve";
|
||||||
File result = Settings.getFile(key);
|
File result = Settings.getDataFile(key);
|
||||||
Assert.assertTrue(result.getAbsolutePath().endsWith(expResult));
|
Assert.assertTrue(result.getAbsolutePath().endsWith(expResult));
|
||||||
|
|
||||||
result = Settings.getFile(Settings.KEYS.DATA_DIRECTORY);
|
result = Settings.getDataFile(Settings.KEYS.DATA_DIRECTORY);
|
||||||
String path = result.getPath();
|
String path = result.getPath();
|
||||||
Assert.assertTrue(path.endsWith("data") || path.endsWith("data" + File.separator));
|
Assert.assertTrue(path.endsWith("data") || path.endsWith("data" + File.separator));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user