Provide class to getBinFile to load classes from plugins and other class loaders.

Plugin might contain file in its own class loader.

GitOrigin-RevId: 724522a01bf67cf633c911758b2457cce66cd779
This commit is contained in:
Ilya.Kazakevich
2023-10-15 21:26:01 +02:00
committed by intellij-monorepo-bot
parent 36e83656c8
commit 5a24f21b50

View File

@@ -42,7 +42,11 @@ object BinFiles {
private val logger = thisLogger()
fun getBinFile(fileName: FileName): Path = synchronized(lock) {
/**
* Load [fileName] either from [BIN_FILES_DIR_NAME] or classpath of [clazz].
* Make sure file is accessible from [clazz] class loader
*/
fun getBinFile(fileName: FileName, clazz: Class<*>): Path = synchronized(lock) {
val devFile = devFilesDir.resolve(fileName.relativePath)
if (devFile.exists()) {
logger.info("Using dev $devFile")
@@ -54,7 +58,7 @@ object BinFiles {
return@synchronized localCopyOfFile
}
val resource = javaClass.classLoader.getResource(fileName.relativePath) ?: throw IllegalArgumentException("$fileName is not in the class path")
val resource = clazz.classLoader.getResource(fileName.relativePath) ?: throw IllegalArgumentException("$fileName is not in the class path")
resource.openStream().use { input ->
localCopyOfFile.outputStream().use { output ->
input.copyTo(output)