#16 -- Remove repo after indexing

This commit is contained in:
Anton Romanov 2021-03-29 17:01:04 +04:00
parent c89a27d495
commit 014af08531

View File

@ -1,5 +1,6 @@
package ru.ulstu.extractor.service; package ru.ulstu.extractor.service;
import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.CreateBranchCommand; import org.eclipse.jgit.api.CreateBranchCommand;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ListBranchCommand; import org.eclipse.jgit.api.ListBranchCommand;
@ -42,14 +43,14 @@ public class GitRepositoryService {
Repository localRepo = new FileRepository(getProjectGitDirectory(url)); Repository localRepo = new FileRepository(getProjectGitDirectory(url));
git = new Git(localRepo); git = new Git(localRepo);
git.pull().call(); git.pull().call();
localRepo.close();
} else { } else {
git = Git.cloneRepository() git = Git.cloneRepository()
.setURI(url) .setURI(url)
.setDirectory(getProjectDirectoryFile(url)) .setDirectory(getProjectDirectoryFile(url))
.call(); .call();
} }
Iterable<RevCommit> commits = git.log().call(); git.close();
//commits.forEach(c -> System.out.println(c.getFullMessage()));
} }
private String getProjectDirectory(String url) { private String getProjectDirectory(String url) {
@ -101,6 +102,8 @@ public class GitRepositoryService {
list.add(commit); list.add(commit);
prevCommit = revCommit; prevCommit = revCommit;
} }
git.close();
localRepo.close();
return list; return list;
} }
@ -207,14 +210,17 @@ public class GitRepositoryService {
cloneOrUpdateRepo(url); cloneOrUpdateRepo(url);
Repository localRepo = new FileRepository(getProjectGitDirectory(url)); Repository localRepo = new FileRepository(getProjectGitDirectory(url));
Git git = new Git(localRepo); Git git = new Git(localRepo);
return git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE) List<Branch> branches = git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE)
.call() .call()
.stream() .stream()
.map(r -> new Branch(r.getName().replace(BRANCH_PREFIX, ""))) .map(r -> new Branch(r.getName().replace(BRANCH_PREFIX, "")))
.collect(Collectors.toList()); .collect(Collectors.toList());
git.close();
localRepo.close();
return branches;
} }
public void remove(String repositoryUrl) throws IOException { public void remove(String repositoryUrl) throws IOException {
//FileUtils.deleteDirectory(getProjectDirectoryFile(repositoryUrl)); FileUtils.deleteDirectory(getProjectDirectoryFile(repositoryUrl));
} }
} }