// 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;
package org.echocat.gradle.plugins.golang.utils;




public class ArchiveUtils {

    private static final Pattern REMOVE_LEADING_GO_PATH_PATTERN = Pattern.compile("^(|\\./)go/");

    public static void download(URI uri, Path to) throws IOException {
        if (exists(to)) {
            deleteQuietly(to);
        }
// 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;

package org.echocat.gradle.plugins.golang.utils;




public class ArchiveUtils {

    private static final Pattern REMOVE_LEADING_GO_PATH_PATTERN = Pattern.compile("^(|\\./)go/");

    public static void download(URI uri, Path to) throws IOException {
        if (exists(to)) {
            deleteQuietly(to);
        }
        createDirectoriesIfRequired(to);