|
@@ -0,0 +1,60 @@
|
|
|
+package api.common.util;
|
|
|
+
|
|
|
+import io.minio.MinioClient;
|
|
|
+import io.minio.PutObjectArgs;
|
|
|
+import io.minio.errors.MinioException;
|
|
|
+import org.eclipse.jgit.api.Git;
|
|
|
+import org.eclipse.jgit.api.errors.GitAPIException;
|
|
|
+import org.eclipse.jgit.lib.Ref;
|
|
|
+import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.security.InvalidKeyException;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ <dependency>
|
|
|
+ <groupId>org.eclipse.jgit</groupId>
|
|
|
+ <artifactId>org.eclipse.jgit</artifactId>
|
|
|
+ </dependency>
|
|
|
+ */
|
|
|
+public class JgitUtil {
|
|
|
+
|
|
|
+
|
|
|
+ public static Map<String, Ref> testConnection(String remoteUrl, String username, String password) throws GitAPIException {
|
|
|
+ UsernamePasswordCredentialsProvider provider = new UsernamePasswordCredentialsProvider(username,password);
|
|
|
+ Map<String, Ref> asMap = Git.lsRemoteRepository().setRemote(remoteUrl).setCredentialsProvider(provider).callAsMap();
|
|
|
+ return asMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Map<String, Ref> testConnectionByToken(String remoteUrl, String gitToken) throws GitAPIException {
|
|
|
+ UsernamePasswordCredentialsProvider provider = new UsernamePasswordCredentialsProvider("PRIVATE-TOKEN", gitToken);
|
|
|
+ Map<String, Ref> asMap = Git.lsRemoteRepository().setRemote(remoteUrl).setCredentialsProvider(provider).callAsMap();
|
|
|
+ return asMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Git clone(String remoteUrl, String directory, String username, String password) throws GitAPIException, IOException {
|
|
|
+ UsernamePasswordCredentialsProvider provider = new UsernamePasswordCredentialsProvider(username,password);
|
|
|
+ File localPath = new File(directory);
|
|
|
+ Git result = Git.cloneRepository().setURI(remoteUrl).setDirectory(localPath).setCredentialsProvider(provider).call();
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) throws GitAPIException, IOException {
|
|
|
+ try {
|
|
|
+ Map<String, Ref> asMap = testConnection("http://10.15.12.70:3000/CSS/simulation-cloud.git","zhaoyan","111112111");
|
|
|
+ System.out.println("slfasjkfasfksd:");
|
|
|
+ System.out.println(asMap);
|
|
|
+ }catch (Exception e){
|
|
|
+ System.out.println("failllll:");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|