Skip to content

Commit 1cb1d90

Browse files
ilgonmicdkrasnoff
authored andcommitted
Adopt #2
1 parent f2eb7d4 commit 1cb1d90

File tree

3 files changed

+69
-74
lines changed

3 files changed

+69
-74
lines changed

build.gradle.kts

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
44
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
55
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
66
import org.springframework.boot.gradle.tasks.bundling.BootJar
7-
import java.io.FileInputStream
8-
import java.util.Properties
97

108
val policy: String by System.getProperties()
119

@@ -36,8 +34,7 @@ allprojects {
3634
}
3735
}
3836

39-
40-
val kotlinComposeWasmStdlibWasmFile: Configuration by configurations.creating {
37+
val kotlinComposeWasmStdlibFile: Configuration by configurations.creating {
4138
isTransitive = false
4239
isCanBeResolved = true
4340
isCanBeConsumed = false
@@ -79,42 +76,47 @@ dependencies {
7976
}
8077
testImplementation(libs.kotlinx.coroutines.test)
8178

82-
kotlinComposeWasmStdlibWasmFile(project(":cache-maker"))
79+
kotlinComposeWasmStdlibFile(project(":cache-maker"))
8380
}
8481

85-
fun buildPropertyFile() {
86-
rootDir.resolve("src/main/resources/${propertyFile}").apply {
87-
println("Generate properties into $absolutePath")
88-
parentFile.mkdirs()
89-
writeText(generateProperties())
82+
fun Project.generateProperties(
83+
prefix: String = "",
84+
): Map<String, String> = mapOf(
85+
"kotlin.version" to kotlinVersion,
86+
"policy.file" to prefix + policy,
87+
"indexes.file" to prefix + indexes,
88+
"indexesJs.file" to prefix + indexesJs,
89+
"indexesWasm.file" to prefix + indexesWasm,
90+
"indexesComposeWasm.file" to prefix + indexesComposeWasm,
91+
"libraries.folder.jvm" to prefix + libJVM,
92+
"libraries.folder.js" to prefix + libJS,
93+
"libraries.folder.wasm" to prefix + libWasm,
94+
"libraries.folder.compose-wasm" to prefix + libComposeWasm,
95+
"libraries.folder.compose-wasm-compiler-plugins" to prefix + libComposeWasmCompilerPlugins,
96+
"libraries.folder.compiler-plugins" to prefix + compilerPluginsForJVM,
97+
"spring.mvc.pathmatch.matching-strategy" to "ant_path_matcher",
98+
"server.compression.enabled" to "true",
99+
"server.compression.mime-types" to "application/json,text/javascript,application/wasm",
100+
"springdoc.swagger-ui.path:" to "/api-docs/swagger-ui.html",
101+
"skiko.version" to libs.versions.skiko.get(),
102+
)
103+
104+
val propertiesGenerator by tasks.registering(PropertiesGenerator::class) {
105+
dependsOn(kotlinComposeWasmStdlibFile)
106+
propertiesFile.fileValue(rootDir.resolve("src/main/resources/${propertyFile}"))
107+
hashableFile.set(kotlinComposeWasmStdlibFile.singleFile)
108+
generateProperties().forEach { (name, value) ->
109+
propertiesMap.put(name, value)
90110
}
91111
}
92112

93-
fun generateProperties(prefix: String = "") = """
94-
# this file is autogenerated by build.gradle.kts
95-
kotlin.version=${kotlinVersion}
96-
policy.file=${prefix + policy}
97-
indexes.file=${prefix + indexes}
98-
indexesJs.file=${prefix + indexesJs}
99-
indexesWasm.file=${prefix + indexesWasm}
100-
indexesComposeWasm.file=${prefix + indexesComposeWasm}
101-
libraries.folder.jvm=${prefix + libJVM}
102-
libraries.folder.js=${prefix + libJS}
103-
libraries.folder.wasm=${prefix + libWasm}
104-
libraries.folder.compose-wasm=${prefix + libComposeWasm}
105-
libraries.folder.compose-wasm-compiler-plugins=${prefix + libComposeWasmCompilerPlugins}
106-
libraries.folder.compiler-plugins=${prefix + compilerPluginsForJVM}
107-
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
108-
server.compression.enabled=true
109-
server.compression.mime-types=application/json,text/javascript,application/wasm
110-
springdoc.swagger-ui.path: /api-docs/swagger-ui.html
111-
skiko.version=${libs.versions.skiko.get()}
112-
""".trimIndent()
113-
114-
val composeWasmPropertiesUpdater by tasks.registering(ComposeWasmPropertiesUpdater::class) {
115-
dependsOn(kotlinComposeWasmStdlibWasmFile)
116-
propertiesPath.set(rootDir.resolve("src/main/resources/${propertyFile}").absolutePath)
117-
hashableFile.set(kotlinComposeWasmStdlibWasmFile.singleFile)
113+
val lambdaPropertiesGenerator by tasks.registering(PropertiesGenerator::class) {
114+
dependsOn(kotlinComposeWasmStdlibFile)
115+
propertiesFile.set(layout.buildDirectory.file("tmp/propertiesGenerator/${propertyFile}"))
116+
hashableFile.set(kotlinComposeWasmStdlibFile.singleFile)
117+
generateProperties(lambdaPrefix).forEach { (name, value) ->
118+
propertiesMap.put(name, value)
119+
}
118120
}
119121

120122
tasks.withType<KotlinCompile> {
@@ -123,8 +125,7 @@ tasks.withType<KotlinCompile> {
123125
}
124126
dependsOn(":executors:jar")
125127
dependsOn(":indexation:run")
126-
dependsOn(composeWasmPropertiesUpdater)
127-
buildPropertyFile()
128+
dependsOn(propertiesGenerator)
128129
}
129130
println("Using Kotlin compiler ${libs.versions.kotlin.get()}")
130131

@@ -135,19 +136,12 @@ tasks.withType<BootJar> {
135136

136137
val buildLambda by tasks.creating(Zip::class) {
137138
val propertyFile = propertyFile
138-
val propertyFileContent = generateProperties(lambdaPrefix)
139139

140140
from(tasks.compileKotlin)
141141
from(tasks.processResources) {
142-
eachFile {
143-
if (name == propertyFile) {
144-
val properties = Properties().apply { load(FileInputStream(file)) }
145-
val composeWasmHash = properties.get("dependencies.compose.wasm")
146-
file.writeText(propertyFileContent)
147-
file.appendText("\ndependencies.compose.wasm=$composeWasmHash")
148-
}
149-
}
142+
exclude(propertyFile)
150143
}
144+
from(lambdaPropertiesGenerator)
151145
from(policy)
152146
from(indexes)
153147
from(indexesJs)
@@ -157,16 +151,16 @@ val buildLambda by tasks.creating(Zip::class) {
157151
from(libWasmFolder) { into(libWasm) }
158152
from(libComposeWasmFolder) { into(libComposeWasm) }
159153
from(libJVMFolder) { into(libJVM) }
160-
from(compilerPluginsForJVMFolder) {into(compilerPluginsForJVM)}
154+
from(compilerPluginsForJVMFolder) { into(compilerPluginsForJVM) }
161155
from(libComposeWasmCompilerPluginsFolder) { into(libComposeWasmCompilerPlugins) }
162-
dependsOn(kotlinComposeWasmStdlibWasmFile)
156+
dependsOn(kotlinComposeWasmStdlibFile)
163157
into("lib") {
164158
from(configurations.compileClasspath) { exclude("tomcat-embed-*") }
165159
}
166160
}
167161

168162
tasks.named<Copy>("processResources") {
169-
dependsOn(composeWasmPropertiesUpdater)
163+
dependsOn(propertiesGenerator)
170164
}
171165

172166
tasks.withType<Test> {

buildSrc/src/main/kotlin/PropertiesUpdater.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import org.gradle.api.DefaultTask
22
import org.gradle.api.file.RegularFileProperty
33
import org.gradle.api.provider.MapProperty
4-
import org.gradle.api.provider.Property
54
import org.gradle.api.tasks.Input
65
import org.gradle.api.tasks.InputFile
76
import org.gradle.api.tasks.OutputFile
@@ -10,10 +9,7 @@ import java.io.File
109
import java.io.FileInputStream
1110
import java.security.MessageDigest
1211

13-
abstract class ComposeWasmPropertiesUpdater : DefaultTask() {
14-
15-
@get:Input
16-
abstract val propertiesPath: Property<String>
12+
abstract class PropertiesGenerator : DefaultTask() {
1713

1814
@get:InputFile
1915
abstract val hashableFile: RegularFileProperty
@@ -22,11 +18,11 @@ abstract class ComposeWasmPropertiesUpdater : DefaultTask() {
2218
abstract val propertiesMap: MapProperty<String, String>
2319

2420
@get:OutputFile
25-
val updatedPropertiesFile: RegularFileProperty = project.objects.fileProperty().fileProvider(propertiesPath.map { File(it) })
21+
abstract val propertiesFile: RegularFileProperty
2622

2723
@TaskAction
2824
fun updateProperties() {
29-
val file = updatedPropertiesFile.get().asFile
25+
val file = propertiesFile.get().asFile
3026

3127
propertiesMap.get().let {
3228
if (it.isNotEmpty()) {

resource-server/build.gradle.kts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import org.gradle.kotlin.dsl.support.serviceOf
2-
import org.gradle.kotlin.dsl.withType
32
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
43
import java.io.FileInputStream
5-
import java.util.Properties
4+
import java.util.*
65

76
plugins {
87
alias(libs.plugins.spring.dependency.management)
@@ -21,7 +20,7 @@ val resourceDependency: Configuration by configurations.creating {
2120
isCanBeConsumed = false
2221
}
2322

24-
val kotlinComposeWasmStdlibTypeInfo: Configuration by configurations.creating {
23+
val kotlinComposeWasmStdlibFile: Configuration by configurations.creating {
2524
isTransitive = false
2625
isCanBeResolved = true
2726
isCanBeConsumed = false
@@ -61,20 +60,20 @@ dependencies {
6160

6261
resourceDependency(libs.skiko.js.wasm.runtime)
6362
kotlinComposeWasmStdlib(project(":cache-maker"))
64-
kotlinComposeWasmStdlibTypeInfo(project(":cache-maker"))
63+
kotlinComposeWasmStdlibFile(project(":cache-maker"))
6564
}
6665

67-
val composeWasmPropertiesUpdater by tasks.registering(ComposeWasmPropertiesUpdater::class) {
68-
dependsOn(kotlinComposeWasmStdlibTypeInfo)
66+
val propertiesGenerator by tasks.registering(PropertiesGenerator::class) {
67+
dependsOn(kotlinComposeWasmStdlibFile)
6968
propertiesMap.put("spring.mvc.pathmatch.matching-strategy", "ant_path_matcher")
7069
propertiesMap.put("server.port", "8081")
7170
propertiesMap.put("skiko.version", libs.versions.skiko.get())
7271

7372
val applicationPropertiesPath = projectDir.resolve("src/main/resources/application.properties")
7473

75-
propertiesPath.set(applicationPropertiesPath.normalize().absolutePath)
74+
propertiesFile.fileValue(applicationPropertiesPath)
7675

77-
val composeWasmStdlibTypeInfo: FileCollection = kotlinComposeWasmStdlibTypeInfo
76+
val composeWasmStdlibTypeInfo: FileCollection = kotlinComposeWasmStdlibFile
7877

7978
hashableFile.fileProvider(
8079
provider {
@@ -84,15 +83,15 @@ val composeWasmPropertiesUpdater by tasks.registering(ComposeWasmPropertiesUpdat
8483
}
8584

8685
tasks.withType<KotlinCompile> {
87-
dependsOn(kotlinComposeWasmStdlibTypeInfo)
88-
dependsOn(composeWasmPropertiesUpdater)
86+
dependsOn(kotlinComposeWasmStdlibFile)
87+
dependsOn(propertiesGenerator)
8988
}
9089

9190
val skikoVersion = libs.versions.skiko
9291

9392
tasks.named<Copy>("processResources") {
94-
dependsOn(kotlinComposeWasmStdlibTypeInfo)
95-
dependsOn(composeWasmPropertiesUpdater)
93+
dependsOn(kotlinComposeWasmStdlibFile)
94+
dependsOn(propertiesGenerator)
9695
val archiveOperation = project.serviceOf<ArchiveOperations>()
9796
from(resourceDependency.map {
9897
archiveOperation.zipTree(it)
@@ -101,17 +100,23 @@ tasks.named<Copy>("processResources") {
101100
rename("skiko\\.(.*)", "skiko-${skikoVersion.get()}.\$1")
102101
}
103102

104-
val propertiesFile = composeWasmPropertiesUpdater.flatMap { it.updatedPropertiesFile }
103+
val propertiesFile = propertiesGenerator.flatMap { it.propertiesFile }
105104

106105
from(kotlinComposeWasmStdlib) {
107106
into("com/compiler/server")
108-
val properties = FileInputStream(propertiesFile.get().asFile).use {
109-
Properties().apply {
110-
load(it)
107+
108+
rename { original ->
109+
val properties = FileInputStream(propertiesFile.get().asFile).use {
110+
Properties().apply {
111+
load(it)
112+
}
111113
}
112-
}
114+
val regex = Regex("stdlib_master\\.(.*)")
115+
regex.find(original)?.groupValues?.get(1)?.let { extension ->
116+
"stdlib-${properties["dependencies.compose.wasm"]}.$extension"
117+
} ?: original
113118

114-
rename("stdlib_master\\.(.*)", "stdlib-${properties["dependencies.compose.wasm"]}.\$1")
119+
}
115120
}
116121
}
117122

0 commit comments

Comments
 (0)