@@ -4,18 +4,29 @@ import java.io.File
44import java.net.URL
55import java.nio.file.Files
66import java.nio.file.StandardCopyOption
7+ import java.util.*
78
89object JarUtils {
910 private const val UNKNOWN_MODIFICATION_TIME = 0L
1011
1112 fun extractJarFileFromResources (jarFileName : String , jarResourcePath : String , targetDirectoryName : String ): File {
12- val targetDirectory =
13- Files .createDirectories(utBotTempDirectory.toFile().resolve(targetDirectoryName).toPath()).toFile()
14- return targetDirectory.resolve(jarFileName).also { jarFile ->
15- val resource = this ::class .java.classLoader.getResource(jarResourcePath)
16- ? : error(" Unable to find \" $jarResourcePath \" in resources, make sure it's on the classpath" )
17- updateJarIfRequired(jarFile, resource)
13+ val resource = this ::class .java.classLoader.getResource(jarResourcePath)
14+ ? : error(" Unable to find \" $jarResourcePath \" in resources, make sure it's on the classpath" )
15+
16+ val targetDirectory = utBotTempDirectory.toFile().resolve(targetDirectoryName).toPath()
17+ fun extractToSubDir (subDir : String ) =
18+ Files .createDirectories(targetDirectory.resolve(subDir)).toFile().resolve(jarFileName).also { jarFile ->
19+ updateJarIfRequired(jarFile, resource)
20+ }
21+
22+ // We attempt to always extract jars to same locations, to avoid eating up drive space with
23+ // every UtBot launch, but we may fail to do so if multiple processes are running in parallel.
24+ repeat(10 ) { i ->
25+ runCatching {
26+ return extractToSubDir(i.toString())
27+ }
1828 }
29+ return extractToSubDir(UUID .randomUUID().toString())
1930 }
2031
2132 private fun updateJarIfRequired (jarFile : File , resource : URL ) {
0 commit comments