Skip to content

Commit e05904c

Browse files
Merge pull request #303 from SpineEventEngine/migrate-to-template-string-from-base
Migrate to `TemplateString` from Spine Base
2 parents 38e7369 + 44f3657 commit e05904c

85 files changed

Lines changed: 1377 additions & 780 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ allprojects {
129129
Roaster.jdt,
130130
Time.lib,
131131
Time.javaExtensions,
132+
Time.kotlinExtensions,
132133
ToolBase.lib,
133134
ToolBase.pluginBase,
134135
Validation.javaBundle,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2026, TeamDev. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Redistribution and use in source and/or binary forms, with or without
11+
* modification, must retain the above copyright notice and the following
12+
* disclaimer.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
27+
import org.gradle.api.Project
28+
import org.gradle.api.Task
29+
import org.gradle.api.tasks.TaskProvider
30+
import org.gradle.kotlin.dsl.named
31+
import org.gradle.kotlin.dsl.register
32+
33+
/**
34+
* Registers a `patchGeneratedTemplateString` task in the project, which replaces
35+
* references to the legacy `io.spine.validation.TemplateString` class (and its
36+
* proto FQN `.spine.validation.TemplateString`) with `io.spine.string.TemplateString`
37+
* in the `generated/` sources.
38+
*
39+
* The task is wired to run after [upstreamTask] (the task that produces the sources
40+
* to be patched) and before `compileJava` and `kspKotlin`.
41+
*
42+
* @param upstreamTask the name of the task whose output should be patched
43+
* (e.g., `generateProto` or `launchSpineCompiler`).
44+
*/
45+
fun Project.patchGeneratedTemplateString(upstreamTask: String): TaskProvider<Task> {
46+
val patchTask = tasks.register("patchGeneratedTemplateString") {
47+
dependsOn(upstreamTask)
48+
49+
val generatedDir = layout.projectDirectory.dir("generated")
50+
inputs.dir(generatedDir).withPropertyName("generatedSources")
51+
outputs.dir(generatedDir).withPropertyName("patchedSources")
52+
53+
doLast {
54+
val oldClassRef = "io.spine.validation.TemplateString"
55+
val newClassRef = "io.spine.string.TemplateString"
56+
val oldProtoRef = ".spine.validation.TemplateString"
57+
val newProtoRef = ".spine.string.TemplateString"
58+
generatedDir.asFile.walkTopDown()
59+
.filter { it.isFile && (it.extension == "java" || it.extension == "kt") }
60+
.forEach { file ->
61+
val original = file.readText()
62+
if (original.contains(oldClassRef) || original.contains(oldProtoRef)) {
63+
val patched = original
64+
.replace(oldClassRef, newClassRef)
65+
.replace(oldProtoRef, newProtoRef)
66+
file.writeText(patched)
67+
}
68+
}
69+
}
70+
}
71+
72+
tasks.named("compileJava") {
73+
dependsOn(patchTask)
74+
}
75+
76+
afterEvaluate {
77+
tasks.named("kspKotlin") {
78+
dependsOn(patchTask)
79+
}
80+
}
81+
82+
return patchTask
83+
}

buildSrc/src/main/kotlin/io/spine/dependency/local/Base.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ package io.spine.dependency.local
3333
*/
3434
@Suppress("ConstPropertyName", "unused")
3535
object Base {
36-
const val version = "2.0.0-SNAPSHOT.387"
37-
const val versionForBuildScript = "2.0.0-SNAPSHOT.387"
36+
const val version = "2.0.0-SNAPSHOT.389"
37+
const val versionForBuildScript = "2.0.0-SNAPSHOT.389"
3838
const val group = Spine.group
3939
private const val prefix = "spine"
4040
const val libModule = "$prefix-base"

buildSrc/src/main/kotlin/io/spine/dependency/local/CoreJvmCompiler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ object CoreJvmCompiler {
4646
/**
4747
* The version used to in the build classpath.
4848
*/
49-
const val dogfoodingVersion = "2.0.0-SNAPSHOT.063"
49+
const val dogfoodingVersion = "2.0.0-SNAPSHOT.064"
5050

5151
/**
5252
* The version to be used for integration tests.

buildSrc/src/main/kotlin/io/spine/dependency/local/Time.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import io.spine.dependency.Dependency
4040
)
4141
object Time : Dependency() {
4242
override val group = Spine.group
43-
override val version = "2.0.0-SNAPSHOT.238"
43+
override val version = "2.0.0-SNAPSHOT.240"
4444
private const val infix = "spine-time"
4545

4646
fun lib(version: String): String = "$group:$infix:$version"

buildSrc/src/main/kotlin/io/spine/dependency/local/Validation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object Validation {
3636
/**
3737
* The version of the Validation library artifacts.
3838
*/
39-
const val version = "2.0.0-SNAPSHOT.415"
39+
const val version = "2.0.0-SNAPSHOT.419"
4040

4141
/**
4242
* The last version of Validation compatible with ProtoData.

buildSrc/src/main/kotlin/module.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ fun Module.forceConfigurations() {
170170
Base.environment,
171171
Protobuf.compiler,
172172
Time.lib,
173+
Time.javaExtensions,
174+
Time.kotlinExtensions,
173175
TestLib.lib,
174176
ToolBase.gradlePluginApi,
175177
ToolBase.jvmTools,

context/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,5 @@ afterEvaluate {
6565
val launchSpineCompiler by tasks.getting
6666
kspKotlin.dependsOn(launchSpineCompiler)
6767
}
68+
69+
patchGeneratedTemplateString(upstreamTask = "launchSpineCompiler")

context/src/main/kotlin/io/spine/tools/validation/ErrorPlaceholder.kt

Lines changed: 0 additions & 78 deletions
This file was deleted.

context/src/main/kotlin/io/spine/tools/validation/ErrorPlaceholders.kt renamed to context/src/main/kotlin/io/spine/tools/validation/Placeholders.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import io.spine.tools.compiler.ast.OneofGroup
3434
import io.spine.tools.compiler.ast.Span
3535
import io.spine.tools.compiler.ast.qualifiedName
3636
import io.spine.tools.compiler.check
37-
import io.spine.validation.ErrorPlaceholder
38-
import io.spine.validation.extractPlaceholders
37+
import io.spine.string.Placeholder
38+
import io.spine.string.Placeholder.Companion.extractPlaceholders
3939

4040
/**
4141
* Checks if this [String] contains placeholders that are not present in the given
@@ -47,7 +47,7 @@ import io.spine.validation.extractPlaceholders
4747
* @param option The name of the option with which the message template was specified.
4848
*/
4949
internal fun String.checkPlaceholders(
50-
supported: Set<ErrorPlaceholder>,
50+
supported: Set<Placeholder>,
5151
message: MessageType,
5252
file: File,
5353
option: String
@@ -69,7 +69,7 @@ internal fun String.checkPlaceholders(
6969
* @param option The name of the option with which the message template was specified.
7070
*/
7171
internal fun String.checkPlaceholders(
72-
supported: Set<ErrorPlaceholder>,
72+
supported: Set<Placeholder>,
7373
oneof: OneofGroup,
7474
file: File,
7575
option: String
@@ -91,7 +91,7 @@ internal fun String.checkPlaceholders(
9191
* @param option The name of the option with which the message template was specified.
9292
*/
9393
public fun String.checkPlaceholders(
94-
supported: Set<ErrorPlaceholder>,
94+
supported: Set<Placeholder>,
9595
field: Field,
9696
file: File,
9797
option: String
@@ -108,7 +108,7 @@ public fun String.checkPlaceholders(
108108
* set of the [supported] placeholders, and reports a compilation error if so.
109109
*/
110110
private fun String.checkPlaceholders(
111-
supported: Set<ErrorPlaceholder>,
111+
supported: Set<Placeholder>,
112112
declaration: String,
113113
span: Span,
114114
file: File,
@@ -119,7 +119,7 @@ private fun String.checkPlaceholders(
119119
Compilation.check(missing.isEmpty(), file, span) {
120120
"The $declaration specifies an error message for the `($option)` option using unsupported" +
121121
" placeholders: `$missing`. Supported placeholders are the following:" +
122-
" `${supported.map { it.value }}`."
122+
" `${supported.map { it.name }}`."
123123
}
124124
}
125125

@@ -132,13 +132,12 @@ private fun String.checkPlaceholders(
132132
*/
133133
private fun missingPlaceholders(
134134
template: String,
135-
placeholders: Set<ErrorPlaceholder>
136-
): Set<String> {
135+
placeholders: Set<Placeholder>
136+
): Set<Placeholder> {
137137
val requested = extractPlaceholders(template)
138-
val provided = placeholders.map { it.value }
139-
val missing = mutableSetOf<String>()
138+
val missing = mutableSetOf<Placeholder>()
140139
for (placeholder in requested) {
141-
if (!provided.contains(placeholder)) {
140+
if (!placeholders.contains(placeholder)) {
142141
missing.add(placeholder)
143142
}
144143
}

0 commit comments

Comments
 (0)