// 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/vcs/git/GitVcsUri.java
// @Nonnull
// public static GitVcsUri gitVcsUriFor(@Nonnull VcsReference reference) {
//     return gitVcsUriFor(reference.getUri());
// }


import com.sun.nio.sctp.IllegalReceiveException;
import org.echocat.gradle.plugins.golang.vcs.*;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.transport.HttpTransport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.nio.file.Path;
import java.util.regex.Pattern;
import static org.echocat.gradle.plugins.golang.utils.FileUtils.deleteQuietly;
import static org.echocat.gradle.plugins.golang.vcs.git.GitVcsUri.gitVcsUriFor;
package org.echocat.gradle.plugins.golang.vcs.git;




public class GitVcsRepository extends VcsRepositorySupport {

    static {
        HttpTransport.setConnectionFactory(new HttpConnectionFactoryImpl());
    }

    protected static final Pattern SPLIT_PATH_PATTERN = Pattern.compile("^(?<root>/[A-Za-z0-9_.\\-/]+?\\.git)(?<subPath>/.*|)$");
    private static final Logger LOGGER = LoggerFactory.getLogger(VcsRepositorySupport.class);

    public GitVcsRepository(@Nonnull VcsReference ref) {
        super(ref);
    }

    @Override
    public boolean isWorking() throws VcsException {
        try {
            return resolveRemoteRef() != null;
        } catch (final IllegalReceiveException ignored) {
            return false;
        } catch (final GitAPIException e) {
            throw new VcsException(e);
        }
    }

    @Override
    @Nonnull
    protected VcsFullReference downloadToInternal(@Nonnull Path targetDirectory, @Nullable ProgressMonitor progressMonitor) throws VcsException {
        Ref ref = null;
// 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/vcs/git/GitVcsUri.java
// @Nonnull
// public static GitVcsUri gitVcsUriFor(@Nonnull VcsReference reference) {
//     return gitVcsUriFor(reference.getUri());
// }


// Path: src/main/java/org/echocat/gradle/plugins/golang/vcs/git/GitVcsRepository.java
import com.sun.nio.sctp.IllegalReceiveException;
import org.echocat.gradle.plugins.golang.vcs.*;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.transport.HttpTransport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.nio.file.Path;
import java.util.regex.Pattern;
import static org.echocat.gradle.plugins.golang.utils.FileUtils.deleteQuietly;
import static org.echocat.gradle.plugins.golang.vcs.git.GitVcsUri.gitVcsUriFor;

package org.echocat.gradle.plugins.golang.vcs.git;




public class GitVcsRepository extends VcsRepositorySupport {

    static {
        HttpTransport.setConnectionFactory(new HttpConnectionFactoryImpl());
    }

    protected static final Pattern SPLIT_PATH_PATTERN = Pattern.compile("^(?<root>/[A-Za-z0-9_.\\-/]+?\\.git)(?<subPath>/.*|)$");
    private static final Logger LOGGER = LoggerFactory.getLogger(VcsRepositorySupport.class);

    public GitVcsRepository(@Nonnull VcsReference ref) {
        super(ref);
    }

    @Override
    public boolean isWorking() throws VcsException {
        try {
            return resolveRemoteRef() != null;
        } catch (final IllegalReceiveException ignored) {
            return false;
        } catch (final GitAPIException e) {
            throw new VcsException(e);
        }
    }

    @Override
    @Nonnull
    protected VcsFullReference downloadToInternal(@Nonnull Path targetDirectory, @Nullable ProgressMonitor progressMonitor) throws VcsException {
        Ref ref = null;
        final GitVcsUri uri = gitVcsUriFor(getReference());