Skip to content

Commit

Permalink
detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara committed Aug 21, 2024
1 parent 58554b3 commit 47e3b97
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
4 changes: 1 addition & 3 deletions build-logic/plugins/src/main/kotlin/AppVersionPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import com.wire.android.gradle.version.Versionizer
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import java.io.ByteArrayOutputStream
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter


/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
Expand All @@ -28,7 +26,7 @@ class AppVersionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
project.tasks.register("generateVersionFile", Task::class.java) {
//clean the repo from a probably existing version.txt
// clean the repo from a probably existing version.txt
if (file("$projectDir/version.txt").exists()) {
println("deleting existing version.txt file for safety reasons")
file("$projectDir/version.txt").delete()
Expand Down
2 changes: 1 addition & 1 deletion build-logic/plugins/src/main/kotlin/Extention.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import java.io.ByteArrayOutputStream
*/

fun String.execute(): Process {
val process = ProcessBuilder(*this.split(" ").toTypedArray())
val process = ProcessBuilder(this.split(" "))
.redirectErrorStream(true)
.start()
process.waitFor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Versionizer(
// VersionCode: $$VERCODE$$\n
// the file is added by CI tp sync build version between store and fdroid
private fun readFromInternalFile(): Int? {
val file = File("${projectDir}/version.txt")
val file = File("$projectDir/version.txt")
println("looking for version file")
if (file.exists()) {
println("Reading version from file")
Expand Down
48 changes: 33 additions & 15 deletions build-logic/plugins/src/test/kotlin/VersionizerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.amshove.kluent.shouldBeLessThan
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import java.io.File
import java.time.LocalDateTime

@RunWith(JUnit4::class)
Expand All @@ -32,23 +33,26 @@ class VersionizerTest {
@Test
fun `given version generator when I generate two versions AT THE SAME TIME I should get the same version number`() {
val dateTime = LocalDateTime.now()

Versionizer(dateTime).versionCode shouldBeEqualTo Versionizer(dateTime).versionCode
val projectRoot = File("")
Versionizer(projectRoot, dateTime).versionCode shouldBeEqualTo Versionizer(projectRoot, dateTime).versionCode
}


@Test
fun `given version generator when I generate a version I should get the same version number on the current Android project`() {
val dateTime = LocalDateTime.of(2021, 6, 23, 13, 54, 28)
val projectRoot = File("")

Versionizer(dateTime).versionCode shouldBeEqualTo 548966
Versionizer(projectRoot, dateTime).versionCode shouldBeEqualTo 548966
}

@Test
fun `given before than 21 of June 2024 Build, then bump every 10 seconds`() {
val oldDate = LocalDateTime.of(2024, 6, 20, 0, 0)
val oldVersionCode = Versionizer(oldDate).versionCode
val newVersionCode = Versionizer(oldDate.plusSeconds(10)).versionCode
val projectRoot = File("")

val oldVersionCode = Versionizer(projectRoot, oldDate).versionCode
val newVersionCode = Versionizer(projectRoot, oldDate.plusSeconds(10)).versionCode

assertVersionCodeAreProperlyIncremented(oldVersionCode, newVersionCode)
assertEquals(1, newVersionCode - oldVersionCode)
Expand All @@ -57,8 +61,10 @@ class VersionizerTest {
@Test
fun `given after 21 of June 2024 Build, then bump every 5 minutes`() {
val oldDate = LocalDateTime.of(2024, 6, 22, 14, 0)
val oldVersionCode = Versionizer(oldDate).versionCode
val newVersionCode = Versionizer(oldDate.plusMinutes(5)).versionCode
val projectRoot = File("")

val oldVersionCode = Versionizer(projectRoot, oldDate).versionCode
val newVersionCode = Versionizer(projectRoot, oldDate.plusMinutes(5)).versionCode

println("Version number: $newVersionCode")
assertVersionCodeAreProperlyIncremented(oldVersionCode, newVersionCode)
Expand All @@ -67,38 +73,50 @@ class VersionizerTest {

@Test
fun `given version generator when I generate a new version THE NEXT DAY then I should get an incremented version number`() {
val oldVersionCode = Versionizer().versionCode
val newVersionCode = Versionizer(LocalDateTime.now().plusDays(1)).versionCode
val projectRoot = File("")
val oldVersionCode = Versionizer(projectRoot).versionCode
val newVersionCode = Versionizer(projectRoot, LocalDateTime.now().plusDays(1)).versionCode

assertVersionCodeAreProperlyIncremented(oldVersionCode, newVersionCode)
}

@Test
fun `given version generator when I generate a new version IN ONE YEAR then I should get an incremented version number`() {
val oldVersionCode = Versionizer().versionCode
val newVersionCode = Versionizer(LocalDateTime.now().plusYears(1)).versionCode
val projectRoot = File("")
val oldVersionCode = Versionizer(projectRoot).versionCode
val newVersionCode = Versionizer(projectRoot, LocalDateTime.now().plusYears(1)).versionCode

assertVersionCodeAreProperlyIncremented(oldVersionCode, newVersionCode)
}

@Test
fun `given version generator when I generate a new version IN ONE and TWO YEARS then I should get an incremented version number`() {
val now = LocalDateTime.now()
val oldVersionCode = Versionizer(now.plusYears(1)).versionCode
val newVersionCode = Versionizer(now.plusYears(2)).versionCode
val projectRoot = File("")
val oldVersionCode = Versionizer(projectRoot, now.plusYears(1)).versionCode
val newVersionCode = Versionizer(projectRoot, now.plusYears(2)).versionCode

assertVersionCodeAreProperlyIncremented(oldVersionCode, newVersionCode)
}

@Test
fun `given version generator when I generate a new version IN TEN YEARS then I should get an incremented version number`() {
val oldVersionCode = Versionizer().versionCode
val newVersionCode = Versionizer(LocalDateTime.now().plusYears(10)).versionCode
val projectRoot = File("")
val oldVersionCode = Versionizer(projectRoot).versionCode
val newVersionCode = Versionizer(projectRoot, LocalDateTime.now().plusYears(10)).versionCode

// This will break 655 years from now.
assertVersionCodeAreProperlyIncremented(oldVersionCode, newVersionCode)
}

@Test
fun `given root project have version txt file, then use the version code from the file`() {
val projectRoot = File("src/test/resources")
val versionCode = Versionizer(projectRoot).versionCode

versionCode shouldBeEqualTo 100018802
}

private fun assertVersionCodeAreProperlyIncremented(oldVersionCode: Int, newVersionCode: Int) {
oldVersionCode shouldBeGreaterThan 0
newVersionCode shouldBeGreaterThan 0
Expand Down
5 changes: 5 additions & 0 deletions build-logic/plugins/src/test/resources/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VersionCode: 100018802
VersionName: 4.8.2-18802
Revision: e53642019
Buildtime: 2024-08-21 19:32:06
Application-name: com.wire

0 comments on commit 47e3b97

Please sign in to comment.