Skip to content

Commit ee5fe6f

Browse files
committed
feat: provide timestamp properties
1 parent f7629ae commit ee5fe6f

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,10 @@ gitVersioning {
205205
206206
- `git.commit` e.g. '0fc20459a8eceb2c4abb9bf0af45a6e8af17b94b'
207207
- `git.ref` value of branch of tag name, always set
208-
- `git.branch` e.g. 'feature/next-big-thing', only set for branch versioning
209-
- `git.tag` e.g. 'v1.2.3', only set for tag versioning
210-
208+
- `git.branch` e.g. 'feature/next-big-thing', only set for branch versioning
209+
- `git.tag` e.g. 'v1.2.3', only set for tag versioning
210+
- `git.commit.timestamp` e.g. '1560694278'
211+
- `git.commit.timestamp.datetime` e.g. '2019-11-16T14:37:10Z'
211212
212213
## Miscellaneous Hints
213214

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
}
1313

1414
group 'me.qoomon'
15-
version '1.3.2'
15+
version '1.4.0'
1616

1717
sourceCompatibility = JavaVersion.VERSION_1_8
1818
targetCompatibility = JavaVersion.VERSION_1_8

src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPlugin.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
import javax.annotation.Nonnull;
99

10+
import java.time.Instant;
11+
import java.time.ZoneOffset;
12+
import java.time.format.DateTimeFormatter;
1013
import java.util.*;
1114
import java.util.Map.Entry;
1215
import java.util.stream.Collectors;
@@ -87,6 +90,9 @@ public void apply(@Nonnull Project rootProject) {
8790

8891
ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties();
8992
extraProperties.set("git.commit", gitVersionDetails.getCommit());
93+
extraProperties.set("git.commit.timestamp", Long.toString(gitVersionDetails.getCommitTimestamp()));
94+
extraProperties.set("git.commit.timestamp.datetime", toTimestampDateTime(gitVersionDetails.getCommitTimestamp()));
95+
9096
extraProperties.set("git.ref", gitVersionDetails.getCommitRefName());
9197
extraProperties.set("git." + gitVersionDetails.getCommitRefType(), gitVersionDetails.getCommitRefName());
9298
});
@@ -139,6 +145,9 @@ private String getCommandOption(final Project project, final String name) {
139145
.toUpperCase();
140146
value = System.getenv(environmentVariableName);
141147
}
148+
if(value == null) {
149+
value = System.getProperty(name);
150+
}
142151
return value;
143152
}
144153

@@ -152,5 +161,15 @@ private boolean getPreferTagsOption(final Project rootProject, final GitVersioni
152161
}
153162
return preferTagsOption;
154163
}
164+
165+
private static String toTimestampDateTime(long timestamp) {
166+
if (timestamp == 0) {
167+
return "0000-00-00T00:00:00Z";
168+
}
169+
170+
return DateTimeFormatter.ISO_DATE_TIME
171+
.withZone(ZoneOffset.UTC)
172+
.format(Instant.ofEpochSecond(timestamp));
173+
}
155174
}
156175

0 commit comments

Comments
 (0)