Skip to content

Commit e252d45

Browse files
Jolanrensenileasile
authored andcommitted
added integrationTypeNameRules to LibrariesScanner.kt for use in Jupyter JUnit tests
1 parent bf2bd00 commit e252d45

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/main/kotlin/org/jetbrains/kotlinx/jupyter/libraries/LibrariesScanner.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import org.jetbrains.kotlinx.jupyter.api.libraries.LibraryDefinition
1616
import org.jetbrains.kotlinx.jupyter.config.errorForUser
1717
import org.jetbrains.kotlinx.jupyter.config.getLogger
1818
import org.jetbrains.kotlinx.jupyter.exceptions.ReplException
19+
import org.jetbrains.kotlinx.jupyter.util.AcceptanceRule
20+
import org.jetbrains.kotlinx.jupyter.util.accepts
1921

2022
class LibrariesScanner(val notebook: Notebook) {
2123
private val processedFQNs = mutableSetOf<TypeName>()
@@ -37,15 +39,15 @@ class LibrariesScanner(val notebook: Notebook) {
3739
}
3840
}
3941

40-
fun addLibrariesFromClassLoader(classLoader: ClassLoader, host: KotlinKernelHost) {
41-
val scanResult = scanForLibraries(classLoader, host)
42+
fun addLibrariesFromClassLoader(classLoader: ClassLoader, host: KotlinKernelHost, integrationTypeNameRules: List<AcceptanceRule<TypeName>> = listOf()) {
43+
val scanResult = scanForLibraries(classLoader, host, integrationTypeNameRules)
4244
log.debug("Scanning for libraries is done. Detected FQNs: ${Json.encodeToString(scanResult)}")
4345
val libraries = instantiateLibraries(classLoader, scanResult, notebook)
4446
log.debug("Number of detected definitions: ${libraries.size}")
4547
host.addLibraries(libraries)
4648
}
4749

48-
private fun scanForLibraries(classLoader: ClassLoader, host: KotlinKernelHost): LibrariesScanResult {
50+
private fun scanForLibraries(classLoader: ClassLoader, host: KotlinKernelHost, integrationTypeNameRules: List<AcceptanceRule<TypeName>> = listOf()): LibrariesScanResult {
4951
val results = classLoader.getResources("$KOTLIN_JUPYTER_RESOURCES_PATH/$KOTLIN_JUPYTER_LIBRARIES_FILE_NAME").toList().map { url ->
5052
val contents = url.readText()
5153
Json.decodeFromString<LibrariesScanResult>(contents)
@@ -55,8 +57,15 @@ class LibrariesScanner(val notebook: Notebook) {
5557
val producers = mutableListOf<LibrariesProducerDeclaration>()
5658

5759
for (result in results) {
58-
definitions.addAll(result.definitions)
59-
producers.addAll(result.producers)
60+
for (definition in result.definitions) {
61+
if (integrationTypeNameRules.accepts(definition.fqn) != false)
62+
definitions += definition
63+
}
64+
65+
for (producer in result.producers) {
66+
if (integrationTypeNameRules.accepts(producer.fqn) != false)
67+
producers += producer
68+
}
6069
}
6170

6271
return LibrariesScanResult(

0 commit comments

Comments
 (0)