From 138960cfb730c9963a13b016fc6bd7b37ba2df95 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 27 Apr 2021 17:05:39 +0400 Subject: [PATCH] add threads --- .../service/GitRepositoryService.java | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/service/GitRepositoryService.java b/src/main/java/ru/ulstu/extractor/service/GitRepositoryService.java index e2ecf19..e90dfa8 100644 --- a/src/main/java/ru/ulstu/extractor/service/GitRepositoryService.java +++ b/src/main/java/ru/ulstu/extractor/service/GitRepositoryService.java @@ -18,6 +18,8 @@ import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.treewalk.TreeWalk; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit; @@ -43,12 +45,16 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Optional; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.stream.Collectors; import static org.apache.logging.log4j.util.Strings.isBlank; @Service public class GitRepositoryService { + private final static Logger LOG = LoggerFactory.getLogger(GitRepositoryService.class); private static final String BRANCH_PREFIX = "refs/remotes/origin/"; @Value("${extractor.custom-projects-dir}") private String customProjectsDir; @@ -60,7 +66,9 @@ public class GitRepositoryService { } public List getRemoteBranches(String url) throws GitAPIException, IOException { + LOG.debug("Get remote branches of {}. Clone", url); cloneOrUpdateRepo(url); + LOG.debug("Get remote branches of {}. Get branches", url); Repository localRepo = new FileRepository(getProjectGitDirectory(url)); Git git = new Git(localRepo); List branches = git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE) @@ -74,7 +82,9 @@ public class GitRepositoryService { } public List getLocalBranches(String url) throws GitAPIException, IOException { + LOG.debug("Get local branches of {}. Clone", url); cloneOrUpdateRepo(url); + LOG.debug("Get local branches of {}. Get branches", url); Repository localRepo = new FileRepository(getProjectGitDirectory(url)); Git git = new Git(localRepo); List branches = git.branchList() @@ -88,6 +98,7 @@ public class GitRepositoryService { } public List getCommits(String repositoryUrl, String branchName) throws GitAPIException, IOException { + LOG.debug("Get commits of {}. Branch {}", repositoryUrl, branchName); cloneOrUpdateRepo(repositoryUrl, branchName); Repository localRepo = new FileRepository(getProjectGitDirectory(repositoryUrl)); Git git = new Git(localRepo); @@ -97,7 +108,10 @@ public class GitRepositoryService { List list = new ArrayList<>(); RevCommit prevCommit = null; + LOG.debug("Start analyse {} commits", commits.size()); + int counter = commits.size(); for (RevCommit revCommit : commits) { + LOG.debug(" {} of {} commits", counter--, commits.size()); Commit commit = new Commit( revCommit.getFullMessage(), new Author(revCommit.getAuthorIdent().getName()), @@ -115,6 +129,7 @@ public class GitRepositoryService { } private void checkoutBranch(String repositoryUrl, Git git, Repository localRepo, String branchName) throws GitAPIException, IOException { + LOG.debug("Checkout branch {} {}", repositoryUrl, branchName); git.pull().call(); if (!localRepo.getBranch().equals(branchName)) { if (getLocalBranches(repositoryUrl).stream().anyMatch(localBranch -> localBranch.getName().contains(branchName))) { @@ -236,12 +251,20 @@ public class GitRepositoryService { if (maybeFileName.isPresent()) { fileChange = new FileChange(); fileChange.setFile(maybeFileName.get()); - fileChange.setContainsEntity( - structuralUnitService.containsEntity(getContent(repository, commit, maybeFileName.get())) - ); - fileChange.setContainsBusinessLogic( - structuralUnitService.containsBusinessLogic(getContent(repository, commit, maybeFileName.get())) - ); + ExecutorService executorService = Executors.newFixedThreadPool(2); + Future futureEntity = executorService.submit(() -> { + return structuralUnitService.containsEntity(getContent(repository, commit, maybeFileName.get())); + }); + + Future futureBL = executorService.submit(() -> { + return structuralUnitService.containsBusinessLogic(getContent(repository, commit, maybeFileName.get())); + }); + try { + fileChange.setContainsBusinessLogic(futureBL.get()); + fileChange.setContainsEntity(futureEntity.get()); + } catch (Exception ex) { + LOG.warn(ex.getMessage()); + } /// вытащить другие изменения из коммита changes.add(fileChange); }