Skip to content

Commit e5e9f8f

Browse files
committed
chore: buildconfig changes
1 parent c9750fe commit e5e9f8f

File tree

6 files changed

+98
-4
lines changed

6 files changed

+98
-4
lines changed

common/src/commonMain/kotlin/dev/suresh/Greeting.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class Greeting {
2525
| Platform : Kotlin $platform
2626
| Build Time : ${BuildConfig.buildTimeLocal}
2727
| Build Version : ${BuildConfig.version}
28+
| Build OS : ${BuildConfig.buildOS}
29+
| Build User : ${BuildConfig.buildUser}
30+
| Build Host : ${BuildConfig.buildHost}
31+
| Build JDK : ${BuildConfig.buildJdkVersion}
2832
| Java Version : ${BuildConfig.java}
2933
| Kotlin Version : ${KotlinVersion.CURRENT}
3034
| Gradle Version : ${BuildConfig.gradle}

common/src/commonTest/kotlin/dev/suresh/CommonTest.kt

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
package dev.suresh
22

3+
import io.ktor.client.*
4+
import io.ktor.client.engine.mock.*
5+
import io.ktor.client.plugins.*
6+
import io.ktor.client.plugins.compression.*
7+
import io.ktor.client.plugins.contentnegotiation.*
8+
import io.ktor.client.plugins.cookies.*
9+
import io.ktor.client.plugins.logging.*
10+
import io.ktor.client.plugins.resources.*
11+
import io.ktor.client.request.*
12+
import io.ktor.client.statement.*
13+
import io.ktor.http.*
14+
import io.ktor.serialization.kotlinx.json.*
15+
import kotlin.test.DefaultAsserter.assertEquals
316
import kotlin.test.Test
417
import kotlin.test.assertTrue
18+
import kotlinx.coroutines.test.runTest
19+
import kotlinx.serialization.json.Json
520

621
class CommonTest {
722

@@ -10,4 +25,66 @@ class CommonTest {
1025
assertTrue(
1126
actual = Greeting().greeting().contains("Kotlin"), message = "Check 'Kotlin' is mentioned")
1227
}
28+
29+
@Test
30+
fun httpClient() = runTest {
31+
val client =
32+
HttpClient(
33+
MockEngine { req ->
34+
respondError(HttpStatusCode.BadRequest, "Client Error Response")
35+
}) {
36+
install(Resources)
37+
38+
install(ContentNegotiation) {
39+
json(
40+
Json {
41+
prettyPrint = true
42+
isLenient = true
43+
ignoreUnknownKeys = true
44+
})
45+
}
46+
47+
install(ContentEncoding) {
48+
deflate(1.0F)
49+
gzip(0.9F)
50+
}
51+
52+
install(HttpTimeout) {
53+
requestTimeoutMillis = 5_000
54+
connectTimeoutMillis = 5_000
55+
socketTimeoutMillis = 5_000
56+
}
57+
58+
install(HttpCookies)
59+
60+
install(Logging) {
61+
logger = Logger.DEFAULT
62+
level = LogLevel.INFO
63+
}
64+
65+
engine { pipelining = true }
66+
67+
followRedirects = true
68+
69+
HttpResponseValidator {
70+
validateResponse {
71+
// it.body<String>()
72+
when (it.status.value) {
73+
in 300..399 -> throw RedirectResponseException(it, "Redirect error")
74+
in 400..499 -> throw ClientRequestException(it, "Client error")
75+
in 500..599 -> throw ServerResponseException(it, "Server error")
76+
}
77+
}
78+
}
79+
}
80+
81+
try {
82+
client.get("/")
83+
} catch (e: ClientRequestException) {
84+
assertEquals(
85+
expected = "Client Error Response",
86+
actual = e.response.bodyAsText(),
87+
message = "Check response body")
88+
}
89+
}
1390
}

gradle/build-logic/common-plugins/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,6 @@ dependencies {
146146
implementation(libs.build.npm.publish.plugin)
147147
implementation(libs.build.mokkery.plugin)
148148
implementation(libs.build.jte.plugin)
149-
testImplementation(gradleTestKit())
150149
// implementation(libs.build.includegit.plugin)
150+
testImplementation(gradleTestKit())
151151
}

gradle/build-logic/common-plugins/src/main/kotlin/tasks/BuildConfig.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ abstract class BuildConfig @Inject constructor(private val extension: BuildConfi
1919
@get:[OutputDirectory Optional]
2020
val generatedOutputDir: DirectoryProperty = extension.outputDir
2121

22+
@get:Internal internal val templateName = "BuildConfig.kte"
23+
2224
init {
2325
description = "Generate build config class"
2426
group = LifecycleBasePlugin.BUILD_TASK_NAME
@@ -64,7 +66,7 @@ abstract class BuildConfig @Inject constructor(private val extension: BuildConfi
6466
val tmplEngine =
6567
TemplateEngine.createPrecompiled(ContentType.Plain).apply { setTrimControlStructures(true) }
6668

67-
tmplEngine.render("BuildConfig.kte", params, content)
69+
tmplEngine.render(templateName, params, content)
6870
file.writeText(content.toString())
6971
}
7072
}

gradle/build-logic/common-plugins/src/main/resources/BuildConfig.kte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import gg.jte.Content
33
@import gg.jte.support.ForSupport
44
@import kotlinx.datetime.*
5+
@import java.net.InetAddress
56

67
@param className: String
78
@param pkg: String
@@ -23,6 +24,16 @@ object ${className} {
2324

2425
val buildTimeLocal = Instant.fromEpochMilliseconds(buildTimeEpochMillis).toLocalDateTime(TimeZone.currentSystemDefault())
2526

27+
val buildUser = "${System.getProperty("user.name")}"
28+
29+
val buildOS = "${System.getProperty("os.name")} ${System.getProperty("os.version")}-${System.getProperty("os.arch")}"
30+
31+
val buildHost = "${InetAddress.getLocalHost().hostName}"
32+
33+
val buildJdkVersion = "${System.getProperty("java.runtime.version")}"
34+
35+
val buildJdkVendor = "${System.getProperty("java.vendor")}"
36+
2637
const val version = "${version}"
2738

2839
@for((k,v) in gitCommit)

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ graalvm = "23.0.1"
6767
rsocket = "0.15.4"
6868
jctools = "4.0.1"
6969
compose-icons = "1.1.0"
70-
benasher44-uuid = "0.8.0"
70+
benasher44-uuid = "0.8.1"
7171
kotlinx-uuid = "0.0.20"
7272
kotlin-codepoints = "0.6.1"
7373
kotlin-logging = "5.0.0"
@@ -129,7 +129,7 @@ gmazzo-buildconfig = "3.1.0"
129129
cyclonedx-plugin = "1.7.4"
130130
modulegraph = "0.4.0"
131131
jetbrains-compose = "1.4.3"
132-
jetbrains-compose-compiler = "1.5.0"
132+
jetbrains-compose-compiler = "1.5.1"
133133
cash-molecule = "1.2.0"
134134
npm-publish-plugin = "3.4.1"
135135
exposed-plugin = "0.2.1"

0 commit comments

Comments
 (0)