From d14ef9de36dc84de1a5f4af2a5554692d4f2e393 Mon Sep 17 00:00:00 2001 From: LamGC Date: Sat, 30 Apr 2022 21:12:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DMaven=20=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E4=BB=93=E5=BA=93=E6=96=87=E4=BB=B6=E5=A4=B9=E6=9C=AA?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E7=9A=84=E9=97=AE=E9=A2=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当本地仓库文件夹未初始化时, 将导致文件写入失败, 已修复该问题. --- scalabot-app/src/main/kotlin/AppMain.kt | 27 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/scalabot-app/src/main/kotlin/AppMain.kt b/scalabot-app/src/main/kotlin/AppMain.kt index 4f290a0..36d5d42 100644 --- a/scalabot-app/src/main/kotlin/AppMain.kt +++ b/scalabot-app/src/main/kotlin/AppMain.kt @@ -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,16 +55,24 @@ internal class Launcher : AutoCloseable { private val botApi = TelegramBotsApi(DefaultBotSession::class.java) private val botSessionMap = mutableMapOf() - private val mavenLocalRepository = - if (Const.config.mavenLocalRepository != null && Const.config.mavenLocalRepository.isNotEmpty()) { - val repoPath = AppPaths.DATA_ROOT.file.toPath() - .resolve(Const.config.mavenLocalRepository) - .toRealPath() - .toFile() - LocalRepository(repoPath) - } else { - LocalRepository("${System.getProperty("user.home")}/.m2/repository") + 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() + repoPath + } else { + File("${System.getProperty("user.home")}/.m2/repository") + } + if (!localPath.exists()) { + localPath.mkdirs() } + return LocalRepository(localPath) + } @Synchronized fun launch(): Boolean {