Fix compiled scripts saving tests:

The tests were broken some time ago by applying script isolation, so
it was necessary to add base libraries into the classpath.
Also refactored some classpath building utilities.
This commit is contained in:
Ilya Chernikov
2019-07-09 15:35:38 +02:00
parent 9c004c3a52
commit c9a4328feb
4 changed files with 43 additions and 14 deletions
@@ -62,12 +62,12 @@ fun ScriptCompilationConfiguration.withUpdatedClasspath(classpath: Collection<Fi
}
}
fun ScriptCompilationConfiguration.Builder.updateClasspath(classpath: Collection<File>) = updateClasspathImpl(classpath)
fun ScriptCompilationConfiguration.Builder.updateClasspath(classpath: Collection<File>?) = updateClasspathImpl(classpath)
fun JvmScriptCompilationConfigurationBuilder.updateClasspath(classpath: Collection<File>) = updateClasspathImpl(classpath)
fun JvmScriptCompilationConfigurationBuilder.updateClasspath(classpath: Collection<File>?) = updateClasspathImpl(classpath)
private fun PropertiesCollection.Builder.updateClasspathImpl(classpath: Collection<File>) {
val newClasspath = classpath.filterNewClasspath(this[ScriptCompilationConfiguration.dependencies])
private fun PropertiesCollection.Builder.updateClasspathImpl(classpath: Collection<File>?) {
val newClasspath = classpath?.filterNewClasspath(this[ScriptCompilationConfiguration.dependencies])
?: return
ScriptCompilationConfiguration.dependencies.append(JvmDependency(newClasspath))
@@ -179,12 +179,14 @@ fun classpathFromClasspathProperty(): List<File>? =
fun classpathFromClass(classLoader: ClassLoader, klass: KClass<out Any>): List<File>? =
classpathFromFQN(classLoader, klass.qualifiedName!!)
fun classpathFromClass(klass: KClass<out Any>): List<File>? =
classpathFromClass(klass.java.classLoader, klass)
inline fun <reified T: Any> classpathFromClass(): List<File>? = classpathFromClass(T::class)
fun classpathFromFQN(classLoader: ClassLoader, fqn: String): List<File>? {
val clp = "${fqn.replace('.', '/')}.class"
val url = classLoader.getResource(clp)
return url?.toURI()?.path?.removeSuffix(clp)?.let {
listOf(File(it))
}
return classLoader.rawClassPathFromKeyResourcePath(clp).filter { it.isValidClasspathFile() }.toList().takeIf { it.isNotEmpty() }
}
fun File.matchMaybeVersionedFile(baseName: String) =
@@ -408,4 +410,11 @@ object KotlinJars {
stdlibOrNull,
scriptRuntimeOrNull
).filterNotNull()
val kotlinScriptStandardJarsWithReflect
get() = listOf(
stdlibOrNull,
scriptRuntimeOrNull,
reflectOrNull
).filterNotNull()
}