Use NIO Files for creating temp files: scripting, daemon, main-kts
This commit is contained in:
@@ -4,7 +4,9 @@ plugins {
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
val JDK_16: String by project
|
||||
jvmTarget = "1.6"
|
||||
javaHome = JDK_16
|
||||
|
||||
dependencies {
|
||||
compile(project(":kotlin-script-runtime"))
|
||||
@@ -22,6 +24,10 @@ tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>> {
|
||||
kotlinOptions.freeCompilerArgs += "-Xallow-kotlin-package"
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
executable = "$JDK_16/bin/java"
|
||||
}
|
||||
|
||||
publish()
|
||||
|
||||
runtimeJar()
|
||||
|
||||
+17
-4
@@ -59,9 +59,18 @@ class ClasspathExtractionException(message: String) : Exception(message)
|
||||
fun classpathFromClassloader(currentClassLoader: ClassLoader, unpackJarCollections: Boolean = false): List<File>? {
|
||||
val processedJars = hashSetOf<File>()
|
||||
val unpackJarCollectionsDir by lazy {
|
||||
createTempDir("unpackedJarCollections").canonicalFile.also {
|
||||
File.createTempFile("unpackedJarCollections", null).canonicalFile.apply {
|
||||
delete()
|
||||
mkdir()
|
||||
setReadable(false, false)
|
||||
setWritable(false, false)
|
||||
setExecutable(false, false)
|
||||
setReadable(true, true)
|
||||
setWritable(true, true)
|
||||
setExecutable(true, true)
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(Thread {
|
||||
it.deleteRecursively()
|
||||
deleteRecursively()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -144,8 +153,12 @@ fun ClassLoader.classPathFromTypicalResourceUrls(): Sequence<File> =
|
||||
.distinct()
|
||||
.filter { it.isValidClasspathFile() }
|
||||
|
||||
private fun File.unpackJarCollection(rootTempDir: File?): Sequence<File> {
|
||||
val targetDir = createTempDir(nameWithoutExtension, directory = rootTempDir)
|
||||
private fun File.unpackJarCollection(rootTempDir: File): Sequence<File> {
|
||||
val targetDir = File.createTempFile(nameWithoutExtension, null, rootTempDir).apply {
|
||||
delete()
|
||||
mkdir()
|
||||
}
|
||||
|
||||
return try {
|
||||
ArrayList<File>().apply {
|
||||
JarInputStream(FileInputStream(this@unpackJarCollection)).use { jarInputStream ->
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.apache.ivy.plugins.resolver.IBiblioResolver
|
||||
import org.apache.ivy.util.DefaultMessageLogger
|
||||
import org.apache.ivy.util.Message
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import kotlin.script.experimental.api.*
|
||||
import kotlin.script.experimental.dependencies.ExternalDependenciesResolver
|
||||
import kotlin.script.experimental.dependencies.RepositoryCoordinates
|
||||
@@ -134,7 +135,7 @@ class IvyResolver : ExternalDependenciesResolver {
|
||||
// val report = ivy.resolve(moduleDescriptor, resolveOptions)
|
||||
|
||||
//creates an ivy configuration file
|
||||
val ivyFile = createTempFile("ivy", ".xml").apply { deleteOnExit() }
|
||||
val ivyFile = Files.createTempFile("ivy", ".xml").toFile().apply { deleteOnExit() }
|
||||
XmlModuleDescriptorWriter.write(moduleDescriptor, ivyFile)
|
||||
val report = ivy.resolve(ivyFile.toURI().toURL(), resolveOptions)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user