Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DevScyu committed Oct 28, 2024
1 parent 33e9b48 commit d8422f9
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import kotlinx.io.asSource
import kotlinx.io.buffered
import kotlinx.io.files.Path
import java.io.File
import java.io.InputStream
import java.nio.file.FileSystems
import java.util.jar.JarFile
import kotlin.io.path.*
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.isRegularFile
import kotlin.io.path.pathString
import kotlin.io.path.walk
import kotlin.reflect.KClass

object PrefabsDSLExtensions {
Expand Down Expand Up @@ -60,20 +63,24 @@ object PrefabsDSLExtensions {
while (entries.hasMoreElements()) {
val entry = entries.nextElement()
if (entry.name.startsWith(directory) && !entry.isDirectory) {
yield(JarResource(
classLoader,
path = entry.name.substringAfter(directory).removePrefix("/"),
resource = entry.name
))
yield(
JarResource(
classLoader,
path = entry.name.substringAfter(directory)
.removePrefix(FileSystems.getDefault().separator),
resource = entry.name
)
)
}
}
} else if (protocol == "file") {
val directoryPath = File(classLoader.getResource(directory)?.toURI() ?: return@sequence).toPath()
yieldAll(directoryPath.walk().filter { it.isRegularFile() }.map {
JarResource(
classLoader,
path = it.toString().substringAfter(directoryPath.toString()).removePrefix("/"),
resource = it.toString()
path = it.toString().substringAfter(directoryPath.toString())
.removePrefix(FileSystems.getDefault().separator),
resource = directory + it.toString().substringAfter(directoryPath.toString())
)
})
}
Expand Down Expand Up @@ -101,7 +108,7 @@ object PrefabsDSLExtensions {
val path: String,
val resource: String
) {
val nameWithoutExt = path.substringAfterLast("/").substringBeforeLast(".")
val nameWithoutExt = path.substringAfterLast(FileSystems.getDefault().separator).substringBeforeLast(".")
val ext = path.substringAfterLast(".")
val stream = classLoader.getResourceAsStream(resource)!!
}
Expand Down

0 comments on commit d8422f9

Please sign in to comment.