| 1 |
import java.time.Instant |
| 2 |
import java.time.OffsetDateTime |
| 3 |
import java.time.ZoneOffset |
| 4 |
import java.time.format.DateTimeFormatter |
| 5 |
import java.time.format.DateTimeFormatterBuilder |
| 6 |
|
| 7 |
plugins { |
| 8 |
id("junitbuild.build-parameters") |
| 9 |
} |
| 10 |
|
| 11 |
val dateFormatter = DateTimeFormatter.ISO_LOCAL_DATE |
| 12 |
val timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSSZ") |
| 13 |
|
| 14 |
val buildTimeAndDate = buildParameters.manifest.buildTimestamp |
| 15 |
.map { |
| 16 |
it.toLongOrNull() |
| 17 |
?.let { s -> Instant.ofEpochSecond(s).atOffset(ZoneOffset.UTC) } |
| 18 |
?: DateTimeFormatterBuilder() |
| 19 |
.append(dateFormatter) |
| 20 |
.appendLiteral(' ') |
| 21 |
.append(timeFormatter) |
| 22 |
.toFormatter() |
| 23 |
.parse(it) |
| 24 |
} |
| 25 |
.orNull |
| 26 |
?: OffsetDateTime.now() |
| 27 |
|
| 28 |
val buildDate: String by extra { dateFormatter.format(buildTimeAndDate) } |
| 29 |
val buildTime: String by extra { timeFormatter.format(buildTimeAndDate) } |
| 30 |
val buildRevision: String by extra { |
| 31 |
providers.exec { |
| 32 |
commandLine("git", "rev-parse", "--verify", "HEAD") |
| 33 |
}.standardOutput.asText.get() |
| 34 |
} |