mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-16 08:36:55 +01:00
updated to use directory of jar instead of working directory to store data
Former-commit-id: 5090e57e59d022d0824bf5a7fdcbedfc0bff027e
This commit is contained in:
@@ -34,11 +34,13 @@ public abstract class BaseIndexTestCase extends TestCase {
|
||||
|
||||
protected static File getDataDirectory() throws IOException {
|
||||
String fileName = Settings.getString(Settings.KEYS.CPE_INDEX);
|
||||
String filePath = BaseIndexTestCase.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||
String filePath = Index.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||
String decodedPath = URLDecoder.decode(filePath, "UTF-8");
|
||||
File exePath = new File(decodedPath);
|
||||
if (!exePath.isDirectory()) {
|
||||
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());
|
||||
|
||||
@@ -13,8 +13,6 @@ import org.apache.lucene.index.CorruptIndexException;
|
||||
import org.apache.lucene.queryParser.ParseException;
|
||||
import org.codesecure.dependencycheck.dependency.Dependency;
|
||||
import org.codesecure.dependencycheck.analyzer.JarAnalyzer;
|
||||
import org.codesecure.dependencycheck.dependency.Evidence;
|
||||
import org.codesecure.dependencycheck.dependency.Evidence.Confidence;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@@ -133,6 +131,7 @@ public class CPEAnalyzerTest extends BaseIndexTestCase {
|
||||
expResult = "cpe:/a:apache:struts:2.3.1.2";
|
||||
result = instance.searchCPE(vendor, product, version);
|
||||
assertEquals(expResult, result.get(0).getName());
|
||||
|
||||
instance.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,11 +36,13 @@ public abstract class BaseIndexTestCase extends TestCase {
|
||||
|
||||
protected static File getDataDirectory() throws IOException {
|
||||
String fileName = Settings.getString(Settings.KEYS.CVE_INDEX);
|
||||
String filePath = BaseIndexTestCase.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||
String filePath = Index.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||
String decodedPath = URLDecoder.decode(filePath, "UTF-8");
|
||||
File exePath = new File(decodedPath);
|
||||
if (!exePath.isDirectory()) {
|
||||
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());
|
||||
|
||||
@@ -4,11 +4,8 @@
|
||||
*/
|
||||
package org.codesecure.dependencycheck.data.nvdcve;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.Map;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.*;
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
package org.codesecure.dependencycheck.data.nvdcve;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.*;
|
||||
@@ -45,8 +44,7 @@ public class IndexTest extends BaseIndexTestCase {
|
||||
Index instance = new Index();
|
||||
String exp = File.separatorChar + "target" + File.separatorChar + "data" + File.separatorChar + "cve";
|
||||
Directory result = instance.getDirectory();
|
||||
|
||||
assertTrue("Recieved '" + result.toString() + "' and excpected '" + exp + "'.",
|
||||
result.toString().contains(exp));
|
||||
|
||||
assertTrue(result.toString().contains(exp));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class SettingsTest extends TestCase {
|
||||
public void testGetString() {
|
||||
System.out.println("getString");
|
||||
String key = Settings.KEYS.CPE_INDEX;
|
||||
String expResult = "../data/cpe";
|
||||
String expResult = "target/data/cpe";
|
||||
String result = Settings.getString(key);
|
||||
assertTrue(result.endsWith(expResult));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user