// Path: src/main/java/org/echocat/gradle/plugins/golang/utils/FileUtils.java
// public static void createDirectoriesIfRequired(@Nonnull Path path) throws IOException {
//     if (!exists(path)) {
//         createDirectories(path);
//     }
// }
// 
// Path: src/main/java/org/echocat/gradle/plugins/golang/utils/FileUtils.java
// public static void deleteQuietly(@Nullable Path path) {
//     if (path == null || !exists(path)) {
//         return;
//     }
//     if (isRegularFile(path)) {
//         try {
//             doDelete(path);
//         } catch (final IOException ignored) {}
//         return;
//     }
//     try {
//         walkFileTree(path, new SimpleFileVisitor<Path>() {
//             @Override
//             public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
//                 try {
//                     doDelete(file);
//                 } catch (final IOException ignored) {}
//                 return CONTINUE;
//             }
// 
//             @Override
//             public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
//                 try {
//                     doDelete(dir);
//                 } catch (final IOException ignored) {}
//                 return CONTINUE;
//             }
//         });
//     } catch (final IOException ignored) {}
// }
// 
// Path: src/main/java/org/echocat/gradle/plugins/golang/utils/FileUtils.java
// public static void ensureParentOf(@Nonnull Path path) throws IOException {
//     createDirectoriesIfRequired(path.getParent());
// }


import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Request.Builder;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFilePermission;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import static java.nio.file.Files.*;
import static org.apache.commons.io.FilenameUtils.getExtension;
import static org.apache.commons.io.IOUtils.copy;
import static org.echocat.gradle.plugins.golang.utils.FileUtils.createDirectoriesIfRequired;
import static org.echocat.gradle.plugins.golang.utils.FileUtils.deleteQuietly;
import static org.echocat.gradle.plugins.golang.utils.FileUtils.ensureParentOf;
                    createDirectoriesIfRequired(entryFile);
                } else {
                    ensureParentOf(entryFile);
                    try (final OutputStream os = newOutputStream(entryFile)) {
                        copy(archive, os);
                    }
                    final PosixFileAttributeView view = getFileAttributeView(entryFile, PosixFileAttributeView.class);
                    if (view != null) {
                        final int mode = entry.getMode();
                        final Set<PosixFilePermission> perms = new HashSet<>();
                        perms.add(PosixFilePermission.OWNER_READ);
                        perms.add(PosixFilePermission.GROUP_READ);
                        perms.add(PosixFilePermission.OTHERS_READ);
                        //noinspection OctalInteger,ResultOfMethodCallIgnored,IncompatibleBitwiseMaskOperation
                        if ((mode | 0001) > 0) {
                            perms.add(PosixFilePermission.OWNER_EXECUTE);
                        }
                        //noinspection OctalInteger,ResultOfMethodCallIgnored,IncompatibleBitwiseMaskOperation
                        if ((mode | 0100) > 0) {
                            perms.add(PosixFilePermission.GROUP_EXECUTE);
                            perms.add(PosixFilePermission.OTHERS_EXECUTE);
                        }
                        view.setPermissions(perms);
                    }
                }
                entry = archive.getNextTarEntry();
            }
        }
    }

// Path: src/main/java/org/echocat/gradle/plugins/golang/utils/FileUtils.java
// public static void createDirectoriesIfRequired(@Nonnull Path path) throws IOException {
//     if (!exists(path)) {
//         createDirectories(path);
//     }
// }
// 
// Path: src/main/java/org/echocat/gradle/plugins/golang/utils/FileUtils.java
// public static void deleteQuietly(@Nullable Path path) {
//     if (path == null || !exists(path)) {
//         return;
//     }
//     if (isRegularFile(path)) {
//         try {
//             doDelete(path);
//         } catch (final IOException ignored) {}
//         return;
//     }
//     try {
//         walkFileTree(path, new SimpleFileVisitor<Path>() {
//             @Override
//             public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
//                 try {
//                     doDelete(file);
//                 } catch (final IOException ignored) {}
//                 return CONTINUE;
//             }
// 
//             @Override
//             public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
//                 try {
//                     doDelete(dir);
//                 } catch (final IOException ignored) {}
//                 return CONTINUE;
//             }
//         });
//     } catch (final IOException ignored) {}
// }
// 
// Path: src/main/java/org/echocat/gradle/plugins/golang/utils/FileUtils.java
// public static void ensureParentOf(@Nonnull Path path) throws IOException {
//     createDirectoriesIfRequired(path.getParent());
// }


// Path: src/main/java/org/echocat/gradle/plugins/golang/utils/ArchiveUtils.java
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Request.Builder;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFilePermission;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import static java.nio.file.Files.*;
import static org.apache.commons.io.FilenameUtils.getExtension;
import static org.apache.commons.io.IOUtils.copy;
import static org.echocat.gradle.plugins.golang.utils.FileUtils.createDirectoriesIfRequired;
import static org.echocat.gradle.plugins.golang.utils.FileUtils.deleteQuietly;
import static org.echocat.gradle.plugins.golang.utils.FileUtils.ensureParentOf;

                    createDirectoriesIfRequired(entryFile);
                } else {
                    ensureParentOf(entryFile);
                    try (final OutputStream os = newOutputStream(entryFile)) {
                        copy(archive, os);
                    }
                    final PosixFileAttributeView view = getFileAttributeView(entryFile, PosixFileAttributeView.class);
                    if (view != null) {
                        final int mode = entry.getMode();
                        final Set<PosixFilePermission> perms = new HashSet<>();
                        perms.add(PosixFilePermission.OWNER_READ);
                        perms.add(PosixFilePermission.GROUP_READ);
                        perms.add(PosixFilePermission.OTHERS_READ);
                        //noinspection OctalInteger,ResultOfMethodCallIgnored,IncompatibleBitwiseMaskOperation
                        if ((mode | 0001) > 0) {
                            perms.add(PosixFilePermission.OWNER_EXECUTE);
                        }
                        //noinspection OctalInteger,ResultOfMethodCallIgnored,IncompatibleBitwiseMaskOperation
                        if ((mode | 0100) > 0) {
                            perms.add(PosixFilePermission.GROUP_EXECUTE);
                            perms.add(PosixFilePermission.OTHERS_EXECUTE);
                        }
                        view.setPermissions(perms);
                    }
                }
                entry = archive.getNextTarEntry();
            }
        }
    }

    public static void unZip(Path file, Path target) throws IOException {