diff --git a/dependencies.md b/dependencies.md index b208f29b..bb3384e0 100644 --- a/dependencies.md +++ b/dependencies.md @@ -1,6 +1,6 @@ -# Dependencies of `io.spine.tools:intellij-platform:2.0.0-SNAPSHOT.240` +# Dependencies of `io.spine.tools:intellij-platform:2.0.0-SNAPSHOT.241` ## Runtime 1. **Group** : be.cyberelf.nanoxml. **Name** : nanoxml. **Version** : 2.2.3. @@ -493,12 +493,12 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Sun Dec 15 16:11:25 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 **Tue Jan 14 15:55:52 CET 2025** 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). -# Dependencies of `io.spine.tools:intellij-platform-java:2.0.0-SNAPSHOT.240` +# Dependencies of `io.spine.tools:intellij-platform-java:2.0.0-SNAPSHOT.241` ## Runtime 1. **Group** : be.cyberelf.nanoxml. **Name** : nanoxml. **Version** : 2.2.3. @@ -1752,12 +1752,12 @@ This report was generated on **Sun Dec 15 16:11:25 WET 2024** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Sun Dec 15 16:11:25 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 **Tue Jan 14 15:55:52 CET 2025** 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). -# Dependencies of `io.spine.tools:spine-plugin-base:2.0.0-SNAPSHOT.240` +# Dependencies of `io.spine.tools:spine-plugin-base:2.0.0-SNAPSHOT.241` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -2505,12 +2505,12 @@ This report was generated on **Sun Dec 15 16:11:25 WET 2024** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Sun Dec 15 16:11:26 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 **Tue Jan 14 15:55:53 CET 2025** 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). -# Dependencies of `io.spine.tools:spine-plugin-testlib:2.0.0-SNAPSHOT.240` +# Dependencies of `io.spine.tools:spine-plugin-testlib:2.0.0-SNAPSHOT.241` ## Runtime 1. **Group** : com.google.auto.value. **Name** : auto-value-annotations. **Version** : 1.10.2. @@ -3373,12 +3373,12 @@ This report was generated on **Sun Dec 15 16:11:26 WET 2024** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Sun Dec 15 16:11:26 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 **Tue Jan 14 15:55:53 CET 2025** 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). -# Dependencies of `io.spine.tools:spine-psi:2.0.0-SNAPSHOT.240` +# Dependencies of `io.spine.tools:spine-psi:2.0.0-SNAPSHOT.241` ## Runtime 1. **Group** : be.cyberelf.nanoxml. **Name** : nanoxml. **Version** : 2.2.3. @@ -4380,12 +4380,12 @@ This report was generated on **Sun Dec 15 16:11:26 WET 2024** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Sun Dec 15 16:11:26 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 **Tue Jan 14 15:55:53 CET 2025** 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). -# Dependencies of `io.spine.tools:spine-psi-java:2.0.0-SNAPSHOT.240` +# Dependencies of `io.spine.tools:spine-psi-java:2.0.0-SNAPSHOT.241` ## Runtime 1. **Group** : be.cyberelf.nanoxml. **Name** : nanoxml. **Version** : 2.2.3. @@ -6065,12 +6065,12 @@ This report was generated on **Sun Dec 15 16:11:26 WET 2024** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Sun Dec 15 16:11:27 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 **Tue Jan 14 15:55:54 CET 2025** 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). -# Dependencies of `io.spine.tools:spine-tool-base:2.0.0-SNAPSHOT.240` +# Dependencies of `io.spine.tools:spine-tool-base:2.0.0-SNAPSHOT.241` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -6867,4 +6867,4 @@ This report was generated on **Sun Dec 15 16:11:27 WET 2024** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Sun Dec 15 16:11:27 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). \ No newline at end of file +This report was generated on **Tue Jan 14 15:55:54 CET 2025** 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). \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6d1d3a3f..d2044558 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject. --> io.spine.tools tool-base -2.0.0-SNAPSHOT.240 +2.0.0-SNAPSHOT.241 2015 diff --git a/psi-java/src/main/kotlin/io/spine/tools/psi/java/PsiCommands.kt b/psi-java/src/main/kotlin/io/spine/tools/psi/java/PsiCommands.kt index b5d4720f..0005d1bd 100644 --- a/psi-java/src/main/kotlin/io/spine/tools/psi/java/PsiCommands.kt +++ b/psi-java/src/main/kotlin/io/spine/tools/psi/java/PsiCommands.kt @@ -29,12 +29,41 @@ package io.spine.tools.psi.java import com.intellij.openapi.command.CommandProcessor import io.spine.tools.psi.java.Environment.commandProcessor import io.spine.tools.psi.java.Environment.project +import kotlin.system.exitProcess /** - * Executes the given [Runnable] as a PSI modification - * [command][CommandProcessor.executeCommand]. + * Executes the given [runnable] as a PSI modification [command][CommandProcessor.executeCommand], + * ensuring any errors thrown by the [runnable] are handled using the provided [errorHandler]. + * + * By default, the `CoreCommandProcessor` used for PSI command processing suppresses + * any [Throwable] thrown by the command, making it difficult for PSI users to detect + * and handle errors. + * + * To address this, the given [runnable] is wrapped in a try-catch block. + * Any thrown errors or exceptions are passed to the provided [errorHandler]. + * + * If no custom [errorHandler] is provided, the default behavior is to print the stack + * trace to [System.err] and terminate the process with the exit code `1`. + * + * @param runnable The [Runnable] to execute as a PSI modification. + * @param errorHandler A lambda to handle any [Throwable] thrown by the [runnable]. + * Defaults to printing the stack trace and terminating the process with the exit code `1`. */ +@JvmOverloads @JvmName("execute") -public fun execute(runnable: Runnable) { - commandProcessor.executeCommand(project, runnable, null, null) +@Suppress("TooGenericExceptionCaught") // We need everything, including `java.lang.Error`. +public fun execute(errorHandler: (Throwable) -> Unit = ::printAndTerminate, runnable: Runnable) { + val withHandledErrors = Runnable { + try { + runnable.run() + } catch (t: Throwable) { + errorHandler(t) + } + } + commandProcessor.executeCommand(project, withHandledErrors, null, null) +} + +private fun printAndTerminate(t: Throwable) { + t.printStackTrace() + exitProcess(1) } diff --git a/version.gradle.kts b/version.gradle.kts index 39eb3c79..3e8094c8 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -24,4 +24,4 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -val versionToPublish: String by extra("2.0.0-SNAPSHOT.240") +val versionToPublish: String by extra("2.0.0-SNAPSHOT.241")