-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ info git/build info at startup #249
- Loading branch information
Showing
10 changed files
with
192 additions
and
55 deletions.
There are no files selected for viewing
Submodule mirana
updated
27 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...encer-curse/src/main/java/pro/fessional/wings/silencer/spring/help/VersionInfoHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package pro.fessional.wings.silencer.spring.help; | ||
|
||
import org.springframework.boot.info.GitProperties; | ||
|
||
import java.time.Instant; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
|
||
import static pro.fessional.wings.silencer.datetime.DateTimePattern.FMT_DATE_10; | ||
import static pro.fessional.wings.silencer.datetime.DateTimePattern.FMT_FULL_19Z; | ||
|
||
/** | ||
* @author trydofor | ||
* @since 2024-06-03 | ||
*/ | ||
public class VersionInfoHelper { | ||
|
||
public static String jvmName() { | ||
return System.getProperty("java.vm.name"); | ||
} | ||
|
||
public static String jvmVersion() { | ||
return System.getProperty("java.vm.version"); | ||
} | ||
|
||
public static String jvmVendor() { | ||
return System.getProperty("java.vm.vendor"); | ||
} | ||
|
||
//// | ||
public static String branch(GitProperties git) { | ||
return git == null ? null : git.getBranch(); | ||
} | ||
|
||
public static String commitIdShort(GitProperties git) { | ||
return git == null ? null : git.getShortCommitId(); | ||
} | ||
|
||
public static String commitId(GitProperties git) { | ||
if (git == null) return null; | ||
String id = git.getCommitId(); | ||
return id != null ? id : git.get("commit.id.full"); | ||
} | ||
|
||
public static String commitDateTime(GitProperties git) { | ||
return git == null ? null : toDatetime(git.getCommitTime()); | ||
} | ||
public static String commitDate(GitProperties git) { | ||
return git == null ? null : toDate(git.getCommitTime()); | ||
} | ||
|
||
public static String commitMessage(GitProperties git) { | ||
return git == null ? null : git.get("commit.message.full"); | ||
} | ||
|
||
public static String buildDateTime(GitProperties git) { | ||
return git == null ? null : toDatetime(git.getInstant("build.time")); | ||
} | ||
public static String buildDate(GitProperties git) { | ||
return git == null ? null : toDate(git.getInstant("build.time")); | ||
} | ||
|
||
public static String buildVersion(GitProperties git) { | ||
return git == null ? null : git.get("build.version"); | ||
} | ||
|
||
private static String toDatetime(Instant time) { | ||
if (time == null) return null; | ||
ZonedDateTime zdt = ZonedDateTime.ofInstant(time, ZoneId.systemDefault()); | ||
return FMT_FULL_19Z.format(zdt); | ||
} | ||
|
||
private static String toDate(Instant time) { | ||
if (time == null) return null; | ||
ZonedDateTime zdt = ZonedDateTime.ofInstant(time, ZoneId.systemDefault()); | ||
return FMT_DATE_10.format(zdt); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...r-curse/src/test/java/pro/fessional/wings/silencer/spring/help/VersionInfoHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package pro.fessional.wings.silencer.spring.help; | ||
|
||
import io.qameta.allure.TmsLink; | ||
import lombok.Setter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.info.BuildProperties; | ||
import org.springframework.boot.info.GitProperties; | ||
import org.springframework.boot.info.JavaInfo; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
/** | ||
* @author trydofor | ||
* @since 2024-06-03 | ||
*/ | ||
@SpringBootTest | ||
@Slf4j | ||
class VersionInfoHelperTest { | ||
|
||
@Setter(onMethod_ = { @Autowired }) | ||
private BuildProperties buildProperties; | ||
|
||
@Setter(onMethod_ = {@Autowired}) | ||
private GitProperties gitProperties; | ||
|
||
@Test | ||
@TmsLink("C11004") | ||
public void infoBuildAndGit() { | ||
JavaInfo javaInfo = new JavaInfo(); | ||
log.info("java={}", javaInfo); | ||
log.info("build={}", buildProperties); | ||
log.info("git={}", gitProperties); | ||
|
||
Assertions.assertEquals("pro.fessional.wings",buildProperties.getGroup()); | ||
Assertions.assertEquals("silencer-curse",buildProperties.getArtifact()); | ||
Assertions.assertNotNull(gitProperties.getBranch()); | ||
// spring use git.commit.id, need commitIdGenerationMode=flat | ||
Assertions.assertNotNull(gitProperties.getCommitId()); | ||
Assertions.assertNotNull(gitProperties.getCommitTime()); | ||
|
||
// safe and format | ||
Assertions.assertNotNull(VersionInfoHelper.jvmName()); | ||
Assertions.assertNotNull(VersionInfoHelper.jvmVersion()); | ||
Assertions.assertNotNull(VersionInfoHelper.jvmVendor()); | ||
Assertions.assertNotNull(VersionInfoHelper.commitIdShort(gitProperties)); | ||
Assertions.assertNotNull(VersionInfoHelper.commitId(gitProperties)); | ||
Assertions.assertNotNull(VersionInfoHelper.commitDate(gitProperties)); | ||
Assertions.assertNotNull(VersionInfoHelper.commitDateTime(gitProperties)); | ||
Assertions.assertNotNull(VersionInfoHelper.commitMessage(gitProperties)); | ||
Assertions.assertNotNull(VersionInfoHelper.branch(gitProperties)); | ||
Assertions.assertNotNull(VersionInfoHelper.buildDate(gitProperties)); | ||
Assertions.assertNotNull(VersionInfoHelper.buildDateTime(gitProperties)); | ||
Assertions.assertNotNull(VersionInfoHelper.buildVersion(gitProperties)); | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
wings/silencer/src/test/java/pro/fessional/wings/silencer/info/InfoPrintTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters