Skip to content

Commit 57eb2e6

Browse files
committed
Log version and git properties at startup
1 parent 0b56c87 commit 57eb2e6

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

build.gradle.kts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
application
33
java
4+
alias(libs.plugins.gradle.git.properties)
45
alias(libs.plugins.shadow)
56
}
67

@@ -34,6 +35,7 @@ dependencies {
3435
// ********** distribution **********
3536

3637
tasks.shadowJar {
38+
dependsOn(tasks.generateGitProperties)
3739
mergeServiceFiles()
3840
archiveBaseName = "split-tests-java"
3941
archiveClassifier = ""
@@ -59,3 +61,16 @@ dependencies {
5961
tasks.test {
6062
useJUnitPlatform()
6163
}
64+
65+
// ********** git properties **********
66+
67+
gitProperties {
68+
dotGitDirectory = project.rootProject.layout.projectDirectory.dir(".git")
69+
gitPropertiesName = "split-tests-java.properties"
70+
keys = listOf("git.branch", "git.commit.id", "git.commit.id.abbrev", "git.commit.time")
71+
customProperty("version", version)
72+
extProperty = "gitProps"
73+
}
74+
tasks.generateGitProperties {
75+
outputs.upToDateWhen { false }
76+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher
2020
logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
2121

2222
[plugins]
23+
gradle-git-properties = { id = "com.gorylenko.gradle-git-properties", version = "2.5.0" }
2324
shadow = { id = "com.gradleup.shadow", version = "8.3.6" }

src/main/java/de/donnerbart/split/TestSplitMain.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99
import org.slf4j.Logger;
1010
import org.slf4j.LoggerFactory;
1111

12+
import java.io.FileInputStream;
1213
import java.nio.file.Files;
1314
import java.nio.file.Path;
1415
import java.nio.file.Paths;
16+
import java.text.SimpleDateFormat;
17+
import java.time.Instant;
18+
import java.util.Date;
1519
import java.util.Objects;
20+
import java.util.Properties;
1621
import java.util.function.Consumer;
1722

1823
import static de.donnerbart.split.util.FormatUtil.formatTime;
@@ -46,6 +51,12 @@ public static void main(final @Nullable String @NotNull [] args) throws Exceptio
4651
if (!validateArguments(arguments, workingDirectory)) {
4752
exitConsumer.accept(1);
4853
}
54+
final var properties = readProperties();
55+
LOG.info("split-tests-java {} (commit: {} on branch: {}) built on {}",
56+
properties.getProperty("version", "unknown"),
57+
properties.getProperty("git.commit.id.abbrev", "unknown"),
58+
properties.getProperty("git.branch", "unknown"),
59+
getBuiltTime(properties.getProperty("git.commit.time", "unknown")));
4960
LOG.info("Split index {} (total: {})", arguments.splitIndex, arguments.splitTotal);
5061
LOG.info("Working directory: {}", workingDirectory);
5162
LOG.info("Glob: {}", arguments.glob);
@@ -140,4 +151,22 @@ static int calculateOptimalTotalSplit(final @NotNull Arguments arguments, final
140151
lastSlowestSplit = slowestSplit;
141152
}
142153
}
154+
155+
private static @NotNull Properties readProperties() throws Exception {
156+
final var resource = Thread.currentThread().getContextClassLoader().getResource("split-tests-java.properties");
157+
if (resource == null) {
158+
throw new IllegalStateException("Cannot find split-tests-java.properties in classpath");
159+
}
160+
final var properties = new Properties();
161+
properties.load(new FileInputStream(resource.getPath()));
162+
return properties;
163+
}
164+
165+
private static @NotNull Date getBuiltTime(final @NotNull String dateString) {
166+
try {
167+
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse(dateString);
168+
} catch (final Exception e) {
169+
return Date.from(Instant.EPOCH);
170+
}
171+
}
143172
}

0 commit comments

Comments
 (0)