square / okio

A modern I/O library for Android, Java, and Kotlin Multiplatform.
https://square.github.io/okio/
Apache License 2.0
8.81k stars 1.18k forks source link

Support FileSystem.RESOURCES on GraalVM #1293

Open jeancharles-roger opened 1 year ago

jeancharles-roger commented 1 year ago

Hi,

I've been using Okio (version 3.3.0) to manage files on a multi-platform project and it works just fine, thanks đź‘Ť.

In this project I build a cli tool using GraalVM to produce an executable. I copy a set of files on initialization to a tmp dir, it works just fine with jvm but I can't get it to work in a GraalVM executable.

val source = "/modules".toPath()
FileSystem.RESOURCES.listRecursively(source).forEach {
    if (FileSystem.RESOURCES.metadata(it).isRegularFile) {
        val stream = Common::class.java.getResourceAsStream(it.toString())
        if (stream != null) {
            val local = it.relativeTo(source)
            val target = modules.resolve(local)
            target.parent?.let { FS.createDirectories(it) }
            FS.write(target) { write(stream.readAllBytes()) }
        }
    }
}

I build the executable with this ressource inclusion file:

{
  "resources": {
    "includes": [
      {
        "pattern": "version.properties"
      },
      {
        "pattern": "modules/.*"
      }
    ]
  }
}

I believe that listing resources is not supported in a GraalVM executable but I may have used Okio in a wrong way. I haven't any indication that it is not supported. Can you tell if it is possible to list and copy resources using Okio from a GraalVM execute ?

Thanks for your help.

swankjesse commented 1 year ago

Thanks for reporting this.

Our current implementation isn’t appropriate for GraalVM and we should fix that.