mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-14 15:53:36 +01:00
Adding more control over data directory path
Former-commit-id: 263475fc5b3aae04f2530ea78a0456deb18686fe
This commit is contained in:
@@ -70,14 +70,7 @@ public class Index extends AbstractIndex {
|
||||
*/
|
||||
public File getDataDirectory() throws IOException {
|
||||
final String fileName = Settings.getString(Settings.KEYS.CPE_INDEX);
|
||||
File exePath = FileUtils.getDataDirectory(fileName, Index.class);
|
||||
if (exePath.getName().toLowerCase().endsWith(".jar")) {
|
||||
exePath = exePath.getParentFile();
|
||||
} else {
|
||||
exePath = new File(".");
|
||||
}
|
||||
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
||||
path = new File(path.getCanonicalPath());
|
||||
File path = FileUtils.getDataDirectory(fileName, Index.class);
|
||||
if (!path.exists()) {
|
||||
if (!path.mkdirs()) {
|
||||
throw new IOException("Unable to create CPE Data directory");
|
||||
|
||||
@@ -408,16 +408,7 @@ public class CveDB {
|
||||
*/
|
||||
public static File getDataDirectory() throws IOException {
|
||||
final String fileName = Settings.getString(Settings.KEYS.CVE_INDEX);
|
||||
File exePath = FileUtils.getDataDirectory(fileName, CveDB.class);
|
||||
|
||||
if (exePath.getName().toLowerCase().endsWith(".jar")) {
|
||||
exePath = exePath.getParentFile();
|
||||
} else {
|
||||
exePath = new File(".");
|
||||
}
|
||||
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
||||
path = new File(path.getCanonicalPath());
|
||||
|
||||
File path = FileUtils.getDataDirectory(fileName, CveDB.class);
|
||||
if (!path.exists()) {
|
||||
if (!path.mkdirs()) {
|
||||
throw new IOException("Unable to create NVD CVE Data directory");
|
||||
|
||||
@@ -83,10 +83,18 @@ public final class FileUtils {
|
||||
public static File getDataDirectory(String configuredFilePath, Class clazz) throws IOException {
|
||||
File file = new File(configuredFilePath);
|
||||
if (file.exists() && file.isDirectory() && file.canWrite()) {
|
||||
return file;
|
||||
return new File(file.getCanonicalPath());
|
||||
} else {
|
||||
String filePath = clazz.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||
return new File(URLDecoder.decode(filePath, "UTF-8"));
|
||||
final String filePath = clazz.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||
final String decodedPath = URLDecoder.decode(filePath, "UTF-8");
|
||||
File exePath = new File(decodedPath);
|
||||
if (exePath.getName().toLowerCase().endsWith(".jar")) {
|
||||
exePath = exePath.getParentFile();
|
||||
} else {
|
||||
exePath = new File(".");
|
||||
}
|
||||
File path = new File(exePath.getCanonicalFile() + File.separator + configuredFilePath);
|
||||
return new File(path.getCanonicalPath());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,15 +58,7 @@ public abstract class BaseIndexTestCase {
|
||||
|
||||
protected static File getDataDirectory() throws IOException {
|
||||
String fileName = Settings.getString(Settings.KEYS.CPE_INDEX);
|
||||
File exePath = FileUtils.getDataDirectory(fileName, Index.class);
|
||||
if (exePath.getName().toLowerCase().endsWith(".jar")) {
|
||||
exePath = exePath.getParentFile();
|
||||
} else {
|
||||
exePath = new File(".");
|
||||
}
|
||||
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
||||
path = new File(path.getCanonicalPath());
|
||||
return path;
|
||||
return FileUtils.getDataDirectory(fileName, Index.class);
|
||||
}
|
||||
|
||||
public static void ensureIndexExists() throws Exception {
|
||||
|
||||
@@ -49,15 +49,7 @@ public abstract class BaseDBTestCase extends TestCase {
|
||||
|
||||
protected static File getDataDirectory() throws IOException {
|
||||
String fileName = Settings.getString(Settings.KEYS.CVE_INDEX);
|
||||
File exePath = FileUtils.getDataDirectory(fileName, Index.class);
|
||||
if (exePath.getName().toLowerCase().endsWith(".jar")) {
|
||||
exePath = exePath.getParentFile();
|
||||
} else {
|
||||
exePath = new File(".");
|
||||
}
|
||||
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
||||
path = new File(path.getCanonicalPath());
|
||||
return path;
|
||||
return FileUtils.getDataDirectory(fileName, Index.class);
|
||||
}
|
||||
|
||||
public static void ensureDBExists() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user