| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.owasp.dependencycheck.data.update; |
| 20 | |
|
| 21 | |
import java.io.File; |
| 22 | |
import java.net.URL; |
| 23 | |
import java.util.concurrent.Callable; |
| 24 | |
import java.util.logging.Level; |
| 25 | |
import java.util.logging.Logger; |
| 26 | |
import org.owasp.dependencycheck.utils.DownloadFailedException; |
| 27 | |
import org.owasp.dependencycheck.utils.Downloader; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | 0 | public class CallableDownloadTask implements Callable<CallableDownloadTask> { |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | 0 | public CallableDownloadTask(NvdCveInfo nvdCveInfo, File first, File second) { |
| 44 | 0 | this.nvdCveInfo = nvdCveInfo; |
| 45 | 0 | this.first = first; |
| 46 | 0 | this.second = second; |
| 47 | 0 | } |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
private NvdCveInfo nvdCveInfo; |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
public NvdCveInfo getNvdCveInfo() { |
| 59 | 0 | return nvdCveInfo; |
| 60 | |
} |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
public void setNvdCveInfo(NvdCveInfo nvdCveInfo) { |
| 68 | 0 | this.nvdCveInfo = nvdCveInfo; |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
private File first; |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
public File getFirst() { |
| 81 | 0 | return first; |
| 82 | |
} |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
public void setFirst(File first) { |
| 90 | 0 | this.first = first; |
| 91 | 0 | } |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
private File second; |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
public File getSecond() { |
| 103 | 0 | return second; |
| 104 | |
} |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
public void setSecond(File second) { |
| 112 | 0 | this.second = second; |
| 113 | 0 | } |
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | 0 | private Exception exception = null; |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
public Exception getException() { |
| 125 | 0 | return exception; |
| 126 | |
} |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
public boolean hasException() { |
| 134 | 0 | return exception != null; |
| 135 | |
} |
| 136 | |
|
| 137 | |
@Override |
| 138 | |
public CallableDownloadTask call() throws Exception { |
| 139 | |
try { |
| 140 | 0 | final URL url1 = new URL(nvdCveInfo.getUrl()); |
| 141 | 0 | final URL url2 = new URL(nvdCveInfo.getOldSchemaVersionUrl()); |
| 142 | 0 | String msg = String.format("Download Started for NVD CVE - %s", nvdCveInfo.getId()); |
| 143 | 0 | Logger.getLogger(CallableDownloadTask.class.getName()).log(Level.INFO, msg); |
| 144 | 0 | Downloader.fetchFile(url1, first); |
| 145 | 0 | Downloader.fetchFile(url2, second); |
| 146 | 0 | msg = String.format("Download Complete for NVD CVE - %s", nvdCveInfo.getId()); |
| 147 | 0 | Logger.getLogger(CallableDownloadTask.class.getName()).log(Level.INFO, msg); |
| 148 | 0 | } catch (DownloadFailedException ex) { |
| 149 | 0 | this.exception = ex; |
| 150 | 0 | } |
| 151 | 0 | return this; |
| 152 | |
} |
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
public void cleanup() { |
| 158 | 0 | boolean deleted = false; |
| 159 | |
try { |
| 160 | 0 | if (first != null && first.exists()) { |
| 161 | 0 | deleted = first.delete(); |
| 162 | |
} |
| 163 | |
} finally { |
| 164 | 0 | if (first != null && (first.exists() || !deleted)) { |
| 165 | 0 | first.deleteOnExit(); |
| 166 | |
} |
| 167 | |
} |
| 168 | |
try { |
| 169 | 0 | deleted = false; |
| 170 | 0 | if (second != null && second.exists()) { |
| 171 | 0 | deleted = second.delete(); |
| 172 | |
} |
| 173 | |
} finally { |
| 174 | 0 | if (second != null && (second.exists() || !deleted)) { |
| 175 | 0 | second.deleteOnExit(); |
| 176 | |
} |
| 177 | |
} |
| 178 | 0 | } |
| 179 | |
} |