Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Compilation.Error extend Mistake #306

Merged
merged 10 commits into from
Dec 15, 2024
1 change: 1 addition & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dependencies {
testFixturesImplementation(it)
}

testImplementation(Logging.testLib)
testImplementation(project(":test-env"))

// For using `CodeGenerationContext` in stubs.
Expand Down
14 changes: 10 additions & 4 deletions api/src/main/kotlin/io/spine/protodata/Compilation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

package io.spine.protodata

import io.spine.base.Mistake
import io.spine.environment.Tests
import java.io.File
import kotlin.system.exitProcess
Expand Down Expand Up @@ -58,7 +59,12 @@ public object Compilation {
public const val ERROR_EXIT_CODE: Int = -1

/**
* Prints the error diagnostics to [System.err] and exits the process with [ERROR_EXIT_CODE].
* Prints the error diagnostics to [System.err] and terminates the compilation.
*
* The termination of the compilation in the production mode is done by
* exiting the process with [ERROR_EXIT_CODE].
*
* If the code is run [under tests][Tests] the method throws [Compilation.Error].
*
* @param file The file in which the error occurred.
* @param line The one-based number of the line with the error.
Expand All @@ -69,10 +75,10 @@ public object Compilation {
@Suppress("TooGenericExceptionThrown") // False positive from detekt.
public fun error(file: File, line: Int, column: Int, message: String): Nothing {
val output = errorMessage(file, line, column, message)
System.err.println(output)
if (underTests) {
throw Error(output)
} else {
System.err.println(output)
exitProcess(ERROR_EXIT_CODE)
}
}
Expand All @@ -88,7 +94,7 @@ public object Compilation {
* Prints the warning diagnostics to [System.out].
*
* The method returns the string printed to the console so that it could be also
* put into logging output.
* put into logging output by the calling code.
*
* @param file The file which causes the warning.
* @param line The one-based number of the line with the questionable code.
Expand All @@ -105,7 +111,7 @@ public object Compilation {
/**
* The exception thrown by [Compilation.error] when the testing mode is on.
*/
public class Error(message: String) : kotlin.Error(message) {
public class Error(message: String) : Mistake(message) {
public companion object {
private const val serialVersionUID: Long = 0L
}
Expand Down
20 changes: 20 additions & 0 deletions api/src/test/kotlin/io/spine/protodata/CompilationSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
package io.spine.protodata

import io.kotest.matchers.string.shouldContain
import io.spine.logging.testing.tapConsole
import java.io.File
import java.nio.file.Paths
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
Expand All @@ -50,4 +52,22 @@ internal class CompilationSpec {
it shouldContain errorMessage
}
}

@Test
fun `print the error message to the system error stream`() {
val file = Paths.get("nested/dir/file.proto").toFile()
val lineNumber = 10
val columnNumber = 5
val errorMessage = "Testing console output."
val consoleOutput = tapConsole {
assertThrows<Compilation.Error> {
Compilation.error(file, lineNumber, columnNumber, errorMessage)
}
}
consoleOutput.let {
it shouldContain file.path
it shouldContain "$lineNumber:$columnNumber"
it shouldContain errorMessage
}
}
}
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/io/spine/dependency/local/Base.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ package io.spine.dependency.local
*/
@Suppress("ConstPropertyName")
object Base {
const val version = "2.0.0-SNAPSHOT.231"
const val versionForBuildScript = "2.0.0-SNAPSHOT.231"
const val version = "2.0.0-SNAPSHOT.232"
const val versionForBuildScript = "2.0.0-SNAPSHOT.232"
const val group = Spine.group
const val artifact = "spine-base"
const val lib = "$group:$artifact:$version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ package io.spine.dependency.local
@Suppress("ConstPropertyName", "unused")
object CoreJava {
const val group = Spine.group
const val version = "2.0.0-SNAPSHOT.190"
const val version = "2.0.0-SNAPSHOT.191"

const val coreArtifact = "spine-core"
const val clientArtifact = "spine-client"
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/io/spine/dependency/local/Logging.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ object Logging {
const val grpcContext = "$group:spine-logging-grpc-context:$version"
const val smokeTest = "$group:spine-logging-smoke-test:$version"

const val testLib = "${Spine.toolsGroup}:spine-logging-testlib:$version"

// Transitive dependencies.
// Make `public` and use them to force a version in a particular repository, if needed.
internal const val julBackend = "$group:spine-logging-jul-backend:$version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ package io.spine.dependency.local
@Suppress("ConstPropertyName", "unused")
object ToolBase {
const val group = Spine.toolsGroup
const val version = "2.0.0-SNAPSHOT.234"
const val version = "2.0.0-SNAPSHOT.240"

const val lib = "$group:spine-tool-base:$version"
const val pluginBase = "$group:spine-plugin-base:$version"
Expand Down
30 changes: 19 additions & 11 deletions dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,14 @@
* **License:** [LGPL, version 2.1](http://www.gnu.org/licenses/licenses.html)

1. **Group** : net.ltgt.gradle. **Name** : gradle-errorprone-plugin. **Version** : 3.1.0.**No license information found**
1. **Group** : org.apache.logging.log4j. **Name** : log4j-api. **Version** : 2.20.0.
* **Project URL:** [https://www.apache.org/](https://www.apache.org/)
* **License:** [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt)

1. **Group** : org.apache.logging.log4j. **Name** : log4j-core. **Version** : 2.20.0.
* **Project URL:** [https://www.apache.org/](https://www.apache.org/)
* **License:** [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt)

1. **Group** : org.apiguardian. **Name** : apiguardian-api. **Version** : 1.1.2.
* **Project URL:** [https://github.com/apiguardian-team/apiguardian](https://github.com/apiguardian-team/apiguardian)
* **License:** [The Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)
Expand Down Expand Up @@ -1017,7 +1025,7 @@

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 19:40:34 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 17:56:05 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -1858,7 +1866,7 @@ This report was generated on **Fri Dec 13 19:40:34 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 19:40:35 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 17:56:06 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -2884,7 +2892,7 @@ This report was generated on **Fri Dec 13 19:40:35 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 19:40:35 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 17:56:06 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -3933,7 +3941,7 @@ This report was generated on **Fri Dec 13 19:40:35 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 19:40:35 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 17:56:06 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -4941,7 +4949,7 @@ This report was generated on **Fri Dec 13 19:40:35 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 19:40:36 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 17:56:07 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -5953,7 +5961,7 @@ This report was generated on **Fri Dec 13 19:40:36 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 19:40:36 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 17:56:07 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -7142,7 +7150,7 @@ This report was generated on **Fri Dec 13 19:40:36 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 19:40:36 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 17:56:08 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -8168,7 +8176,7 @@ This report was generated on **Fri Dec 13 19:40:36 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 19:40:37 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 17:56:08 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -9006,7 +9014,7 @@ This report was generated on **Fri Dec 13 19:40:37 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 19:40:37 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 17:56:08 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -10047,7 +10055,7 @@ This report was generated on **Fri Dec 13 19:40:37 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 19:40:37 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 17:56:08 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -11171,4 +11179,4 @@ This report was generated on **Fri Dec 13 19:40:37 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 19:40:37 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 17:56:09 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
20 changes: 13 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine</groupId>
<artifactId>spine-base</artifactId>
<version>2.0.0-SNAPSHOT.231</version>
<version>2.0.0-SNAPSHOT.232</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -110,7 +110,7 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine</groupId>
<artifactId>spine-server</artifactId>
<version>2.0.0-SNAPSHOT.190</version>
<version>2.0.0-SNAPSHOT.191</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -128,13 +128,13 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-psi-java</artifactId>
<version>2.0.0-SNAPSHOT.234</version>
<version>2.0.0-SNAPSHOT.240</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-tool-base</artifactId>
<version>2.0.0-SNAPSHOT.234</version>
<version>2.0.0-SNAPSHOT.240</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -185,16 +185,22 @@ all modules and does not describe the project structure per-subproject.
<version>1.1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-logging-testlib</artifactId>
<version>2.0.0-SNAPSHOT.242</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-plugin-testlib</artifactId>
<version>2.0.0-SNAPSHOT.234</version>
<version>2.0.0-SNAPSHOT.240</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-testutil-server</artifactId>
<version>2.0.0-SNAPSHOT.190</version>
<version>2.0.0-SNAPSHOT.191</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -293,7 +299,7 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-plugin-base</artifactId>
<version>2.0.0-SNAPSHOT.234</version>
<version>2.0.0-SNAPSHOT.240</version>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
Expand Down
Loading