diff --git a/pom.xml b/pom.xml index ef11cc871..698541268 100644 --- a/pom.xml +++ b/pom.xml @@ -216,11 +216,11 @@ along with DependencyCheck. If not, see . --> cve - ../data/cve + target/data/cve cpe - ../data/cpe + target/data/cpe @@ -236,11 +236,11 @@ along with DependencyCheck. If not, see . cve - ../data/cve + target/data/cve cpe - ../data/cpe + target/data/cpe @@ -357,9 +357,10 @@ along with DependencyCheck. If not, see . integration-tests - + diff --git a/src/main/java/org/codesecure/dependencycheck/App.java b/src/main/java/org/codesecure/dependencycheck/App.java index 0273d125b..48dfa0f31 100644 --- a/src/main/java/org/codesecure/dependencycheck/App.java +++ b/src/main/java/org/codesecure/dependencycheck/App.java @@ -22,7 +22,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.net.URLDecoder; import java.util.List; import java.util.logging.Level; import java.util.logging.LogManager; @@ -70,31 +69,11 @@ public class App { app.run(args); } - private static File getLoggingDirectory() throws IOException { - String fileName = "logs"; - String filePath = App.class.getProtectionDomain().getCodeSource().getLocation().getPath(); - String decodedPath = URLDecoder.decode(filePath, "UTF-8"); - File exePath = new File(decodedPath); - if (!exePath.isDirectory()) { - exePath = exePath.getParentFile(); - } - File path = new File(exePath.getCanonicalFile() + File.separator + fileName); - path = new File(path.getCanonicalPath()); - return path; - } - private static void prepareLogger() { //while java doc for JUL says to use preferences api - it throws an exception... //Preferences.systemRoot().put("java.util.logging.config.file", "log.properties"); //System.getProperties().put("java.util.logging.config.file", "configuration/log.properties"); - File dir; - try { - dir = getLoggingDirectory(); - } catch (IOException ex) { - Logger.getLogger(App.class.getName()).log(Level.SEVERE, "Unable to get default logging location, " - + "using the working directory instead.", ex); - dir = new File("logs"); - } + File dir = new File("logs"); if (!dir.exists()) { dir.mkdir(); 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 4d7354c87..6a057de12 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/cpe/Index.java +++ b/src/main/java/org/codesecure/dependencycheck/data/cpe/Index.java @@ -93,8 +93,10 @@ public class Index extends AbstractIndex implements CachedWebDataSource { 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()); 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 6a381dd21..d544acd60 100644 --- a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/Index.java +++ b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/Index.java @@ -91,8 +91,10 @@ public class Index extends AbstractIndex implements CachedWebDataSource { 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()); diff --git a/src/main/resources/configuration/log.properties b/src/main/resources/configuration/log.properties index 51a88bb8f..8302a23d3 100644 --- a/src/main/resources/configuration/log.properties +++ b/src/main/resources/configuration/log.properties @@ -20,4 +20,4 @@ java.util.logging.FileHandler.level=FINEST # %g - generation number for rotating logs # %u - unique number to avoid conflicts # FileHandler writes to %h/demo0.log by default. -java.util.logging.FileHandler.pattern=./logs/DependencyCheck%g.log \ No newline at end of file +java.util.logging.FileHandler.pattern=./logs/DependencyCheck%u.log \ No newline at end of file diff --git a/src/test/java/org/codesecure/dependencycheck/data/cpe/BaseIndexTestCase.java b/src/test/java/org/codesecure/dependencycheck/data/cpe/BaseIndexTestCase.java index 96bee0fb5..712117f70 100644 --- a/src/test/java/org/codesecure/dependencycheck/data/cpe/BaseIndexTestCase.java +++ b/src/test/java/org/codesecure/dependencycheck/data/cpe/BaseIndexTestCase.java @@ -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()); diff --git a/src/test/java/org/codesecure/dependencycheck/data/cpe/CPEAnalyzerTest.java b/src/test/java/org/codesecure/dependencycheck/data/cpe/CPEAnalyzerTest.java index c1fb3d971..ec4af676b 100644 --- a/src/test/java/org/codesecure/dependencycheck/data/cpe/CPEAnalyzerTest.java +++ b/src/test/java/org/codesecure/dependencycheck/data/cpe/CPEAnalyzerTest.java @@ -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(); } diff --git a/src/test/java/org/codesecure/dependencycheck/data/nvdcve/BaseIndexTestCase.java b/src/test/java/org/codesecure/dependencycheck/data/nvdcve/BaseIndexTestCase.java index 1898b15d3..7855d7aa2 100644 --- a/src/test/java/org/codesecure/dependencycheck/data/nvdcve/BaseIndexTestCase.java +++ b/src/test/java/org/codesecure/dependencycheck/data/nvdcve/BaseIndexTestCase.java @@ -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()); 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 86af35386..25027bbd4 100644 --- a/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexIntegrationTest.java +++ b/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexIntegrationTest.java @@ -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.*; /** diff --git a/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexTest.java b/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexTest.java index 135c63cdb..609d61e49 100644 --- a/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexTest.java +++ b/src/test/java/org/codesecure/dependencycheck/data/nvdcve/IndexTest.java @@ -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)); } } diff --git a/src/test/java/org/codesecure/dependencycheck/utils/SettingsTest.java b/src/test/java/org/codesecure/dependencycheck/utils/SettingsTest.java index 8f2e5a6fa..4edcd7032 100644 --- a/src/test/java/org/codesecure/dependencycheck/utils/SettingsTest.java +++ b/src/test/java/org/codesecure/dependencycheck/utils/SettingsTest.java @@ -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)); }