diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/GitUtils.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/GitUtils.java index cdfc0e5a2..509a587a1 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/GitUtils.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/GitUtils.java @@ -1,20 +1,22 @@ package org.jfrog.build.extractor.clientConfiguration.util; import org.apache.commons.lang3.StringUtils; -import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.api.errors.GitAPIException; -import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.revwalk.RevCommit; -import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.jfrog.build.api.util.Log; import org.jfrog.build.extractor.ci.Vcs; +import org.jfrog.build.extractor.executor.CommandExecutor; +import org.jfrog.build.extractor.executor.CommandResults; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.jfrog.build.api.IssuesCollectionConfig.ISSUES_COLLECTION_ERROR_PREFIX; public class GitUtils { + private static final String GIT_LOG_LIMIT = "100"; private static File getDotGit(File file) { if (file == null) { @@ -191,21 +193,18 @@ private static String extractVcsBranch(File dotGit, Log log) throws IOException return ""; } - private static String extractVcsMessage(File dotGit, Log log) throws IOException { - FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder(); - Repository repository = repositoryBuilder.setGitDir(dotGit) - .readEnvironment() - .findGitDir() - .build(); - RevCommit latestCommit; + private static String extractVcsMessage(File dotGit, Log log) { + String warnMessage = "Failed fetching commit message from git directory: " + dotGit + "\nWith the following error: "; try { - latestCommit = new Git(repository).log().setMaxCount(1).call().iterator().next(); - } catch (GitAPIException e) { - log.warn("Failed fetching commit message from git directory: " + dotGit + "\nWith the following error: " + e.getMessage()); - return ""; + CommandResults res = getGitLog(dotGit, log, 1); + if (res.isOk()) { + return res.getRes().trim(); + } + log.warn(warnMessage + res.getErr()); + } catch (InterruptedException | IOException e) { + log.warn(warnMessage + e.getMessage()); } - - return latestCommit.getFullMessage().trim(); + return ""; } /** @@ -215,4 +214,24 @@ private static class RevisionOrRef { private String revision; private String ref; } + + public static CommandResults getGitLog(File execDir, Log logger, String previousVcsRevision) throws InterruptedException, IOException { + return getGitLog(execDir, logger, previousVcsRevision, 0); + } + + public static CommandResults getGitLog(File execDir, Log logger, int limit) throws InterruptedException, IOException { + return getGitLog(execDir, logger, "", limit); + } + + public static CommandResults getGitLog(File execDir, Log logger, String previousVcsRevision, int limit) throws InterruptedException, IOException { + List args = new ArrayList<>(); + args.add("log"); + args.add("--pretty=format:%s"); + args.add("-" + (limit == 0 ? GIT_LOG_LIMIT : limit)); + if (!previousVcsRevision.isEmpty()) { + args.add(previousVcsRevision + ".."); + } + CommandExecutor commandExecutor = new CommandExecutor("git", null); + return commandExecutor.exeCommand(execDir, args, null, logger); + } } diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/issuesCollection/IssuesCollector.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/issuesCollection/IssuesCollector.java index 2a5e8ca17..c14162aab 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/issuesCollection/IssuesCollector.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/issuesCollection/IssuesCollector.java @@ -12,7 +12,7 @@ import org.jfrog.build.api.util.Log; import org.jfrog.build.extractor.clientConfiguration.ArtifactoryManagerBuilder; import org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager; -import org.jfrog.build.extractor.executor.CommandExecutor; +import org.jfrog.build.extractor.clientConfiguration.util.GitUtils; import org.jfrog.build.extractor.executor.CommandResults; import java.io.File; @@ -35,7 +35,6 @@ public class IssuesCollector implements Serializable { private static final long serialVersionUID = 1L; private static final String LATEST = "LATEST"; - private static final String GIT_LOG_LIMIT = "100"; public static Pattern REVISION_NOT_EXIST; @@ -145,15 +144,7 @@ private Issue getMatchingIssue(int keyIndex, int summaryIndex, Matcher matcher, } private String getGitLog(File execDir, Log logger, String previousVcsRevision) throws InterruptedException, IOException { - List args = new ArrayList<>(); - args.add("log"); - args.add("--pretty=format:%s"); - args.add("-" + GIT_LOG_LIMIT); - if (!previousVcsRevision.isEmpty()) { - args.add(previousVcsRevision + ".."); - } - CommandExecutor commandExecutor = new CommandExecutor("git", null); - CommandResults res = commandExecutor.exeCommand(execDir, args, null, logger); + CommandResults res = GitUtils.getGitLog(execDir, logger, previousVcsRevision); if (!res.isOk()) { if (getRevisionNotExistPattern().matcher(res.getErr()).find()) { logger.info("Revision: " + previousVcsRevision + " that was fetched from latest build info does not exist in the git revision range. No new issues are added."); diff --git a/build.gradle b/build.gradle index 5b945f9a1..e2120493f 100644 --- a/build.gradle +++ b/build.gradle @@ -268,7 +268,6 @@ project('build-info-extractor') { apply plugin: 'java-test-fixtures' description = 'JFrog Build-Info Extractor' dependencies { - implementation 'org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r' implementation project(':build-info-client') implementation project(':build-info-api')