Skip to content

Commit 72dbfb2

Browse files
Merge pull request #64 from SpineEventEngine/migrate-to-reactions
Migrate to `Reaction` API
2 parents 318bfe4 + 8529ee8 commit 72dbfb2

File tree

25 files changed

+191
-160
lines changed

25 files changed

+191
-160
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ package io.spine.dependency.local
3333
*/
3434
@Suppress("ConstPropertyName")
3535
object BaseTypes {
36-
const val version = "2.0.0-SNAPSHOT.211"
36+
const val version = "2.0.0-SNAPSHOT.212"
3737
const val group = Spine.group
3838
const val artifact = "spine-base-types"
3939
const val lib = "$group:$artifact:$version"

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ package io.spine.dependency.local
2929
/**
3030
* Dependencies on the Spine Compiler modules.
3131
*
32-
* To use a locally published ProtoData version instead of the version from a public plugin
32+
* To use a locally published Compiler version instead of the version from a public plugin
3333
* registry, set the `COMPILER_VERSION` and/or the `COMPILER_DF_VERSION` environment variables
3434
* and stop the Gradle daemons so that Gradle observes the env change:
3535
* ```
@@ -67,22 +67,22 @@ object Compiler {
6767
const val module = "io.spine.tools:compiler"
6868

6969
/**
70-
* The version of ProtoData dependencies.
70+
* The version of the Compiler dependencies.
7171
*/
7272
val version: String
73-
private const val fallbackVersion = "2.0.0-SNAPSHOT.030"
73+
private const val fallbackVersion = "2.0.0-SNAPSHOT.034"
7474

7575
/**
76-
* The distinct version of ProtoData used by other build tools.
76+
* The distinct version of the Compiler used by other build tools.
7777
*
78-
* When ProtoData is used both for building the project and as a part of the Project's
79-
* transitional dependencies, this is the version used to build the project itself.
78+
* When the Compiler is used both for building the project and as a part of the Project's
79+
* transitive dependencies, this is the version used to build the project itself.
8080
*/
8181
val dogfoodingVersion: String
8282
private const val fallbackDfVersion = "2.0.0-SNAPSHOT.030"
8383

8484
/**
85-
* The artifact for the ProtoData Gradle plugin.
85+
* The artifact for the Compiler Gradle plugin.
8686
*/
8787
val pluginLib: String
8888

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ package io.spine.dependency.local
3131
typealias CoreJava = CoreJvm
3232

3333
/**
34-
* Dependencies on `core-java` modules.
34+
* Dependencies on `core-jvm` modules.
3535
*
36-
* See [`SpineEventEngine/core-java`](https://github.com/SpineEventEngine/core-jvm/).
36+
* See [`SpineEventEngine/core-jvm`](https://github.com/SpineEventEngine/core-jvm/).
3737
*/
3838
@Suppress("ConstPropertyName", "unused")
3939
object CoreJvm {
4040
const val group = Spine.group
41-
const val version = "2.0.0-SNAPSHOT.346"
41+
const val version = "2.0.0-SNAPSHOT.356"
4242

4343
const val coreArtifact = "spine-core"
4444
const val clientArtifact = "spine-client"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ object CoreJvmCompiler {
4646
/**
4747
* The version used to in the build classpath.
4848
*/
49-
const val dogfoodingVersion = "2.0.0-SNAPSHOT.030"
49+
const val dogfoodingVersion = "2.0.0-SNAPSHOT.035"
5050

5151
/**
5252
* The version to be used for integration tests.
5353
*/
54-
const val version = "2.0.0-SNAPSHOT.030"
54+
const val version = "2.0.0-SNAPSHOT.035"
5555

5656
/**
5757
* The ID of the Gradle plugin.

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.354"
39+
const val version = "2.0.0-SNAPSHOT.360"
4040

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

buildSrc/src/main/kotlin/io/spine/gradle/git/Repository.kt

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626

2727
package io.spine.gradle.git
2828

29+
import com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly
2930
import io.spine.gradle.Cli
3031
import io.spine.gradle.fs.LazyTempPath
32+
import java.util.concurrent.TimeUnit.MILLISECONDS
3133
import org.gradle.api.logging.Logger
3234

3335
/**
@@ -133,8 +135,10 @@ class Repository private constructor(
133135
* Performs a pull with rebase before pushing to ensure the local branch is up-to-date.
134136
*/
135137
fun push() {
136-
repoExecute("git", "pull", "--rebase")
137-
repoExecute("git", "push")
138+
withRetries(description = "Pushing to $sshUrl, branch = '$currentBranch'") {
139+
repoExecute("git", "pull", "--rebase")
140+
repoExecute("git", "push")
141+
}
138142
}
139143

140144
override fun close() {
@@ -174,3 +178,44 @@ class Repository private constructor(
174178
}
175179
}
176180
}
181+
182+
/**
183+
* Executes a given operation with retries using exponential backoff strategy.
184+
*
185+
* If the operation fails, it will be retried up to the specified number of times
186+
* with increasing delays between attempts.
187+
* The delay increases exponentially but is capped at the specified maximum value.
188+
*
189+
* If all retries fail, the exception from the final attempt will be thrown to the caller.
190+
*
191+
* @param T the type of value returned by the operation
192+
* @param times the maximum number of attempts to execute the operation (default: 3)
193+
* @param initialDelay the delay before the first retry in milliseconds (default: 100ms)
194+
* @param maxDelay the maximum delay between retries in milliseconds (default: 2000ms)
195+
* @param factor the multiplier used to increase delay after each failure (default: 2.0)
196+
* @param description a description of the operation for error reporting (default: empty string)
197+
* @param block the operation to execute
198+
* @return the result of the successful operation execution
199+
*/
200+
@Suppress("TooGenericExceptionCaught", "LongParameterList")
201+
private fun <T> withRetries(
202+
times: Int = 3,
203+
initialDelay: Long = 100, // ms
204+
maxDelay: Long = 2000, // ms
205+
factor: Double = 2.0,
206+
description: String = "",
207+
block: () -> T
208+
): T {
209+
var currentDelay = initialDelay
210+
repeat(times - 1) {
211+
try {
212+
return block()
213+
} catch (e: Exception) {
214+
System.err.println("'$description' failed. " +
215+
"Message: '${e.message}'. Retrying in $currentDelay ms.")
216+
}
217+
sleepUninterruptibly(currentDelay, MILLISECONDS)
218+
currentDelay = (currentDelay * factor).toLong().coerceAtMost(maxDelay)
219+
}
220+
return block()
221+
}

buildSrc/src/main/kotlin/io/spine/gradle/report/license/LicenseReporter.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,18 @@ object LicenseReporter {
151151
sourceProjects: Iterable<Project>,
152152
rootProject: Project
153153
) {
154-
val paths = sourceProjects.map {
155-
val buildDir = it.layout.buildDirectory.asFile.get()
156-
"$buildDir/${Paths.relativePath}/${Paths.outputFilename}"
157-
}
158-
println("Merging the license reports from the all projects.")
154+
val paths = sourceProjects
155+
.map {
156+
val buildDir = it.layout.buildDirectory.asFile.get()
157+
"$buildDir/${Paths.relativePath}/${Paths.outputFilename}"
158+
}.filter {
159+
val exists = File(it).exists()
160+
if (!exists) {
161+
rootProject.logger.debug("License report file not found: $it")
162+
}
163+
exists
164+
}
165+
println("Merging the license reports from all projects.")
159166
val mergedContent = paths.joinToString("\n\n\n") { (File(it)).readText() }
160167
val output = File("${rootProject.rootDir}/${Paths.outputFilename}")
161168
output.writeText(mergedContent)

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import io.spine.dependency.local.ToolBase
4848
import io.spine.dependency.local.Validation
4949
import io.spine.dependency.test.JUnit
5050
import io.spine.gradle.checkstyle.CheckStyleConfig
51+
import io.spine.gradle.github.pages.updateGitHubPages
5152
import io.spine.gradle.javac.configureErrorProne
5253
import io.spine.gradle.javac.configureJavac
5354
import io.spine.gradle.javadoc.JavadocConfig
@@ -94,6 +95,7 @@ project.run {
9495
setupSourceSets(generatedResources)
9596

9697
configureTaskDependencies()
98+
setupDocPublishing()
9799
}
98100

99101
typealias Module = Project
@@ -278,3 +280,16 @@ fun Module.setupSourceSets(generatedResources: String) {
278280
resources.srcDir(generatedResources)
279281
}
280282
}
283+
284+
/**
285+
* Configures documentation publishing for this subproject.
286+
*/
287+
fun Module.setupDocPublishing() {
288+
updateGitHubPages {
289+
rootFolder.set(rootDir)
290+
}
291+
292+
tasks.named("publish") {
293+
dependsOn("${project.path}:updateGitHubPages")
294+
}
295+
}

comparable/src/main/kotlin/io/spine/tools/core/jvm/comparable/ComparableMessageDiscovery.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ package io.spine.tools.core.jvm.comparable
2828

2929
import io.spine.core.External
3030
import io.spine.option.CompareByOption
31-
import io.spine.tools.compiler.ast.event.TypeDiscovered
32-
import io.spine.tools.compiler.ast.find
33-
import io.spine.tools.compiler.plugin.Policy
34-
import io.spine.tools.compiler.settings.loadSettings
3531
import io.spine.server.event.NoReaction
3632
import io.spine.server.event.React
3733
import io.spine.server.tuple.EitherOf2
3834
import io.spine.server.tuple.EitherOf2.withA
3935
import io.spine.server.tuple.EitherOf2.withB
36+
import io.spine.tools.compiler.ast.event.TypeDiscovered
37+
import io.spine.tools.compiler.ast.find
38+
import io.spine.tools.compiler.plugin.Reaction
39+
import io.spine.tools.compiler.settings.loadSettings
4040
import io.spine.tools.core.jvm.comparable.event.ComparableMessageDiscovered
4141
import io.spine.tools.core.jvm.comparable.event.comparableMessageDiscovered
4242
import io.spine.tools.core.jvm.settings.Comparables
4343

4444
/**
4545
* Discovers comparable messages.
4646
*/
47-
internal class ComparableMessageDiscovery : Policy<TypeDiscovered>(), ComparableComponent {
47+
internal class ComparableMessageDiscovery : Reaction<TypeDiscovered>(), ComparableComponent {
4848

4949
private val settings: Comparables by lazy { loadSettings() }
5050

comparable/src/main/kotlin/io/spine/tools/core/jvm/comparable/ComparablePlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import io.spine.tools.compiler.plugin.Plugin
3636
* [ComparableSettings][io.spine.tools.core.jvm.gradle.settings.ComparableSettings].
3737
*/
3838
public class ComparablePlugin : Plugin(
39-
policies = setOf(ComparableMessageDiscovery()),
39+
reactions = setOf(ComparableMessageDiscovery()),
4040
views = setOf(ComparableMessageView::class.java),
4141
renderers = listOf(ComparableActionsRenderer())
4242
) {

0 commit comments

Comments
 (0)