diff --git a/pom.xml b/pom.xml index c14d3feca..f544f208e 100644 --- a/pom.xml +++ b/pom.xml @@ -206,13 +206,21 @@ along with DependencyCheck. If not, see . ${project.build.directory}/cobertura/cobertura.ser target - + + + cve + ../data/cve + + + cpe + ../data/cpe @@ -337,9 +345,9 @@ along with DependencyCheck. If not, see . integration-tests - + diff --git a/src/main/java/org/codesecure/dependencycheck/data/cpe/Index.java b/src/main/java/org/codesecure/dependencycheck/data/cpe/Index.java index 0bca410b2..9e4fa3391 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/cpe/Index.java +++ b/src/main/java/org/codesecure/dependencycheck/data/cpe/Index.java @@ -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; diff --git a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/Index.java b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/Index.java index 3099e0be8..dad110f23 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/Index.java +++ b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/Index.java @@ -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; } diff --git a/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexIntegrationTest.java b/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexIntegrationTest.java index 47d0ed66e..d67107544 100644 --- a/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexIntegrationTest.java +++ b/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexIntegrationTest.java @@ -40,35 +40,6 @@ public class IndexIntegrationTest extends BaseIndexTestCase { public void tearDown() { } - /** - * Test of open method, of class Index. - */ - @Test - public void testOpen() { - System.out.println("open"); - Index instance = new Index(); - try { - instance.open(); - } catch (IOException ex) { - fail(ex.getMessage()); - } - instance.close(); - } - - /** - * Test of getDirectory method, of class Index. - */ - @Test - public void testGetDirectory() throws Exception { - System.out.println("getDirectory"); - Index index = new Index(); - Directory result = index.getDirectory(); - - String exp = File.separatorChar + "target" + File.separatorChar + "data" + File.separatorChar + "cpe"; - // TODO review the generated test code and remove the default call to fail. - assertTrue(result.toString().contains(exp)); - } - /** * Test of update method, of class Index. */ diff --git a/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexTest.java b/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexTest.java new file mode 100644 index 000000000..300cdaec7 --- /dev/null +++ b/src/test/java/org/codesecure/dependencycheck/data/cpe/IndexTest.java @@ -0,0 +1,71 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.codesecure.dependencycheck.data.cpe; + +import java.io.File; +import java.io.IOException; +import org.apache.lucene.store.Directory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Jeremy Long (jeremy.long@gmail.com) + */ +public class IndexTest extends BaseIndexTestCase { + + public IndexTest(String testCase) { + super(testCase); + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of open method, of class Index. + */ + @Test + public void testOpen() { + System.out.println("open"); + Index instance = new Index(); + try { + instance.open(); + } catch (IOException ex) { + fail(ex.getMessage()); + } + instance.close(); + } + + /** + * Test of getDirectory method, of class Index. + */ + @Test + public void testGetDirectory() throws Exception { + System.out.println("getDirectory"); + Index index = new Index(); + Directory result = index.getDirectory(); + + String exp = File.separatorChar + "target" + File.separatorChar + "data" + File.separatorChar + "cpe"; + // TODO review the generated test code and remove the default call to fail. + assertTrue(result.toString().contains(exp)); + } +} diff --git a/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexIntegrationTest.java b/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexIntegrationTest.java index 8167fbe29..86af35386 100644 --- a/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexIntegrationTest.java +++ b/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexIntegrationTest.java @@ -16,7 +16,7 @@ import org.junit.*; * @author Jeremy */ public class IndexIntegrationTest extends BaseIndexTestCase { - + public IndexIntegrationTest(String testName) { super(testName); } @@ -28,11 +28,11 @@ public class IndexIntegrationTest extends BaseIndexTestCase { @AfterClass public static void tearDownClass() throws Exception { } - + @Before public void setUp() { } - + @After public void tearDown() { } @@ -45,19 +45,7 @@ public class IndexIntegrationTest extends BaseIndexTestCase { System.out.println("retrieveCurrentTimestampFromWeb"); Index instance = new Index(); Map result = instance.retrieveCurrentTimestampsFromWeb(); - assertEquals(12, result.size()); - } - - /** - * Test of getDirectory method, of class Index. - */ - @Test - public void testGetDirectory() throws Exception { - System.out.println("getDirectory"); - Index instance = new Index(); - String exp = File.separatorChar + "target" + File.separatorChar + "data" + File.separatorChar + "cve"; - Directory result = instance.getDirectory(); - assertTrue(result.toString().contains(exp)); + assertEquals(12, result.size()); } /** @@ -81,5 +69,4 @@ public class IndexIntegrationTest extends BaseIndexTestCase { //if an exception is thrown this test fails. However, because it depends on the // order of the tests what this will return I am just testing for the exception. } - } diff --git a/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexTest.java b/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexTest.java new file mode 100644 index 000000000..02c2a0b4b --- /dev/null +++ b/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexTest.java @@ -0,0 +1,50 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +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.*; + +/** + * + * @author Jeremy + */ +public class IndexTest extends BaseIndexTestCase { + + public IndexTest(String testName) { + super(testName); + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getDirectory method, of class Index. + */ + @Test + public void testGetDirectory() throws Exception { + System.out.println("getDirectory"); + Index instance = new Index(); + String exp = File.separatorChar + "target" + File.separatorChar + "data" + File.separatorChar + "cve"; + Directory result = instance.getDirectory(); + assertTrue(result.toString().contains(exp)); + } +}