mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-19 07:44:23 +01:00
corrected minor issue with path to zipped test data
Former-commit-id: 862ea03dc2738dc315a82c03d514f3ce8b6f410e
This commit is contained in:
@@ -146,13 +146,32 @@ Copyright (c) 2013 - Jeremy Long. All Rights Reserved.
|
|||||||
<directory>${basedir}/../src/test/resources</directory>
|
<directory>${basedir}/../src/test/resources</directory>
|
||||||
<filtering>false</filtering>
|
<filtering>false</filtering>
|
||||||
<includes>
|
<includes>
|
||||||
<include>jetty-6.1.0.jar</include>
|
|
||||||
<include>org.mortbay.jetty.jar</include>
|
<include>org.mortbay.jetty.jar</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>copy-data</id>
|
||||||
|
<phase>validate</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/test-classes</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${basedir}/../src/test/resources</directory>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
<includes>
|
||||||
|
<include>db.cve.zip</include>
|
||||||
|
<include>index.cpe.zip</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -238,6 +257,10 @@ Copyright (c) 2013 - Jeremy Long. All Rights Reserved.
|
|||||||
<value>${project.build.directory}/cobertura/cobertura.ser</value>
|
<value>${project.build.directory}/cobertura/cobertura.ser</value>
|
||||||
<workingDirectory>target</workingDirectory>
|
<workingDirectory>target</workingDirectory>
|
||||||
</property>
|
</property>
|
||||||
|
<property>
|
||||||
|
<name>data.directory</name>
|
||||||
|
<value>${project.build.directory}/dependency-check-data</value>
|
||||||
|
</property>
|
||||||
</systemProperties>
|
</systemProperties>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
@@ -389,6 +412,13 @@ Copyright (c) 2013 - Jeremy Long. All Rights Reserved.
|
|||||||
<artifactId>dependency-check-core</artifactId>
|
<artifactId>dependency-check-core</artifactId>
|
||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.owasp</groupId>
|
||||||
|
<artifactId>dependency-check-core</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<type>test-jar</type>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.ant</groupId>
|
<groupId>org.apache.ant</groupId>
|
||||||
<artifactId>ant</artifactId>
|
<artifactId>ant</artifactId>
|
||||||
|
|||||||
@@ -46,7 +46,10 @@ public class DependencyCheckTaskTest extends BuildFileTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
@Override
|
@Override
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
|
org.owasp.dependencycheck.data.nvdcve.BaseDBTestCase.ensureDBExists(DependencyCheckTaskTest.class);
|
||||||
|
org.owasp.dependencycheck.data.cpe.BaseIndexTestCase.ensureIndexExists(this.getClass());
|
||||||
|
|
||||||
final String buildFile = this.getClass().getClassLoader().getResource("build.xml").getPath();
|
final String buildFile = this.getClass().getClassLoader().getResource("build.xml").getPath();
|
||||||
configureProject(buildFile);
|
configureProject(buildFile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,6 +112,18 @@ along with Dependency-Check. If not, see <http://www.gnu.org/licenses />.
|
|||||||
</excludes>
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>test-jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>cobertura-maven-plugin</artifactId>
|
<artifactId>cobertura-maven-plugin</artifactId>
|
||||||
|
|||||||
@@ -258,15 +258,17 @@ public final class Settings {
|
|||||||
* to the folder containing the JAR file containing this class.
|
* to the folder containing the JAR file containing this class.
|
||||||
*
|
*
|
||||||
* @param key the key to lookup within the properties file
|
* @param key the key to lookup within the properties file
|
||||||
|
* @param clazz the class to obtain the base directory from in case "[JAR]\"
|
||||||
|
* exists
|
||||||
* @return the property from the properties file converted to a File object
|
* @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
|
* @throws IOException thrown if the file path to the JAR cannot be found
|
||||||
*/
|
*/
|
||||||
public static File getFile(String key) throws IOException {
|
public static File getFile(String key, Class clazz) throws IOException {
|
||||||
final String file = getString(key);
|
final String file = getString(key);
|
||||||
final String baseDir = getString(Settings.KEYS.DATA_DIRECTORY);
|
final String baseDir = getString(Settings.KEYS.DATA_DIRECTORY);
|
||||||
if (baseDir != null) {
|
if (baseDir != null) {
|
||||||
if (baseDir.startsWith("[JAR]/")) {
|
if (baseDir.startsWith("[JAR]/")) {
|
||||||
final File jarPath = getJarPath();
|
final File jarPath = getJarPath(clazz);
|
||||||
final File newBase = new File(jarPath.getCanonicalPath(), baseDir.substring(6));
|
final File newBase = new File(jarPath.getCanonicalPath(), baseDir.substring(6));
|
||||||
return new File(newBase, file);
|
return new File(newBase, file);
|
||||||
}
|
}
|
||||||
@@ -275,14 +277,31 @@ public final class Settings {
|
|||||||
return new File(file);
|
return new File(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a value from the properties file as a File object. If the value
|
||||||
|
* was specified as a system property or passed in via the -Dprop=value
|
||||||
|
* 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) throws IOException {
|
||||||
|
return getFile(key, Settings.class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to retrieve the folder containing the Jar file containing the
|
* Attempts to retrieve the folder containing the Jar file containing the
|
||||||
* Settings class.
|
* Settings class.
|
||||||
*
|
*
|
||||||
* @return a File object
|
* @return a File object
|
||||||
*/
|
*/
|
||||||
private static File getJarPath() {
|
private static File getJarPath(Class clazz) {
|
||||||
final String jarPath = Settings.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
final String jarPath = clazz.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||||
String decodedPath = ".";
|
String decodedPath = ".";
|
||||||
try {
|
try {
|
||||||
decodedPath = URLDecoder.decode(jarPath, "UTF-8");
|
decodedPath = URLDecoder.decode(jarPath, "UTF-8");
|
||||||
@@ -291,7 +310,8 @@ public final class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final File path = new File(decodedPath);
|
final File path = new File(decodedPath);
|
||||||
if (path.getName().toLowerCase().endsWith(".jar")) {
|
//TODO - need to remove the "test-classes" check which is only here to make test cases work.
|
||||||
|
if (path.getName().toLowerCase().endsWith(".jar") || path.getName().equals("test-classes")) {
|
||||||
return path.getParentFile();
|
return path.getParentFile();
|
||||||
} else {
|
} else {
|
||||||
return new File(".");
|
return new File(".");
|
||||||
|
|||||||
@@ -61,16 +61,18 @@ public abstract class BaseIndexTestCase {
|
|||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static File getDataDirectory() throws IOException {
|
protected static File getDataDirectory(Class clazz) throws IOException {
|
||||||
final String fileName = Settings.getString(Settings.KEYS.CPE_DATA_DIRECTORY);
|
final File dataDirectory = Settings.getFile(Settings.KEYS.CPE_DATA_DIRECTORY, clazz);
|
||||||
final String dataDirectory = Settings.getString(Settings.KEYS.DATA_DIRECTORY);
|
return dataDirectory;
|
||||||
return new File(dataDirectory, fileName);
|
|
||||||
//return FileUtils.getDataDirectory(fileName, Index.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ensureIndexExists() throws Exception {
|
public static void ensureIndexExists() throws Exception {
|
||||||
|
ensureIndexExists(BaseIndexTestCase.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ensureIndexExists(Class clazz) throws Exception {
|
||||||
//String indexPath = Settings.getString(Settings.KEYS.CPE_DATA_DIRECTORY);
|
//String indexPath = Settings.getString(Settings.KEYS.CPE_DATA_DIRECTORY);
|
||||||
String indexPath = getDataDirectory().getCanonicalPath();
|
String indexPath = getDataDirectory(clazz).getAbsolutePath();
|
||||||
java.io.File f = new File(indexPath);
|
java.io.File f = new File(indexPath);
|
||||||
|
|
||||||
if (!f.exists() || (f.isDirectory() && f.listFiles().length == 0)) {
|
if (!f.exists() || (f.isDirectory() && f.listFiles().length == 0)) {
|
||||||
|
|||||||
@@ -46,21 +46,24 @@ public abstract class BaseDBTestCase extends TestCase {
|
|||||||
ensureDBExists();
|
ensureDBExists();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static File getDataDirectory() throws IOException {
|
protected static File getDataDirectory(Class clazz) throws IOException {
|
||||||
final String fileName = Settings.getString(Settings.KEYS.CVE_DATA_DIRECTORY);
|
final File dataDirectory = Settings.getFile(Settings.KEYS.CVE_DATA_DIRECTORY, clazz);
|
||||||
final String dataDirectory = Settings.getString(Settings.KEYS.DATA_DIRECTORY);
|
return dataDirectory;
|
||||||
return new File(dataDirectory, fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ensureDBExists() throws Exception {
|
public static void ensureDBExists() throws Exception {
|
||||||
String indexPath = getDataDirectory().getCanonicalPath();
|
ensureDBExists(BaseDBTestCase.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ensureDBExists(Class clazz) throws Exception {
|
||||||
|
String indexPath = getDataDirectory(clazz).getAbsolutePath();
|
||||||
java.io.File f = new File(indexPath);
|
java.io.File f = new File(indexPath);
|
||||||
if (!f.exists() || (f.isDirectory() && f.listFiles().length == 0)) {
|
if (!f.exists() || (f.isDirectory() && f.listFiles().length == 0)) {
|
||||||
f.mkdirs();
|
f.mkdirs();
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
ZipInputStream zin = null;
|
ZipInputStream zin = null;
|
||||||
try {
|
try {
|
||||||
File path = new File(BaseDBTestCase.class.getClassLoader().getResource("db.cve.zip").getPath());
|
File path = new File(clazz.getClassLoader().getResource("db.cve.zip").getPath());
|
||||||
fis = new FileInputStream(path);
|
fis = new FileInputStream(path);
|
||||||
zin = new ZipInputStream(new BufferedInputStream(fis));
|
zin = new ZipInputStream(new BufferedInputStream(fis));
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
|
|||||||
Reference in New Issue
Block a user