|
| 1 | +package Hack.Utilities; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.util.Properties; |
| 5 | + |
| 6 | +public class GitRepositoryState { |
| 7 | + private static GitRepositoryState gitRepositoryState; |
| 8 | + private final String tags; |
| 9 | + private final String branch; |
| 10 | + private final String dirty; |
| 11 | + private final String remoteOriginUrl; |
| 12 | + private final String commitId; |
| 13 | + private final String commitIdAbbrev; |
| 14 | + private final String describe; |
| 15 | + private final String describeShort; |
| 16 | + private final String commitUserName; |
| 17 | + private final String commitUserEmail; |
| 18 | + private final String commitMessageFull; |
| 19 | + private final String commitMessageShort; |
| 20 | + private final String commitTime; |
| 21 | + private final String closestTagName; |
| 22 | + private final String closestTagCommitCount; |
| 23 | + private final String buildUserName; |
| 24 | + private final String buildUserEmail; |
| 25 | + private final String buildTime; |
| 26 | + private final String buildHost; |
| 27 | + private final String buildVersion; |
| 28 | + |
| 29 | + public static GitRepositoryState getGitRepositoryState() throws IOException { |
| 30 | + if (gitRepositoryState == null) { |
| 31 | + Properties properties = new Properties(); |
| 32 | + properties.load(GitRepositoryState.class.getClassLoader().getResourceAsStream("git.properties")); |
| 33 | + |
| 34 | + gitRepositoryState = new GitRepositoryState(properties); |
| 35 | + } |
| 36 | + return gitRepositoryState; |
| 37 | + } |
| 38 | + |
| 39 | + private GitRepositoryState(Properties properties) { |
| 40 | + this.tags = String.valueOf(properties.get("git.tags")); |
| 41 | + this.branch = String.valueOf(properties.get("git.branch")); |
| 42 | + this.dirty = String.valueOf(properties.get("git.dirty")); |
| 43 | + this.remoteOriginUrl = String.valueOf(properties.get("git.remote.origin.url")); |
| 44 | + |
| 45 | + this.commitId = String.valueOf(properties.get("git.commit.id.full")); // OR properties.get("git.commit.id") depending on your configuration |
| 46 | + this.commitIdAbbrev = String.valueOf(properties.get("git.commit.id.abbrev")); |
| 47 | + this.describe = String.valueOf(properties.get("git.commit.id.describe")); |
| 48 | + this.describeShort = String.valueOf(properties.get("git.commit.id.describe-short")); |
| 49 | + this.commitUserName = String.valueOf(properties.get("git.commit.user.name")); |
| 50 | + this.commitUserEmail = String.valueOf(properties.get("git.commit.user.email")); |
| 51 | + this.commitMessageFull = String.valueOf(properties.get("git.commit.message.full")); |
| 52 | + this.commitMessageShort = String.valueOf(properties.get("git.commit.message.short")); |
| 53 | + this.commitTime = String.valueOf(properties.get("git.commit.time")); |
| 54 | + this.closestTagName = String.valueOf(properties.get("git.closest.tag.name")); |
| 55 | + this.closestTagCommitCount = String.valueOf(properties.get("git.closest.tag.commit.count")); |
| 56 | + |
| 57 | + this.buildUserName = String.valueOf(properties.get("git.build.user.name")); |
| 58 | + this.buildUserEmail = String.valueOf(properties.get("git.build.user.email")); |
| 59 | + this.buildTime = String.valueOf(properties.get("git.build.time")); |
| 60 | + this.buildHost = String.valueOf(properties.get("git.build.host")); |
| 61 | + this.buildVersion = String.valueOf(properties.get("git.build.version")); |
| 62 | + } |
| 63 | + |
| 64 | + public String getTags() { |
| 65 | + return tags; |
| 66 | + } |
| 67 | + |
| 68 | + public String getBranch() { |
| 69 | + return branch; |
| 70 | + } |
| 71 | + |
| 72 | + public String getDirty() { |
| 73 | + return dirty; |
| 74 | + } |
| 75 | + |
| 76 | + public String getRemoteOriginUrl() { |
| 77 | + return remoteOriginUrl; |
| 78 | + } |
| 79 | + |
| 80 | + public String getCommitId() { |
| 81 | + return commitId; |
| 82 | + } |
| 83 | + |
| 84 | + public String getCommitIdAbbrev() { |
| 85 | + return commitIdAbbrev; |
| 86 | + } |
| 87 | + |
| 88 | + public String getDescribe() { |
| 89 | + return describe; |
| 90 | + } |
| 91 | + |
| 92 | + public String getDescribeShort() { |
| 93 | + return describeShort; |
| 94 | + } |
| 95 | + |
| 96 | + public String getCommitUserName() { |
| 97 | + return commitUserName; |
| 98 | + } |
| 99 | + |
| 100 | + public String getCommitUserEmail() { |
| 101 | + return commitUserEmail; |
| 102 | + } |
| 103 | + |
| 104 | + public String getCommitMessageFull() { |
| 105 | + return commitMessageFull; |
| 106 | + } |
| 107 | + |
| 108 | + public String getCommitMessageShort() { |
| 109 | + return commitMessageShort; |
| 110 | + } |
| 111 | + |
| 112 | + public String getCommitTime() { |
| 113 | + return commitTime; |
| 114 | + } |
| 115 | + |
| 116 | + public String getClosestTagName() { |
| 117 | + return closestTagName; |
| 118 | + } |
| 119 | + |
| 120 | + public String getClosestTagCommitCount() { |
| 121 | + return closestTagCommitCount; |
| 122 | + } |
| 123 | + |
| 124 | + public String getBuildUserName() { |
| 125 | + return buildUserName; |
| 126 | + } |
| 127 | + |
| 128 | + public String getBuildUserEmail() { |
| 129 | + return buildUserEmail; |
| 130 | + } |
| 131 | + |
| 132 | + public String getBuildTime() { |
| 133 | + return buildTime; |
| 134 | + } |
| 135 | + |
| 136 | + public String getBuildHost() { |
| 137 | + return buildHost; |
| 138 | + } |
| 139 | + |
| 140 | + public String getBuildVersion() { |
| 141 | + return buildVersion; |
| 142 | + } |
| 143 | +} |
0 commit comments