Browse Source
Describe proposed changes and the issue being fixed Fixes [CMP-8134](https://youtrack.jetbrains.com/issue/CMP-8134/Switch-the-ClassLoader-used-by-ResourceReader) ## Testing - [x] Add Test to **desktopTest** SourceSet - (Optional) This should be tested by QA ## Release Notes ### Features - Resources - Added `JvmResourceReader` API and made `LocalResourceReader` public to allow providing a custom classloader for desktop targetpull/5348/head
10 changed files with 153 additions and 76 deletions
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
@file:OptIn(ExperimentalTestApi::class) |
||||
|
||||
package org.jetbrains.compose.resources |
||||
|
||||
import androidx.compose.ui.test.ExperimentalTestApi |
||||
import kotlinx.coroutines.test.runTest |
||||
import java.net.URLClassLoader |
||||
import kotlin.io.path.Path |
||||
import kotlin.io.path.isDirectory |
||||
import kotlin.test.Test |
||||
import kotlin.test.assertEquals |
||||
|
||||
|
||||
class CustomClassloaderTest { |
||||
|
||||
val RESOURCES_PATH |
||||
get() = System.getenv("RESOURCES_PATH") |
||||
?.let { Path(it) } |
||||
?.takeIf { it.isDirectory() } |
||||
?: error("RESOURCES_PATH environment variable is not set or is not a directory") |
||||
|
||||
@Test |
||||
fun testCustomClassloader() = runTest { |
||||
val actualResourceText = |
||||
CustomClassloaderTest::class |
||||
.java |
||||
.classLoader |
||||
.getResourceAsStream("hello.txt") |
||||
?.readAllBytes() |
||||
?.toString(Charsets.UTF_8) |
||||
|
||||
val classloader = URLClassLoader(arrayOf(RESOURCES_PATH.toUri().toURL()), null) |
||||
val reader = JvmResourceReader(classloader) |
||||
assertEquals( |
||||
expected = actualResourceText, |
||||
actual = reader.read("hello.txt").toString(Charsets.UTF_8) |
||||
) |
||||
} |
||||
} |
||||
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
Hello World! |
||||
Loading…
Reference in new issue