1
1
@file:Suppress(" JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE" )
2
2
package org.usvm.instrumentation.util
3
- import jdk.internal.loader.URLClassPath
4
- import jdk.internal.loader.Resource as InternalResource
5
3
6
4
import java.io.File
7
- import java.io.InputStream
8
5
import java.net.URL
9
- import java.security.AccessController
6
+ import java.net.URLClassLoader
10
7
import java.security.CodeSigner
11
8
12
- class URLClassPathLoader (classPath : List <File >) {
9
+ class URLClassPathLoader (private val classPath : List <File >) {
13
10
14
11
interface Resource {
15
12
fun getName (): String
16
13
fun getURL (): URL
17
14
fun getCodeSourceURL (): URL
18
- fun getInputStream (): InputStream
19
- fun getContentLength (): Int
20
15
fun getBytes (): ByteArray
21
16
fun getCodeSigners (): Array <CodeSigner >?
22
17
}
23
18
24
- private class InternalResourceWrapper (val resource : InternalResource ): Resource {
25
- override fun getName (): String = resource.name
26
- override fun getURL (): URL = resource.url
27
- override fun getCodeSourceURL (): URL = resource.codeSourceURL
28
- override fun getInputStream (): InputStream = resource.inputStream
29
- override fun getContentLength (): Int = resource.contentLength
30
- override fun getBytes (): ByteArray = resource.bytes
31
- override fun getCodeSigners (): Array <CodeSigner >? = resource.codeSigners
32
- }
33
-
34
- private val urlClassPath = URLClassPath (classPath.map { it.toURI().toURL() }.toTypedArray(), AccessController .getContext())
19
+ private val urlClassLoader = URLClassLoader (classPath.map { it.toURI().toURL() }.toTypedArray())
35
20
36
- fun getResource (name : String ): Resource = InternalResourceWrapper (urlClassPath.getResource(name, false ))
21
+ fun getResource (name : String ): Resource {
22
+ val resourceUrl = urlClassLoader.getResource(name) ? : error(" Resource $name not found on classpath $classPath " )
23
+ return object : Resource {
24
+ override fun getName (): String = name
25
+ override fun getURL (): URL = resourceUrl
26
+ // TODO usvm-sbft-merge: may be incorrect, especially for non-ASCII URLs
27
+ override fun getCodeSourceURL (): URL = resourceUrl
28
+ override fun getBytes (): ByteArray = resourceUrl.readBytes()
29
+ // TODO usvm-sbft-merge: figure out the way to get code signers
30
+ override fun getCodeSigners (): Array <CodeSigner >? = null
31
+ }
32
+ }
37
33
38
34
}
0 commit comments