mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-02-24 19:35:16 +01:00
fixed issue with data directory and made a few other minor changes
Former-commit-id: 46f89f4deb6b0b55f34ee61c61424f87bf0334d8
This commit is contained in:
@@ -66,12 +66,11 @@ public class Index extends AbstractIndex {
|
||||
* @throws IOException is thrown if an IOException occurs of course...
|
||||
*/
|
||||
public File getDataDirectory() throws IOException {
|
||||
final String fileName = Settings.getString(Settings.KEYS.CPE_DATA_DIRECTORY);
|
||||
final String dataDirectory = Settings.getString(Settings.KEYS.DATA_DIRECTORY);
|
||||
//final File path = FileUtils.getDataDirectory(fileName, Index.class);
|
||||
final File path = new File(dataDirectory, fileName);
|
||||
if (!path.exists() && !path.mkdirs()) {
|
||||
throw new IOException("Unable to create CPE Data directory");
|
||||
final File path = Settings.getFile(Settings.KEYS.CPE_DATA_DIRECTORY);
|
||||
if (!path.exists()) {
|
||||
if (!path.mkdirs()) {
|
||||
throw new IOException("Unable to create CPE Data directory");
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@@ -523,9 +523,7 @@ public class CveDB {
|
||||
* @throws IOException is thrown if an IOException occurs of course...
|
||||
*/
|
||||
public static File getDataDirectory() throws IOException {
|
||||
final String fileName = Settings.getString(Settings.KEYS.CVE_DATA_DIRECTORY);
|
||||
final String dataDirectory = Settings.getString(Settings.KEYS.DATA_DIRECTORY);
|
||||
final File path = new File(dataDirectory, fileName);
|
||||
final File path = Settings.getFile(Settings.KEYS.CVE_DATA_DIRECTORY);
|
||||
if (!path.exists()) {
|
||||
if (!path.mkdirs()) {
|
||||
throw new IOException("Unable to create NVD CVE Data directory");
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -252,16 +254,48 @@ 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
|
||||
* @throws IOException thrown if the file path to the JAR cannot be found
|
||||
*/
|
||||
public static File getFile(String key) {
|
||||
public static File getFile(String key) throws IOException {
|
||||
final String file = getString(key);
|
||||
final String baseDir = getString(Settings.KEYS.DATA_DIRECTORY);
|
||||
final String tmp = getString(key);
|
||||
if (baseDir != null) {
|
||||
return new File(baseDir, tmp);
|
||||
if (baseDir.startsWith("[JAR]/")) {
|
||||
final File jarPath = getJarPath();
|
||||
final File newBase = new File(jarPath.getCanonicalPath(), baseDir.substring(6));
|
||||
return new File(newBase, file);
|
||||
}
|
||||
return new File(baseDir, file);
|
||||
}
|
||||
return new File(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
String decodedPath = ".";
|
||||
try {
|
||||
decodedPath = URLDecoder.decode(jarPath, "UTF-8");
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
Logger.getLogger(Settings.class.getName()).log(Level.FINEST, null, ex);
|
||||
}
|
||||
|
||||
final File path = new File(decodedPath);
|
||||
if (path.getName().toLowerCase().endsWith(".jar")) {
|
||||
return path.getParentFile();
|
||||
} else {
|
||||
return new File(".");
|
||||
}
|
||||
return new File(tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,8 +5,8 @@ autoupdate=true
|
||||
#temp.directory defaults to System.getProperty("java.io.tmpdir")
|
||||
#temp.directory=[path to temp directory]
|
||||
|
||||
# the path to the data directory
|
||||
data.directory=data
|
||||
# the path to the data directory; if tis
|
||||
data.directory=[JAR]/data
|
||||
# the path to the lucene index to store the cpe data
|
||||
data.cpe=cpe
|
||||
# the path to the h2 database to store the nvd cve data
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DownloaderIntegrationTest {
|
||||
String outputPath = "target/downloaded_cpe.xml";
|
||||
Downloader.fetchFile(url, outputPath, true);
|
||||
|
||||
url = new URL("http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-2010.xml");
|
||||
url = new URL(Settings.getString(Settings.KEYS.CVE_MODIFIED_20_URL));
|
||||
outputPath = "target/downloaded_cve.xml";
|
||||
Downloader.fetchFile(url, outputPath, false);
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public class SettingsTest {
|
||||
* Test of getFile method, of class Settings.
|
||||
*/
|
||||
@Test
|
||||
public void testGetFile() {
|
||||
public void testGetFile() throws IOException {
|
||||
String key = Settings.KEYS.CPE_DATA_DIRECTORY;
|
||||
String expResult = "data" + File.separator + "cpe";
|
||||
File result = Settings.getFile(key);
|
||||
|
||||
Reference in New Issue
Block a user