Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions dataframe-jupyter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ repositories {
dependencies {
api(projects.dataframe)

// logger, need it for apache poi
implementation(libs.log4j.core)
implementation(libs.log4j.api)

testImplementation(libs.junit)
testImplementation(libs.serialization.json)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ import org.jetbrains.kotlinx.jupyter.api.KotlinKernelHost
import org.jetbrains.kotlinx.jupyter.api.Notebook
import org.jetbrains.kotlinx.jupyter.api.VariableName
import org.jetbrains.kotlinx.jupyter.api.declare
import org.jetbrains.kotlinx.jupyter.api.dependencies.DependencyDescription
import org.jetbrains.kotlinx.jupyter.api.dependencies.ResolutionResult
import org.jetbrains.kotlinx.jupyter.api.libraries.ColorScheme
import org.jetbrains.kotlinx.jupyter.api.libraries.FieldHandlerFactory
import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration
import org.jetbrains.kotlinx.jupyter.api.libraries.resources
import org.jetbrains.kotlinx.jupyter.util.ModifiableParentsClassLoader
import java.net.URLClassLoader
import kotlin.reflect.KClass
import kotlin.reflect.KProperty
import kotlin.reflect.KType
Expand Down Expand Up @@ -200,6 +204,9 @@ internal class Integration(private val notebook: Notebook, private val options:
declare("dataFrameConfig" to config)
}

// Needed to suppress ERROR Log4j API could not find a logging provider in 2025.2.4
loadLog4jIntoNotebookClasspath(notebook)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does calling this function in 2025.3+ cause any issues? Or could it cause issues in the future?

As it's only meant for 2025.2-. Can we somehow check which version the notebook is running and only call it if it's necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does calling this function in 2025.3+ cause any issues? Or could it cause issues in the future?

No, StatusLogger is suppressed by notebooks there. I don't think this issue will reappear

Can we somehow check which version the notebook is running and only call it if it's necessary?

We have KotlinNotebookPluginUtils.IdeBuildNumber. I'll try


resources {
if (!config.display.isolatedOutputs) {
js("DataFrame") {
Expand Down Expand Up @@ -349,6 +356,28 @@ internal class Integration(private val notebook: Notebook, private val options:
}
}

// https://github.com/Kotlin/kotlin-notebook-integrations/blob/master/integrations/database/database-api/src/main/kotlin/org/jetbrains/kotlinx/jupyter/database/internal/drivers/ExternalDependencyDriverLoader.kt
internal fun loadLog4jIntoNotebookClasspath(notebook: Notebook) {
val customizableClassLoader = notebook.intermediateClassLoader as? ModifiableParentsClassLoader ?: return

val resolver = notebook.dependencyManager.resolver

val resolutionResult = resolver.resolve(
listOf(
DependencyDescription("org.apache.logging.log4j:log4j-core:2.24.3"),
DependencyDescription("org.apache.logging.log4j:log4j-api:2.24.3"),
),
)

val resolvedJars = when (resolutionResult) {
is ResolutionResult.Success -> resolutionResult.binaryClasspath
is ResolutionResult.Failure -> return
}

val urlClassLoader = URLClassLoader(resolvedJars.map { it.toURI().toURL() }.toTypedArray())
customizableClassLoader.addParent(urlClassLoader)
}

public fun KotlinKernelHost.useSchemas(schemaClasses: Iterable<KClass<*>>) {
newDataSchemas.addAll(schemaClasses)
}
Expand Down