location of data files is no longer the working directory, rather the location of the JAR file itself

Former-commit-id: b3f83447f9422618d6db60d49488830381787110
This commit is contained in:
Jeremy Long
2012-11-12 12:19:39 -05:00
parent 965687186c
commit 3fb9390040
7 changed files with 149 additions and 51 deletions

View File

@@ -28,6 +28,7 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -75,7 +76,11 @@ public class Index extends AbstractIndex implements CachedWebDataSource {
*/
public Directory getDirectory() throws IOException {
String fileName = Settings.getString(Settings.KEYS.CPE_INDEX);
File path = new File(fileName);
String filePath = Index.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = URLDecoder.decode(filePath, "UTF-8");
File path = new File(decodedPath + File.separator + fileName);
path = new File(path.getCanonicalPath());
Directory dir = FSDirectory.open(path);
return dir;

View File

@@ -21,6 +21,7 @@ package org.codesecure.dependencycheck.data.nvdcve;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -73,8 +74,13 @@ public class Index extends AbstractIndex implements CachedWebDataSource {
*/
public Directory getDirectory() throws IOException {
String fileName = Settings.getString(Settings.KEYS.CVE_INDEX);
File path = new File(fileName);
String filePath = Index.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = URLDecoder.decode(filePath, "UTF-8");
File path = new File(decodedPath + File.separator + fileName);
path = new File(path.getCanonicalPath());
Directory dir = FSDirectory.open(path);
return dir;
}