From 8c31e4d63b336f984534636c3a1885403a7189d7 Mon Sep 17 00:00:00 2001 From: yuanyuancin Date: Thu, 13 Oct 2022 17:59:13 +0800 Subject: [PATCH] Fix/build info (#579) * fix build info when git in commit * fix build info * change version to 2.0.7-SNAPSHOT Co-authored-by: yuanyuan Co-authored-by: leo james --- pom.xml | 2 +- sofa-ark-bom/pom.xml | 2 +- sofa-ark-parent/assembly/pom.xml | 2 +- sofa-ark-parent/core-impl/archive/pom.xml | 2 +- sofa-ark-parent/core-impl/container/pom.xml | 2 +- sofa-ark-parent/core-impl/pom.xml | 2 +- sofa-ark-parent/core/api/pom.xml | 2 +- sofa-ark-parent/core/common/pom.xml | 2 +- sofa-ark-parent/core/exception/pom.xml | 2 +- sofa-ark-parent/core/pom.xml | 2 +- sofa-ark-parent/core/spi/pom.xml | 2 +- sofa-ark-parent/pom.xml | 2 +- .../support/ark-maven-plugin/pom.xml | 2 +- .../support/ark-plugin-maven-plugin/pom.xml | 2 +- .../ark-common-springboot/pom.xml | 2 +- .../ark-compatible-springboot1/pom.xml | 2 +- .../ark-compatible-springboot2/pom.xml | 2 +- .../ark-springboot-starter/pom.xml | 2 +- .../support/ark-support-starter/pom.xml | 2 +- sofa-ark-parent/support/ark-tools/pom.xml | 2 +- .../alipay/sofa/ark/tools/git/JGitParser.java | 31 +++++++++++++++++++ sofa-ark-parent/support/pom.xml | 2 +- sofa-ark-plugin/config-ark-plugin/pom.xml | 2 +- sofa-ark-plugin/web-ark-plugin/pom.xml | 2 +- 24 files changed, 54 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index c160fcebc..785c37ca0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.alipay.sofa sofa-ark - 2.0.6 + 2.0.7-SNAPSHOT pom diff --git a/sofa-ark-bom/pom.xml b/sofa-ark-bom/pom.xml index 9e5b0c276..3476899dc 100644 --- a/sofa-ark-bom/pom.xml +++ b/sofa-ark-bom/pom.xml @@ -5,7 +5,7 @@ sofa-ark com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT 4.0.0 diff --git a/sofa-ark-parent/assembly/pom.xml b/sofa-ark-parent/assembly/pom.xml index 0f5c64988..0513f35cd 100644 --- a/sofa-ark-parent/assembly/pom.xml +++ b/sofa-ark-parent/assembly/pom.xml @@ -4,7 +4,7 @@ sofa-ark-parent com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT sofa-ark-all diff --git a/sofa-ark-parent/core-impl/archive/pom.xml b/sofa-ark-parent/core-impl/archive/pom.xml index 5df40bdc5..3254284f8 100644 --- a/sofa-ark-parent/core-impl/archive/pom.xml +++ b/sofa-ark-parent/core-impl/archive/pom.xml @@ -4,7 +4,7 @@ sofa-ark-core-impl com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT sofa-ark-archive diff --git a/sofa-ark-parent/core-impl/container/pom.xml b/sofa-ark-parent/core-impl/container/pom.xml index d703cfe87..88d39dd0e 100644 --- a/sofa-ark-parent/core-impl/container/pom.xml +++ b/sofa-ark-parent/core-impl/container/pom.xml @@ -4,7 +4,7 @@ sofa-ark-core-impl com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT sofa-ark-container diff --git a/sofa-ark-parent/core-impl/pom.xml b/sofa-ark-parent/core-impl/pom.xml index 3641f2b8d..2b23aa7f1 100644 --- a/sofa-ark-parent/core-impl/pom.xml +++ b/sofa-ark-parent/core-impl/pom.xml @@ -4,7 +4,7 @@ sofa-ark-parent com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT sofa-ark-core-impl diff --git a/sofa-ark-parent/core/api/pom.xml b/sofa-ark-parent/core/api/pom.xml index 4fcb4375d..85c281d6c 100644 --- a/sofa-ark-parent/core/api/pom.xml +++ b/sofa-ark-parent/core/api/pom.xml @@ -5,7 +5,7 @@ sofa-ark-core com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT 4.0.0 diff --git a/sofa-ark-parent/core/common/pom.xml b/sofa-ark-parent/core/common/pom.xml index 0e7972f72..4ea40e005 100644 --- a/sofa-ark-parent/core/common/pom.xml +++ b/sofa-ark-parent/core/common/pom.xml @@ -4,7 +4,7 @@ sofa-ark-core com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT sofa-ark-common diff --git a/sofa-ark-parent/core/exception/pom.xml b/sofa-ark-parent/core/exception/pom.xml index 76ff2ff97..a61df5705 100644 --- a/sofa-ark-parent/core/exception/pom.xml +++ b/sofa-ark-parent/core/exception/pom.xml @@ -4,7 +4,7 @@ sofa-ark-core com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT sofa-ark-exception diff --git a/sofa-ark-parent/core/pom.xml b/sofa-ark-parent/core/pom.xml index e2b40b6c0..22e06e92d 100644 --- a/sofa-ark-parent/core/pom.xml +++ b/sofa-ark-parent/core/pom.xml @@ -4,7 +4,7 @@ sofa-ark-parent com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT sofa-ark-core diff --git a/sofa-ark-parent/core/spi/pom.xml b/sofa-ark-parent/core/spi/pom.xml index cb06457b4..84f8219d7 100644 --- a/sofa-ark-parent/core/spi/pom.xml +++ b/sofa-ark-parent/core/spi/pom.xml @@ -4,7 +4,7 @@ sofa-ark-core com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT sofa-ark-spi diff --git a/sofa-ark-parent/pom.xml b/sofa-ark-parent/pom.xml index 822d1c84d..ef54c52b8 100644 --- a/sofa-ark-parent/pom.xml +++ b/sofa-ark-parent/pom.xml @@ -5,7 +5,7 @@ sofa-ark-bom com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT ../sofa-ark-bom 4.0.0 diff --git a/sofa-ark-parent/support/ark-maven-plugin/pom.xml b/sofa-ark-parent/support/ark-maven-plugin/pom.xml index 6da3e513d..b0685375d 100644 --- a/sofa-ark-parent/support/ark-maven-plugin/pom.xml +++ b/sofa-ark-parent/support/ark-maven-plugin/pom.xml @@ -5,7 +5,7 @@ sofa-ark-support com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT 4.0.0 maven-plugin diff --git a/sofa-ark-parent/support/ark-plugin-maven-plugin/pom.xml b/sofa-ark-parent/support/ark-plugin-maven-plugin/pom.xml index 4054d9eb8..5fc0347e3 100644 --- a/sofa-ark-parent/support/ark-plugin-maven-plugin/pom.xml +++ b/sofa-ark-parent/support/ark-plugin-maven-plugin/pom.xml @@ -5,7 +5,7 @@ sofa-ark-support com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT 4.0.0 diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-common-springboot/pom.xml b/sofa-ark-parent/support/ark-springboot-integration/ark-common-springboot/pom.xml index 3a8c008fe..ddb80f935 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-common-springboot/pom.xml +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-common-springboot/pom.xml @@ -5,7 +5,7 @@ sofa-ark-support com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-compatible-springboot1/pom.xml b/sofa-ark-parent/support/ark-springboot-integration/ark-compatible-springboot1/pom.xml index 33a773141..c5bc8f072 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-compatible-springboot1/pom.xml +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-compatible-springboot1/pom.xml @@ -5,7 +5,7 @@ sofa-ark-support com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-compatible-springboot2/pom.xml b/sofa-ark-parent/support/ark-springboot-integration/ark-compatible-springboot2/pom.xml index 1bf9c9ae9..2b090afab 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-compatible-springboot2/pom.xml +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-compatible-springboot2/pom.xml @@ -5,7 +5,7 @@ sofa-ark-support com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/pom.xml b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/pom.xml index 7ed2bd9ae..0f9df217e 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/pom.xml +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/pom.xml @@ -5,7 +5,7 @@ sofa-ark-support com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/sofa-ark-parent/support/ark-support-starter/pom.xml b/sofa-ark-parent/support/ark-support-starter/pom.xml index b1cd271f7..8d43000a1 100644 --- a/sofa-ark-parent/support/ark-support-starter/pom.xml +++ b/sofa-ark-parent/support/ark-support-starter/pom.xml @@ -5,7 +5,7 @@ sofa-ark-support com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT 4.0.0 diff --git a/sofa-ark-parent/support/ark-tools/pom.xml b/sofa-ark-parent/support/ark-tools/pom.xml index 6e10657e4..9e024d9d1 100644 --- a/sofa-ark-parent/support/ark-tools/pom.xml +++ b/sofa-ark-parent/support/ark-tools/pom.xml @@ -4,7 +4,7 @@ sofa-ark-support com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT sofa-ark-tools diff --git a/sofa-ark-parent/support/ark-tools/src/main/java/com/alipay/sofa/ark/tools/git/JGitParser.java b/sofa-ark-parent/support/ark-tools/src/main/java/com/alipay/sofa/ark/tools/git/JGitParser.java index cc70aae32..26a4d45dc 100644 --- a/sofa-ark-parent/support/ark-tools/src/main/java/com/alipay/sofa/ark/tools/git/JGitParser.java +++ b/sofa-ark-parent/support/ark-tools/src/main/java/com/alipay/sofa/ark/tools/git/JGitParser.java @@ -16,6 +16,10 @@ */ package com.alipay.sofa.ark.tools.git; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.ListBranchCommand; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.lib.*; import org.eclipse.jgit.revwalk.RevCommit; @@ -26,8 +30,12 @@ import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; import static com.alipay.sofa.ark.spi.constant.Constants.DATE_FORMAT; +import static org.eclipse.jgit.lib.Constants.MASTER; public class JGitParser { @@ -59,6 +67,11 @@ public static GitInfo parse(File gitDirectory) { gitInfo.setLastCommitEmail(lastCommitEmail); gitInfo.setLastCommitTime(lastCommitTime); gitInfo.setLastCommitDateTime(commitDateTime); + + if (lastCommitId.equals(branchName)) { + gitInfo.setBranchName(StringUtils.join( + getBranchsFromCommit(repository, lastCommitId), ",")); + } } return gitInfo; @@ -67,6 +80,24 @@ public static GitInfo parse(File gitDirectory) { } } + private static List getBranchsFromCommit(FileRepository repository, String lastCommitId) throws GitAPIException { + Git git = new Git(repository); + List refs = Git.wrap(repository).branchList() + .setListMode(ListBranchCommand.ListMode.REMOTE) + .setContains(lastCommitId) + .call(); + return refs.stream() + .filter(ref -> !ref.isSymbolic()) + .map(Ref::getName) + .map(repository::shortenRemoteBranchName) + .filter(StringUtils::isNotBlank) + .distinct() + .sorted(MASTER_FIRST_COMPARATOR) + .collect(Collectors.toList()); + } + + public static final Comparator MASTER_FIRST_COMPARATOR = (o1, o2) -> MASTER.equals(o1) ? -1 : 1; + private static RevCommit getLastCommit(Repository repository) throws Exception { RevWalk revWalk = new RevWalk(repository); Ref headCommitReference = repository.getRefDatabase().findRef("HEAD"); diff --git a/sofa-ark-parent/support/pom.xml b/sofa-ark-parent/support/pom.xml index fc4df975a..a1f54172d 100644 --- a/sofa-ark-parent/support/pom.xml +++ b/sofa-ark-parent/support/pom.xml @@ -5,7 +5,7 @@ sofa-ark-parent com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT 4.0.0 diff --git a/sofa-ark-plugin/config-ark-plugin/pom.xml b/sofa-ark-plugin/config-ark-plugin/pom.xml index f46d97333..d190f2d77 100644 --- a/sofa-ark-plugin/config-ark-plugin/pom.xml +++ b/sofa-ark-plugin/config-ark-plugin/pom.xml @@ -5,7 +5,7 @@ sofa-ark-bom com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT ../../sofa-ark-bom 4.0.0 diff --git a/sofa-ark-plugin/web-ark-plugin/pom.xml b/sofa-ark-plugin/web-ark-plugin/pom.xml index 6a7fd222b..a3ae6feb8 100644 --- a/sofa-ark-plugin/web-ark-plugin/pom.xml +++ b/sofa-ark-plugin/web-ark-plugin/pom.xml @@ -5,7 +5,7 @@ sofa-ark-bom com.alipay.sofa - 2.0.6 + 2.0.7-SNAPSHOT ../../sofa-ark-bom 4.0.0