corrected minor issue with path to zipped test data

Former-commit-id: 862ea03dc2738dc315a82c03d514f3ce8b6f410e
This commit is contained in:
Jeremy Long
2013-08-16 14:13:01 -04:00
parent d14bcf4541
commit acd20c580f
6 changed files with 89 additions and 19 deletions

View File

@@ -258,15 +258,17 @@ public final class Settings {
* to the folder containing the JAR file containing this class.
*
* @param key the key to lookup within the properties file
* @param clazz the class to obtain the base directory from in case "[JAR]\"
* exists
* @return the property from the properties file converted to a File object
* @throws IOException thrown if the file path to the JAR cannot be found
*/
public static File getFile(String key) throws IOException {
public static File getFile(String key, Class clazz) throws IOException {
final String file = getString(key);
final String baseDir = getString(Settings.KEYS.DATA_DIRECTORY);
if (baseDir != null) {
if (baseDir.startsWith("[JAR]/")) {
final File jarPath = getJarPath();
final File jarPath = getJarPath(clazz);
final File newBase = new File(jarPath.getCanonicalPath(), baseDir.substring(6));
return new File(newBase, file);
}
@@ -275,14 +277,31 @@ public final class Settings {
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 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
* @throws IOException thrown if the file path to the JAR cannot be found
*/
public static File getFile(String key) throws IOException {
return getFile(key, Settings.class);
}
/**
* Attempts to retrieve the folder containing the Jar file containing the
* Settings class.
*
* @return a File object
*/
private static File getJarPath() {
final String jarPath = Settings.class.getProtectionDomain().getCodeSource().getLocation().getPath();
private static File getJarPath(Class clazz) {
final String jarPath = clazz.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = ".";
try {
decodedPath = URLDecoder.decode(jarPath, "UTF-8");
@@ -291,7 +310,8 @@ public final class Settings {
}
final File path = new File(decodedPath);
if (path.getName().toLowerCase().endsWith(".jar")) {
//TODO - need to remove the "test-classes" check which is only here to make test cases work.
if (path.getName().toLowerCase().endsWith(".jar") || path.getName().equals("test-classes")) {
return path.getParentFile();
} else {
return new File(".");