use of org.zaproxy.zap.internal.AddOnDownloadData in project zaproxy by zaproxy.
the class DownloadAddOns method parseAddOnsData.
private Set<AddOnDownloadData> parseAddOnsData() throws IOException {
File outputDirectory = getOutputDir().get().getAsFile();
List<String> lines = Files.readAllLines(addOnsData.get().getAsFile().toPath());
return lines.stream().map(String::trim).filter(line -> !(line.isEmpty() || line.startsWith("#"))).map(line -> {
String[] lineData = line.split(" ", 2);
String url = lineData[0];
String hash = lineData[1];
File file = new File(outputDirectory, getFileName(url));
return new AddOnDownloadData(url, hash, file);
}).collect(Collectors.toCollection(HashSet::new));
}
use of org.zaproxy.zap.internal.AddOnDownloadData in project zaproxy by zaproxy.
the class DownloadAddOns method checkExistingFiles.
private void checkExistingFiles(Set<AddOnDownloadData> downloads) {
File[] files = getOutputDir().get().getAsFile().listFiles();
if (files == null) {
return;
}
List<File> existingFiles = new ArrayList<>(Arrays.asList(files));
for (Iterator<AddOnDownloadData> it = downloads.iterator(); it.hasNext(); ) {
AddOnDownloadData downloadData = it.next();
File file = downloadData.getOutputFile();
if (existingFiles.contains(file) && hasSameHash(file, downloadData.getHash())) {
existingFiles.remove(file);
it.remove();
}
}
for (File file : existingFiles) {
getProject().delete(file);
}
}
use of org.zaproxy.zap.internal.AddOnDownloadData in project zaproxy by zaproxy.
the class DownloadAddOns method download.
@TaskAction
public void download() throws IOException {
Set<AddOnDownloadData> downloads = parseAddOnsData();
checkExistingFiles(downloads);
for (AddOnDownloadData downloadData : downloads) {
downloadFile(downloadData);
}
}
Aggregations