|
|
|
@ -20,6 +20,9 @@ import org.eclipse.jgit.revwalk.RevCommit;
|
|
|
|
|
import org.eclipse.jgit.treewalk.TreeWalk;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
|
|
|
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
|
|
|
|
import ru.ulstu.extractor.heuristic.model.ResourceUnit;
|
|
|
|
|
import ru.ulstu.extractor.heuristic.service.StructuralUnitService;
|
|
|
|
|
import ru.ulstu.extractor.model.Author;
|
|
|
|
|
import ru.ulstu.extractor.model.Branch;
|
|
|
|
@ -85,24 +88,10 @@ public class GitRepositoryService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Commit> getCommits(String repositoryUrl, String branchName) throws GitAPIException, IOException {
|
|
|
|
|
cloneOrUpdateRepo(repositoryUrl);
|
|
|
|
|
cloneOrUpdateRepo(repositoryUrl, branchName);
|
|
|
|
|
Repository localRepo = new FileRepository(getProjectGitDirectory(repositoryUrl));
|
|
|
|
|
Git git = new Git(localRepo);
|
|
|
|
|
git.pull().call();
|
|
|
|
|
if (!localRepo.getBranch().equals(branchName)) {
|
|
|
|
|
if (getLocalBranches(repositoryUrl).stream().anyMatch(localBranch -> localBranch.getName().contains(branchName))) {
|
|
|
|
|
git.checkout()
|
|
|
|
|
.setName(branchName)
|
|
|
|
|
.call();
|
|
|
|
|
} else {
|
|
|
|
|
git.checkout()
|
|
|
|
|
.setCreateBranch(true)
|
|
|
|
|
.setName(branchName)
|
|
|
|
|
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
|
|
|
|
|
.setStartPoint("origin/" + branchName)
|
|
|
|
|
.call();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<RevCommit> commits = new ArrayList<>();
|
|
|
|
|
git.log().call().forEach(commits::add);
|
|
|
|
|
|
|
|
|
@ -125,32 +114,76 @@ public class GitRepositoryService {
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkoutBranch(String repositoryUrl, Git git, Repository localRepo, String branchName) throws GitAPIException, IOException {
|
|
|
|
|
git.pull().call();
|
|
|
|
|
if (!localRepo.getBranch().equals(branchName)) {
|
|
|
|
|
if (getLocalBranches(repositoryUrl).stream().anyMatch(localBranch -> localBranch.getName().contains(branchName))) {
|
|
|
|
|
git.checkout()
|
|
|
|
|
.setName(branchName)
|
|
|
|
|
.call();
|
|
|
|
|
} else {
|
|
|
|
|
git.checkout()
|
|
|
|
|
.setCreateBranch(true)
|
|
|
|
|
.setName(branchName)
|
|
|
|
|
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
|
|
|
|
|
.setStartPoint("origin/" + branchName)
|
|
|
|
|
.call();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
git.pull().call();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public File getProjectDirectoryFile(String url) {
|
|
|
|
|
validateUrl(url);
|
|
|
|
|
return Path.of(getProjectDirectory(url))
|
|
|
|
|
.toFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<EntityUnit> getEntities(String repositoryUrl, String branchName) throws IOException, GitAPIException {
|
|
|
|
|
cloneOrUpdateRepo(repositoryUrl, branchName);
|
|
|
|
|
return structuralUnitService.getEntities(getProjectDirectoryFile(repositoryUrl));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<BusinessLogicUnit> getBusinessLogic(String repositoryUrl, String branchName) throws IOException, GitAPIException {
|
|
|
|
|
cloneOrUpdateRepo(repositoryUrl, branchName);
|
|
|
|
|
return structuralUnitService.getBusinessLogic(getProjectDirectoryFile(repositoryUrl));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ResourceUnit> getResource(String repositoryUrl, String branchName) throws IOException, GitAPIException {
|
|
|
|
|
cloneOrUpdateRepo(repositoryUrl, branchName);
|
|
|
|
|
return structuralUnitService.getResource(getProjectDirectoryFile(repositoryUrl));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void remove(String repositoryUrl) throws IOException {
|
|
|
|
|
FileUtils.deleteDirectory(getProjectDirectoryFile(repositoryUrl));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cloneOrUpdateRepo(String url) throws GitAPIException, IOException {
|
|
|
|
|
private void cloneOrUpdateRepo(String repositoryUrl, String branchName) throws GitAPIException, IOException {
|
|
|
|
|
Git git;
|
|
|
|
|
if (projectDirExists(getProjectDirectoryFile(url))) {
|
|
|
|
|
Repository localRepo = new FileRepository(getProjectGitDirectory(url));
|
|
|
|
|
Repository localRepo;
|
|
|
|
|
if (projectDirExists(getProjectDirectoryFile(repositoryUrl))) {
|
|
|
|
|
localRepo = new FileRepository(getProjectGitDirectory(repositoryUrl));
|
|
|
|
|
git = new Git(localRepo);
|
|
|
|
|
git.pull().call();
|
|
|
|
|
localRepo.close();
|
|
|
|
|
} else {
|
|
|
|
|
git = Git.cloneRepository()
|
|
|
|
|
.setURI(url)
|
|
|
|
|
.setDirectory(getProjectDirectoryFile(url))
|
|
|
|
|
.setURI(repositoryUrl)
|
|
|
|
|
.setDirectory(getProjectDirectoryFile(repositoryUrl))
|
|
|
|
|
.call();
|
|
|
|
|
localRepo = new FileRepository(getProjectGitDirectory(repositoryUrl));
|
|
|
|
|
}
|
|
|
|
|
if (branchName != null && !branchName.isEmpty()) {
|
|
|
|
|
checkoutBranch(repositoryUrl, git, localRepo, branchName);
|
|
|
|
|
}
|
|
|
|
|
git.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cloneOrUpdateRepo(String url) throws GitAPIException, IOException {
|
|
|
|
|
cloneOrUpdateRepo(url, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getProjectDirectory(String url) {
|
|
|
|
|
return (isBlank(customProjectsDir)
|
|
|
|
|
? System.getProperty("java.io.tmpdir")
|
|
|
|
@ -268,32 +301,4 @@ public class GitRepositoryService {
|
|
|
|
|
}
|
|
|
|
|
return Optional.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Optional<String> getLineTo(String commitString) {
|
|
|
|
|
String startString = "+";
|
|
|
|
|
String startPlus = "+++";
|
|
|
|
|
if (commitString.startsWith(startString)) {
|
|
|
|
|
String lineTo = commitString.substring(commitString.indexOf(startString) + startString.length());
|
|
|
|
|
if (commitString.startsWith(startPlus)) {
|
|
|
|
|
return Optional.empty();
|
|
|
|
|
} else {
|
|
|
|
|
return Optional.of(lineTo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Optional.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Optional<String> getLineFrom(String commitString) {
|
|
|
|
|
String startString = "-";
|
|
|
|
|
String startMinus = "---";
|
|
|
|
|
if (commitString.startsWith(startString)) {
|
|
|
|
|
String lineFrom = commitString.substring(commitString.indexOf(startString) + startString.length());
|
|
|
|
|
if (commitString.startsWith(startMinus)) {
|
|
|
|
|
return Optional.empty();
|
|
|
|
|
} else {
|
|
|
|
|
return Optional.of(lineFrom);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Optional.empty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|