mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-21 16:49:43 +01:00
updated to use directory of jar instead of working directory to store data
Former-commit-id: 93b0784cd0f38445c0550737b2377618f4ebee1e
This commit is contained in:
13
pom.xml
13
pom.xml
@@ -216,11 +216,11 @@ along with DependencyCheck. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
</property>-->
|
</property>-->
|
||||||
<property>
|
<property>
|
||||||
<name>cve</name>
|
<name>cve</name>
|
||||||
<value>../data/cve</value>
|
<value>target/data/cve</value>
|
||||||
</property>
|
</property>
|
||||||
<property>
|
<property>
|
||||||
<name>cpe</name>
|
<name>cpe</name>
|
||||||
<value>../data/cpe</value>
|
<value>target/data/cpe</value>
|
||||||
</property>
|
</property>
|
||||||
</systemProperties>
|
</systemProperties>
|
||||||
<excludes>
|
<excludes>
|
||||||
@@ -236,11 +236,11 @@ along with DependencyCheck. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<systemProperties>
|
<systemProperties>
|
||||||
<property>
|
<property>
|
||||||
<name>cve</name>
|
<name>cve</name>
|
||||||
<value>../data/cve</value>
|
<value>target/data/cve</value>
|
||||||
</property>
|
</property>
|
||||||
<property>
|
<property>
|
||||||
<name>cpe</name>
|
<name>cpe</name>
|
||||||
<value>../data/cpe</value>
|
<value>target/data/cpe</value>
|
||||||
</property>
|
</property>
|
||||||
</systemProperties>
|
</systemProperties>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -357,9 +357,10 @@ along with DependencyCheck. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<reportSets>
|
<reportSets>
|
||||||
<reportSet>
|
<reportSet>
|
||||||
<id>integration-tests</id>
|
<id>integration-tests</id>
|
||||||
<!--<reports>
|
<reports>
|
||||||
|
<report>report-only</report>
|
||||||
<report>failsafe-report-only</report>
|
<report>failsafe-report-only</report>
|
||||||
</reports>-->
|
</reports>
|
||||||
</reportSet>
|
</reportSet>
|
||||||
</reportSets>
|
</reportSets>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import java.io.File;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.LogManager;
|
import java.util.logging.LogManager;
|
||||||
@@ -70,31 +69,11 @@ public class App {
|
|||||||
app.run(args);
|
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() {
|
private static void prepareLogger() {
|
||||||
//while java doc for JUL says to use preferences api - it throws an exception...
|
//while java doc for JUL says to use preferences api - it throws an exception...
|
||||||
//Preferences.systemRoot().put("java.util.logging.config.file", "log.properties");
|
//Preferences.systemRoot().put("java.util.logging.config.file", "log.properties");
|
||||||
//System.getProperties().put("java.util.logging.config.file", "configuration/log.properties");
|
//System.getProperties().put("java.util.logging.config.file", "configuration/log.properties");
|
||||||
File dir;
|
File dir = new File("logs");
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
dir.mkdir();
|
dir.mkdir();
|
||||||
|
|||||||
@@ -93,8 +93,10 @@ public class Index extends AbstractIndex implements CachedWebDataSource {
|
|||||||
String filePath = Index.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
String filePath = Index.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||||
String decodedPath = URLDecoder.decode(filePath, "UTF-8");
|
String decodedPath = URLDecoder.decode(filePath, "UTF-8");
|
||||||
File exePath = new File(decodedPath);
|
File exePath = new File(decodedPath);
|
||||||
if (!exePath.isDirectory()) {
|
if (exePath.getName().toLowerCase().endsWith(".jar")) {
|
||||||
exePath = exePath.getParentFile();
|
exePath = exePath.getParentFile();
|
||||||
|
} else {
|
||||||
|
exePath = new File(".");
|
||||||
}
|
}
|
||||||
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
||||||
path = new File(path.getCanonicalPath());
|
path = new File(path.getCanonicalPath());
|
||||||
|
|||||||
@@ -91,8 +91,10 @@ public class Index extends AbstractIndex implements CachedWebDataSource {
|
|||||||
String filePath = Index.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
String filePath = Index.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||||
String decodedPath = URLDecoder.decode(filePath, "UTF-8");
|
String decodedPath = URLDecoder.decode(filePath, "UTF-8");
|
||||||
File exePath = new File(decodedPath);
|
File exePath = new File(decodedPath);
|
||||||
if (!exePath.isDirectory()) {
|
if (exePath.getName().toLowerCase().endsWith(".jar")) {
|
||||||
exePath = exePath.getParentFile();
|
exePath = exePath.getParentFile();
|
||||||
|
} else {
|
||||||
|
exePath = new File(".");
|
||||||
}
|
}
|
||||||
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
||||||
path = new File(path.getCanonicalPath());
|
path = new File(path.getCanonicalPath());
|
||||||
|
|||||||
@@ -20,4 +20,4 @@ java.util.logging.FileHandler.level=FINEST
|
|||||||
# %g - generation number for rotating logs
|
# %g - generation number for rotating logs
|
||||||
# %u - unique number to avoid conflicts
|
# %u - unique number to avoid conflicts
|
||||||
# FileHandler writes to %h/demo0.log by default.
|
# FileHandler writes to %h/demo0.log by default.
|
||||||
java.util.logging.FileHandler.pattern=./logs/DependencyCheck%g.log
|
java.util.logging.FileHandler.pattern=./logs/DependencyCheck%u.log
|
||||||
@@ -34,11 +34,13 @@ public abstract class BaseIndexTestCase extends TestCase {
|
|||||||
|
|
||||||
protected static File getDataDirectory() throws IOException {
|
protected static File getDataDirectory() throws IOException {
|
||||||
String fileName = Settings.getString(Settings.KEYS.CPE_INDEX);
|
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");
|
String decodedPath = URLDecoder.decode(filePath, "UTF-8");
|
||||||
File exePath = new File(decodedPath);
|
File exePath = new File(decodedPath);
|
||||||
if (!exePath.isDirectory()) {
|
if (exePath.getName().toLowerCase().endsWith(".jar")) {
|
||||||
exePath = exePath.getParentFile();
|
exePath = exePath.getParentFile();
|
||||||
|
} else {
|
||||||
|
exePath = new File(".");
|
||||||
}
|
}
|
||||||
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
||||||
path = new File(path.getCanonicalPath());
|
path = new File(path.getCanonicalPath());
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import org.apache.lucene.index.CorruptIndexException;
|
|||||||
import org.apache.lucene.queryParser.ParseException;
|
import org.apache.lucene.queryParser.ParseException;
|
||||||
import org.codesecure.dependencycheck.dependency.Dependency;
|
import org.codesecure.dependencycheck.dependency.Dependency;
|
||||||
import org.codesecure.dependencycheck.analyzer.JarAnalyzer;
|
import org.codesecure.dependencycheck.analyzer.JarAnalyzer;
|
||||||
import org.codesecure.dependencycheck.dependency.Evidence;
|
|
||||||
import org.codesecure.dependencycheck.dependency.Evidence.Confidence;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,6 +131,7 @@ public class CPEAnalyzerTest extends BaseIndexTestCase {
|
|||||||
expResult = "cpe:/a:apache:struts:2.3.1.2";
|
expResult = "cpe:/a:apache:struts:2.3.1.2";
|
||||||
result = instance.searchCPE(vendor, product, version);
|
result = instance.searchCPE(vendor, product, version);
|
||||||
assertEquals(expResult, result.get(0).getName());
|
assertEquals(expResult, result.get(0).getName());
|
||||||
|
|
||||||
instance.close();
|
instance.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,11 +36,13 @@ public abstract class BaseIndexTestCase extends TestCase {
|
|||||||
|
|
||||||
protected static File getDataDirectory() throws IOException {
|
protected static File getDataDirectory() throws IOException {
|
||||||
String fileName = Settings.getString(Settings.KEYS.CVE_INDEX);
|
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");
|
String decodedPath = URLDecoder.decode(filePath, "UTF-8");
|
||||||
File exePath = new File(decodedPath);
|
File exePath = new File(decodedPath);
|
||||||
if (!exePath.isDirectory()) {
|
if (exePath.getName().toLowerCase().endsWith(".jar")) {
|
||||||
exePath = exePath.getParentFile();
|
exePath = exePath.getParentFile();
|
||||||
|
} else {
|
||||||
|
exePath = new File( "." );
|
||||||
}
|
}
|
||||||
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
||||||
path = new File(path.getCanonicalPath());
|
path = new File(path.getCanonicalPath());
|
||||||
|
|||||||
@@ -4,11 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.codesecure.dependencycheck.data.nvdcve;
|
package org.codesecure.dependencycheck.data.nvdcve;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Map;
|
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.*;
|
import org.junit.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
package org.codesecure.dependencycheck.data.nvdcve;
|
package org.codesecure.dependencycheck.data.nvdcve;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
@@ -46,7 +45,6 @@ public class IndexTest extends BaseIndexTestCase {
|
|||||||
String exp = File.separatorChar + "target" + File.separatorChar + "data" + File.separatorChar + "cve";
|
String exp = File.separatorChar + "target" + File.separatorChar + "data" + File.separatorChar + "cve";
|
||||||
Directory result = instance.getDirectory();
|
Directory result = instance.getDirectory();
|
||||||
|
|
||||||
assertTrue("Recieved '" + result.toString() + "' and excpected '" + exp + "'.",
|
assertTrue(result.toString().contains(exp));
|
||||||
result.toString().contains(exp));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class SettingsTest extends TestCase {
|
|||||||
public void testGetString() {
|
public void testGetString() {
|
||||||
System.out.println("getString");
|
System.out.println("getString");
|
||||||
String key = Settings.KEYS.CPE_INDEX;
|
String key = Settings.KEYS.CPE_INDEX;
|
||||||
String expResult = "../data/cpe";
|
String expResult = "target/data/cpe";
|
||||||
String result = Settings.getString(key);
|
String result = Settings.getString(key);
|
||||||
assertTrue(result.endsWith(expResult));
|
assertTrue(result.endsWith(expResult));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user