Search in sources :

Example 1 with AddOnDownloadData

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));
}
Also used : AddOnDownloadData(org.zaproxy.zap.internal.AddOnDownloadData) Arrays(java.util.Arrays) Iterator(java.util.Iterator) Files(java.nio.file.Files) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) OutputDirectory(org.gradle.api.tasks.OutputDirectory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TaskAction(org.gradle.api.tasks.TaskAction) List(java.util.List) RegularFileProperty(org.gradle.api.file.RegularFileProperty) ObjectFactory(org.gradle.api.model.ObjectFactory) DirectoryProperty(org.gradle.api.file.DirectoryProperty) DownloadAction(de.undercouch.gradle.tasks.download.DownloadAction) InputFile(org.gradle.api.tasks.InputFile) DefaultTask(org.gradle.api.DefaultTask) DigestUtils(org.apache.commons.codec.digest.DigestUtils) InvalidUserDataException(org.gradle.api.InvalidUserDataException) InputStream(java.io.InputStream) AddOnDownloadData(org.zaproxy.zap.internal.AddOnDownloadData) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile)

Example 2 with AddOnDownloadData

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);
    }
}
Also used : ArrayList(java.util.ArrayList) AddOnDownloadData(org.zaproxy.zap.internal.AddOnDownloadData) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile)

Example 3 with AddOnDownloadData

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);
    }
}
Also used : AddOnDownloadData(org.zaproxy.zap.internal.AddOnDownloadData) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

AddOnDownloadData (org.zaproxy.zap.internal.AddOnDownloadData)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 InputFile (org.gradle.api.tasks.InputFile)2 TaskAction (org.gradle.api.tasks.TaskAction)2 DownloadAction (de.undercouch.gradle.tasks.download.DownloadAction)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Files (java.nio.file.Files)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 DigestUtils (org.apache.commons.codec.digest.DigestUtils)1 DefaultTask (org.gradle.api.DefaultTask)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 DirectoryProperty (org.gradle.api.file.DirectoryProperty)1 RegularFileProperty (org.gradle.api.file.RegularFileProperty)1