From 8cc6e8199e227e3ad47b22bbf58c43436e513874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Papp=20=28TWiStErRob=29?= Date: Sun, 11 Jul 2021 23:28:04 +0000 Subject: [PATCH] [SVN] r3292 Gradle Plugin in /Libraries/twister-plugin-gradle/ [COM] Release 4.1.1.14-29-29.1 [FIX] Flaky test around midnight --- .../gradle/android/tasks/CalculateBuildTimeTask.kt | 10 ++++++---- .../gradle/android/AndroidBuildPluginIntgTest.kt | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/plugin/plugin/src/main/kotlin/net/twisterrob/gradle/android/tasks/CalculateBuildTimeTask.kt b/plugin/plugin/src/main/kotlin/net/twisterrob/gradle/android/tasks/CalculateBuildTimeTask.kt index 321aeefb4..02a38b4a5 100644 --- a/plugin/plugin/src/main/kotlin/net/twisterrob/gradle/android/tasks/CalculateBuildTimeTask.kt +++ b/plugin/plugin/src/main/kotlin/net/twisterrob/gradle/android/tasks/CalculateBuildTimeTask.kt @@ -12,7 +12,9 @@ import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskProvider import java.time.Instant +import java.time.OffsetDateTime import java.time.format.DateTimeFormatter +import java.time.temporal.ChronoUnit import java.util.concurrent.TimeUnit private val DAY = TimeUnit.DAYS.toMillis(1) @@ -24,12 +26,12 @@ open class CalculateBuildTimeTask : DefaultTask() { * to minimize `compile*JavaWithJavac` rebuilds due to a single number change in BuildConfig.java. * * It can be overridden like this: - * `tasks.calculateBuildConfigBuildTime.configure { getBuildTime = { System.currentTimeMillies() }}` + * `tasks.calculateBuildConfigBuildTime.configure { getBuildTime = { System.currentTimeMillis() }}` * * @returns a long representing the UTC time of the build. */ @Input - var getBuildTime = { System.currentTimeMillis() / DAY * DAY } + var getBuildTime = { OffsetDateTime.now().truncatedTo(ChronoUnit.DAYS).toInstant().toEpochMilli() } @get:OutputFile val buildTimeFile: RegularFileProperty = intermediateRegularFile("buildConfigDecorations/buildTime.txt") @@ -49,11 +51,11 @@ open class CalculateBuildTimeTask : DefaultTask() { fun TaskProvider.addBuildConfigFields(android: BaseExtension) { val buildTimeField = flatMap(CalculateBuildTimeTask::buildTimeFile).map { - it.asBuildConfigField("java.util.Date") { + it.asBuildConfigField("java.util.Date") { date -> fun dateFormat(date: Long): String = DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(date)) - val buildTime = it.toLong() + val buildTime = date.toLong() "new java.util.Date(${buildTime}L) /* ${dateFormat(buildTime)} */" } } diff --git a/plugin/plugin/src/test/kotlin/net/twisterrob/gradle/android/AndroidBuildPluginIntgTest.kt b/plugin/plugin/src/test/kotlin/net/twisterrob/gradle/android/AndroidBuildPluginIntgTest.kt index 590813955..83df37a97 100644 --- a/plugin/plugin/src/test/kotlin/net/twisterrob/gradle/android/AndroidBuildPluginIntgTest.kt +++ b/plugin/plugin/src/test/kotlin/net/twisterrob/gradle/android/AndroidBuildPluginIntgTest.kt @@ -333,21 +333,22 @@ class AndroidBuildPluginIntgTest : BaseAndroidIntgTest() { val result = gradle.run(script, "test").build() - val today = LocalDate.now().atStartOfDay().toEpochSecond(ZoneOffset.UTC) * 1000 + val today = LocalDate.now().atStartOfDay() + val todayMillis = today.toEpochSecond(ZoneOffset.systemDefault().rules.getOffset(today)) * 1000 result.assertSuccess(":testReleaseUnitTest") result.assertHasOutputLine(" release.app_package=${packageName}") result.assertHasOutputLine(" release.in_prod=true") result.assertHasOutputLine(" release.in_test=false") result.assertHasOutputLine(" release.REVISION=no VCS") result.assertHasOutputLine(" release.REVISION_NUMBER=0") - result.assertHasOutputLine(" release.BUILD_TIME=${today}") + result.assertHasOutputLine(" release.BUILD_TIME=${todayMillis}") result.assertSuccess(":testDebugUnitTest") result.assertHasOutputLine(" debug.app_package=${packageName}.debug") result.assertHasOutputLine(" debug.in_prod=false") result.assertHasOutputLine(" debug.in_test=true") result.assertHasOutputLine(" debug.REVISION=no VCS") result.assertHasOutputLine(" debug.REVISION_NUMBER=0") - result.assertHasOutputLine(" debug.BUILD_TIME=${today}") + result.assertHasOutputLine(" debug.BUILD_TIME=${todayMillis}") } @Test fun `can customize build time`() {