diff --git a/RepositoryMinerForGit/src/main/java/Test.java b/RepositoryMinerForGit/src/main/java/Test.java index b64c229..15f64f1 100644 --- a/RepositoryMinerForGit/src/main/java/Test.java +++ b/RepositoryMinerForGit/src/main/java/Test.java @@ -1,7 +1,8 @@ import java.io.File; +import java.nio.file.Path; import java.io.IOException; import java.util.List; - + import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.InvalidRemoteException; @@ -24,34 +25,48 @@ import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.eclipse.jgit.treewalk.CanonicalTreeParser; import org.eclipse.jgit.util.io.DisabledOutputStream; - + public class Test { - + public static void main(String[] args) { + + String amaryllis_server = "http://nitta-lab-www.is.konan-u.ac.jp/gitbucket/git/nitta-lab-2020/org.ntlab.amaryllis.server.git"; + String acanthus_client = "http://nitta-lab-www.is.konan-u.ac.jp/gitbucket/git/nitta-lab-2021/org.ntlab.acanthus_client.git"; + String acanthus_server = "http://nitta-lab-www.is.konan-u.ac.jp/gitbucket/git/nitta-lab-2021/org.ntlab.acanthus_server.git"; + // TODO Auto-generated method stub try { Repository repo = new FileRepository( "./project/.git" ); Git git = new Git( repo ); - + if( git != null ){ //. git clone File project = new File( "./project" ); - git.cloneRepository().setURI( "http://nitta-lab-www.is.konan-u.ac.jp/gitbucket/git/nitta-lab-2021/org.ntlab.acanthus_server.git" ).setDirectory( project ).call(); + + String filePath = "./project"; + + // フォルダの存在を確認する + if (project.exists()) { + System.out.println("projectフォルダが存在します"); + delete(filePath); + } else { + System.out.println("projectフォルダが存在しません"); + } + + git.cloneRepository().setURI( acanthus_client ).setDirectory( project ).call(); } PlotWalk revWalk = new PlotWalk(repo); ObjectId rootId = repo.resolve("HEAD"); RevCommit root = revWalk.parseCommit(rootId); revWalk.markStart(root); - + // コミットコメント PlotCommitList plotCommitList = new PlotCommitList(); plotCommitList.source(revWalk); plotCommitList.fillTo(Integer.MAX_VALUE); - + for (PlotCommit c: plotCommitList) { - //詳細情報 - System.out.println("アカウント、日付: "+c.getAuthorIdent()); // コミットメッセージ System.out.println("コミットメッセージ: " + c.getFullMessage()); ObjectId curId = c.getTree(); @@ -67,14 +82,14 @@ df.setRepository(repo); df.setDiffComparator(RawTextComparator.DEFAULT); df.setDetectRenames(true); - + ObjectReader reader = repo.newObjectReader(); CanonicalTreeParser newTreeIter = new CanonicalTreeParser(); newTreeIter.reset(reader, curId); CanonicalTreeParser oldTreeIter = new CanonicalTreeParser(); oldTreeIter.reset(reader, parentId); List entries = df.scan( oldTreeIter, newTreeIter ); - + for( DiffEntry entry : entries ) { // ファイル毎の情報 System.out.println("パス: " + entry.getNewPath()); @@ -96,7 +111,21 @@ // TODO Auto-generated catch block e.printStackTrace(); } - + } - -} + + public static void delete(String path) { + File filePath = new File(path); + String[] list = filePath.list(); + for(String file : list) { + File f = new File(path + File.separator + file); + if(f.isDirectory()) { + delete(path + File.separator + file); + }else { + f.delete(); + } + } + filePath.delete(); + } + +} \ No newline at end of file