mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-04-19 07:00:23 +02:00
minor updates for issue #58
Former-commit-id: ffb30eb654dfb71317c32a5553074f45e4024ab9
This commit is contained in:
@@ -109,10 +109,11 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
|
||||
File file = null;
|
||||
boolean deleteTempFile = false;
|
||||
try {
|
||||
Pattern uriRx = Pattern.compile("^(https?|file)\\:.*", Pattern.CASE_INSENSITIVE);
|
||||
final Pattern uriRx = Pattern.compile("^(https?|file)\\:.*", Pattern.CASE_INSENSITIVE);
|
||||
if (uriRx.matcher(suppressionFilePath).matches()) {
|
||||
deleteTempFile = true;
|
||||
file = File.createTempFile("suppression", "xml", Settings.getTempDirectory());
|
||||
URL url = new URL(suppressionFilePath);
|
||||
final URL url = new URL(suppressionFilePath);
|
||||
try {
|
||||
Downloader.fetchFile(url, file, false);
|
||||
} catch (DownloadFailedException ex) {
|
||||
|
||||
@@ -63,6 +63,26 @@ public final class Downloader {
|
||||
* @throws DownloadFailedException is thrown if there is an error downloading the file
|
||||
*/
|
||||
public static void fetchFile(URL url, File outputPath, boolean useProxy) throws DownloadFailedException {
|
||||
if ("file".equalsIgnoreCase(url.getProtocol())) {
|
||||
File file;
|
||||
try {
|
||||
file = new File(url.toURI());
|
||||
} catch (URISyntaxException ex) {
|
||||
final String msg = String.format("Download failed, unable to locate '%s'", url.toString());
|
||||
throw new DownloadFailedException(msg);
|
||||
}
|
||||
if (file.exists()) {
|
||||
try {
|
||||
org.apache.commons.io.FileUtils.copyFile(file, outputPath);
|
||||
} catch (IOException ex) {
|
||||
final String msg = String.format("Download failed, unable to copy '%s'", url.toString());
|
||||
throw new DownloadFailedException(msg);
|
||||
}
|
||||
} else {
|
||||
final String msg = String.format("Download failed, file does not exist '%s'", url.toString());
|
||||
throw new DownloadFailedException(msg);
|
||||
}
|
||||
} else {
|
||||
HttpURLConnection conn = null;
|
||||
try {
|
||||
conn = URLConnectionFactory.createHttpURLConnection(url, useProxy);
|
||||
@@ -123,6 +143,7 @@ public final class Downloader {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an HTTP Head request to retrieve the last modified date of the given URL. If the file:// protocol is
|
||||
@@ -134,20 +155,11 @@ public final class Downloader {
|
||||
*/
|
||||
public static long getLastModified(URL url) throws DownloadFailedException {
|
||||
long timestamp = 0;
|
||||
//TODO add the FPR protocol?
|
||||
//TODO add the FTP protocol?
|
||||
if ("file".equalsIgnoreCase(url.getProtocol())) {
|
||||
File lastModifiedFile;
|
||||
try {
|
||||
// if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
|
||||
// String filePath = url.toString();
|
||||
// if (filePath.matches("file://[a-zA-Z]:.*")) {
|
||||
// f = new File(filePath.substring(7));
|
||||
// } else {
|
||||
// f = new File(url.toURI());
|
||||
// }
|
||||
// } else {
|
||||
lastModifiedFile = new File(url.toURI());
|
||||
// }
|
||||
} catch (URISyntaxException ex) {
|
||||
final String msg = String.format("Unable to locate '%s'; is the cve.url-2.0.modified property set correctly?", url.toString());
|
||||
throw new DownloadFailedException(msg);
|
||||
|
||||
Reference in New Issue
Block a user