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