mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-22 17:19:30 +01:00
updated to work with the new zip file and folder structure
Former-commit-id: e7e50500e644e108e5addfffd3a319021c594a93
This commit is contained in:
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
|
|||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import org.owasp.dependencycheck.data.update.DataStoreMetaInfo;
|
||||||
import org.owasp.dependencycheck.utils.Settings;
|
import org.owasp.dependencycheck.utils.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,18 +47,11 @@ public abstract class BaseDBTestCase extends TestCase {
|
|||||||
ensureDBExists();
|
ensureDBExists();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static File getDataDirectory() throws IOException {
|
|
||||||
final String fileName = Settings.getString(Settings.KEYS.CVE_DATA_DIRECTORY);
|
|
||||||
final String dataDirectory = Settings.getString(Settings.KEYS.DATA_DIRECTORY);
|
|
||||||
return new File(dataDirectory, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ensureDBExists() throws Exception {
|
public static void ensureDBExists() throws Exception {
|
||||||
String indexPath = getDataDirectory().getCanonicalPath();
|
|
||||||
java.io.File f = new File(indexPath);
|
java.io.File dataPath = Settings.getFile(Settings.KEYS.DATA_DIRECTORY);
|
||||||
if (!f.exists() || (f.isDirectory() && f.listFiles().length == 0)) {
|
if (!dataPath.exists() || (dataPath.isDirectory() && dataPath.listFiles().length == 0)) {
|
||||||
f = f.getParentFile();
|
dataPath.mkdirs();
|
||||||
f.mkdirs();
|
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
ZipInputStream zin = null;
|
ZipInputStream zin = null;
|
||||||
try {
|
try {
|
||||||
@@ -67,12 +61,14 @@ public abstract class BaseDBTestCase extends TestCase {
|
|||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
while ((entry = zin.getNextEntry()) != null) {
|
while ((entry = zin.getNextEntry()) != null) {
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
|
final File d = new File(dataPath, entry.getName());
|
||||||
|
d.mkdir();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
FileOutputStream fos = null;
|
FileOutputStream fos = null;
|
||||||
BufferedOutputStream dest = null;
|
BufferedOutputStream dest = null;
|
||||||
try {
|
try {
|
||||||
File o = new File(indexPath, entry.getName());
|
File o = new File(dataPath, entry.getName());
|
||||||
o.createNewFile();
|
o.createNewFile();
|
||||||
fos = new FileOutputStream(o, false);
|
fos = new FileOutputStream(o, false);
|
||||||
dest = new BufferedOutputStream(fos, BUFFER_SIZE);
|
dest = new BufferedOutputStream(fos, BUFFER_SIZE);
|
||||||
@@ -82,7 +78,7 @@ public abstract class BaseDBTestCase extends TestCase {
|
|||||||
dest.write(data, 0, count);
|
dest.write(data, 0, count);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.getLogger(BaseDBTestCase.class.getName()).log(Level.FINEST, null, ex);
|
Logger.getLogger(BaseDBTestCase.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (dest != null) {
|
if (dest != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user