@@ -4,18 +4,29 @@ import java.io.File
4
4
import java.net.URL
5
5
import java.nio.file.Files
6
6
import java.nio.file.StandardCopyOption
7
+ import java.util.*
7
8
8
9
object JarUtils {
9
10
private const val UNKNOWN_MODIFICATION_TIME = 0L
10
11
11
12
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
+ }
18
28
}
29
+ return extractToSubDir(UUID .randomUUID().toString())
19
30
}
20
31
21
32
private fun updateJarIfRequired (jarFile : File , resource : URL ) {
0 commit comments