@@ -62,9 +62,11 @@ fun classpathFromClassloader(currentClassLoader: ClassLoader, unpackJarCollectio
62
62
setWritable(true , true )
63
63
setExecutable(true , true )
64
64
65
- Runtime .getRuntime().addShutdownHook(Thread {
66
- deleteRecursively()
67
- })
65
+ Runtime .getRuntime().addShutdownHook(
66
+ Thread {
67
+ deleteRecursively()
68
+ }
69
+ )
68
70
}
69
71
}
70
72
return allRelatedClassLoaders(currentClassLoader).flatMap { classLoader ->
@@ -198,7 +200,7 @@ fun classpathFromClass(classLoader: ClassLoader, klass: KClass<out Any>): List<F
198
200
fun classpathFromClass (klass : KClass <out Any >): List <File >? =
199
201
classpathFromClass(klass.java.classLoader, klass)
200
202
201
- inline fun <reified T : Any > classpathFromClass (): List <File >? = classpathFromClass(T ::class )
203
+ inline fun <reified T : Any > classpathFromClass (): List <File >? = classpathFromClass(T ::class )
202
204
203
205
fun classpathFromFQN (classLoader : ClassLoader , fqn : String ): List <File >? {
204
206
val clp = " ${fqn.replace(' .' , ' /' )} .class"
@@ -207,8 +209,8 @@ fun classpathFromFQN(classLoader: ClassLoader, fqn: String): List<File>? {
207
209
208
210
fun File.matchMaybeVersionedFile (baseName : String ) =
209
211
name == baseName ||
210
- name == baseName.removeSuffix(" .jar" ) || // for classes dirs
211
- Regex (Regex .escape(baseName.removeSuffix(" .jar" )) + " (-\\ d.*)?\\ .jar" ).matches(name)
212
+ name == baseName.removeSuffix(" .jar" ) || // for classes dirs
213
+ Regex (Regex .escape(baseName.removeSuffix(" .jar" )) + " (-\\ d.*)?\\ .jar" ).matches(name)
212
214
213
215
fun File.hasParentNamed (baseName : String ): Boolean =
214
216
nameWithoutExtension == baseName || parentFile?.hasParentNamed(baseName) ? : false
@@ -310,7 +312,6 @@ fun scriptCompilationClasspathFromContextOrNull(
310
312
? : classpathFromClasspathProperty()?.takeAndFilter()
311
313
}
312
314
313
-
314
315
fun scriptCompilationClasspathFromContext (
315
316
vararg keyNames : String ,
316
317
classLoader : ClassLoader = Thread .currentThread().contextClassLoader,
@@ -363,19 +364,21 @@ object KotlinJars {
363
364
val kotlinBaseJars = kotlinCompilerJars + kotlinLibsJars + kotlinScriptingJars
364
365
365
366
val classpath = explicitCompilerClasspath
366
- // search classpath from context classloader and `java.class.path` property
367
- ? : (classpathFromFQN(Thread .currentThread().contextClassLoader, " org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" )
368
- ? : classpathFromClassloader(Thread .currentThread().contextClassLoader)?.takeIf { it.isNotEmpty() }
369
- ? : classpathFromClasspathProperty()
370
- )?.filter { f -> kotlinBaseJars.any { f.matchMaybeVersionedFile(it) } }?.takeIf { it.isNotEmpty() }
367
+ // search classpath from context classloader and `java.class.path` property
368
+ ? : (
369
+ classpathFromFQN(Thread .currentThread().contextClassLoader, " org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" )
370
+ ? : classpathFromClassloader(Thread .currentThread().contextClassLoader)?.takeIf { it.isNotEmpty() }
371
+ ? : classpathFromClasspathProperty()
372
+ )?.filter { f -> kotlinBaseJars.any { f.matchMaybeVersionedFile(it) } }?.takeIf { it.isNotEmpty() }
371
373
// if autodetected, additionally check for presence of the compiler jars
372
- if (classpath == null || (explicitCompilerClasspath == null && classpath.none { f ->
374
+ if (classpath == null || (
375
+ explicitCompilerClasspath == null && classpath.none { f ->
373
376
kotlinCompilerJars.any {
374
- f.matchMaybeVersionedFile(
375
- it
376
- )
377
+ f.matchMaybeVersionedFile(it)
377
378
}
378
- })) {
379
+ }
380
+ )
381
+ ) {
379
382
throw FileNotFoundException (" Cannot find kotlin compiler jar, set kotlin.compiler.classpath property to proper location" )
380
383
}
381
384
return classpath
@@ -422,5 +425,4 @@ object KotlinJars {
422
425
" kotlin.reflect.full.KClasses" // using a class that is a part of the kotlin-reflect.jar
423
426
)
424
427
}
425
-
426
428
}
0 commit comments