fix: 修复Maven 本地仓库文件夹未初始化的问题.

当本地仓库文件夹未初始化时, 将导致文件写入失败, 已修复该问题.
This commit is contained in:
LamGC 2022-04-30 21:12:36 +08:00
parent 3e51327ed7
commit d14ef9de36
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D

View File

@ -9,6 +9,7 @@ import org.telegram.telegrambots.bots.DefaultBotOptions
import org.telegram.telegrambots.meta.TelegramBotsApi
import org.telegram.telegrambots.meta.generics.BotSession
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession
import java.io.File
import kotlin.system.exitProcess
private val log = KotlinLogging.logger { }
@ -54,15 +55,23 @@ internal class Launcher : AutoCloseable {
private val botApi = TelegramBotsApi(DefaultBotSession::class.java)
private val botSessionMap = mutableMapOf<ScalaBot, BotSession>()
private val mavenLocalRepository =
private val mavenLocalRepository = getMavenLocalRepository()
private fun getMavenLocalRepository(): LocalRepository {
val localPath =
if (Const.config.mavenLocalRepository != null && Const.config.mavenLocalRepository.isNotEmpty()) {
val repoPath = AppPaths.DATA_ROOT.file.toPath()
.resolve(Const.config.mavenLocalRepository)
.toRealPath()
.toFile()
LocalRepository(repoPath)
repoPath
} else {
LocalRepository("${System.getProperty("user.home")}/.m2/repository")
File("${System.getProperty("user.home")}/.m2/repository")
}
if (!localPath.exists()) {
localPath.mkdirs()
}
return LocalRepository(localPath)
}
@Synchronized