From a94e71349fcdc236c4468fdfdde84bf5dcd7aaa4 Mon Sep 17 00:00:00 2001 From: Florian Magin <8415354+fmagin@users.noreply.github.com> Date: Tue, 2 Mar 2021 13:34:11 +0100 Subject: [PATCH] Make embedKernel arguments nullable EmptyResolutionInfoProvider is created by an [object declaration](https://kotlinlang.org/docs/object-declarations.html#object-declarations) which fails to import in pure java code. The `embedKernel` method is intended to be called inside pure Java code that simply has the compiled kotlin kernel jars available as a dependency, but the former signature after the refactor in https://github.com/Kotlin/kotlin-jupyter/commit/782f0882ed5f9e89ad378b4a986591397027721d#diff-3c1c4b1ddbb3338fe28601f266bb3c492ac38a395dafb1c3ad4b60a8ffeedc62R85 makes this impossible. This commit makes the `resolutionInfoProvider` nullable again, which also means that existing code using the method and passing null, still works with the the signature using `ResolutionInfoProvider` --- src/main/kotlin/org/jetbrains/kotlinx/jupyter/ikotlin.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/jetbrains/kotlinx/jupyter/ikotlin.kt b/src/main/kotlin/org/jetbrains/kotlinx/jupyter/ikotlin.kt index c5af78f45..634ce09c9 100644 --- a/src/main/kotlin/org/jetbrains/kotlinx/jupyter/ikotlin.kt +++ b/src/main/kotlin/org/jetbrains/kotlinx/jupyter/ikotlin.kt @@ -80,13 +80,17 @@ fun main(vararg args: String) { /** * This function is to be run in projects which use kernel as a library, * so we don't have a big need in covering it with tests + * + * The expected use case for this function is embedding into a Java application that doesn't necessarily support extensions written in Kotlin + * The signature of this function should thus be simple, and e.g. allow resolutionInfoProvider to be null instead of having to pass EmptyResolutionInfoProvider + * because EmptyResolutionInfoProvider is a Kotlin singleton object and cannot be imported in Java code. */ @Suppress("unused") -fun embedKernel(cfgFile: File, resolutionInfoProvider: ResolutionInfoProvider = EmptyResolutionInfoProvider, scriptReceivers: List? = null) { +fun embedKernel(cfgFile: File, resolutionInfoProvider: ResolutionInfoProvider?, scriptReceivers: List? = null) { val cp = System.getProperty("java.class.path").split(File.pathSeparator).toTypedArray().map { File(it) } val config = KernelConfig.fromConfig( KernelJupyterParams.fromFile(cfgFile), - resolutionInfoProvider, + resolutionInfoProvider ?: EmptyResolutionInfoProvider, cp, null, true