Skip to content

Commit

Permalink
[SVN] r3292 Gradle Plugin in /Libraries/twister-plugin-gradle/
Browse files Browse the repository at this point in the history
[COM] Release 4.1.1.14-29-29.1
[FIX] Flaky test around midnight
  • Loading branch information
TWiStErRob committed Jul 11, 2021
1 parent 46d3e11 commit 8cc6e81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -49,11 +51,11 @@ open class CalculateBuildTimeTask : DefaultTask() {

fun TaskProvider<CalculateBuildTimeTask>.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)} */"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`() {
Expand Down

0 comments on commit 8cc6e81

Please sign in to comment.