From 30a2cb34d595d899b0b0dba9cc107c2a4514020c Mon Sep 17 00:00:00 2001 From: LamGC Date: Mon, 7 Nov 2022 11:16:41 +0800 Subject: [PATCH] =?UTF-8?q?refactor(launch):=20=E5=B0=86=20AppPaths=20?= =?UTF-8?q?=E4=BB=8E=20Launcher=20=E8=A7=A3=E8=80=A6.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解耦后有助于后续改进, 以及单元测试的编写. --- scalabot-app/src/main/kotlin/AppMain.kt | 41 +++++++++++++------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/scalabot-app/src/main/kotlin/AppMain.kt b/scalabot-app/src/main/kotlin/AppMain.kt index e216ea0..2ed97ea 100644 --- a/scalabot-app/src/main/kotlin/AppMain.kt +++ b/scalabot-app/src/main/kotlin/AppMain.kt @@ -61,7 +61,10 @@ internal fun startMetricsServer(config: MetricsConfig = Const.config.metrics): H return httpServer } -internal class Launcher(private val config: AppConfig = Const.config) : AutoCloseable { +internal class Launcher( + private val config: AppConfig = Const.config, + private val configFile: File = AppPaths.CONFIG_APPLICATION.file, +) : AutoCloseable { companion object { @JvmStatic @@ -75,27 +78,25 @@ internal class Launcher(private val config: AppConfig = Const.config) : AutoClos private fun getMavenLocalRepository(): LocalRepository { val localPath = if (config.mavenLocalRepository != null && config.mavenLocalRepository!!.isNotEmpty()) { - val repoPath = AppPaths.DATA_ROOT.file.toPath() - .resolve(config.mavenLocalRepository!!) - .apply { - if (!exists()) { - if (!parent.isWritable() || !parent.isReadable()) { - throw IOException("Unable to read and write the directory where Maven repository is located.") - } - if (System.getProperty("os.name").lowercase().startsWith("windows")) { - createDirectories() - } else { - val fileAttributes = setOf( - PosixFilePermission.OWNER_READ, - PosixFilePermission.OWNER_WRITE, - PosixFilePermission.GROUP_READ, - PosixFilePermission.GROUP_WRITE, - PosixFilePermission.OTHERS_READ, - ) - createDirectories(PosixFilePermissions.asFileAttribute(fileAttributes)) - } + val repoPath = configFile.toPath().resolve(config.mavenLocalRepository!!).apply { + if (!exists()) { + if (!parent.isWritable() || !parent.isReadable()) { + throw IOException("Unable to read and write the directory where Maven repository is located.") + } + if (System.getProperty("os.name").lowercase().startsWith("windows")) { + createDirectories() + } else { + val fileAttributes = setOf( + PosixFilePermission.OWNER_READ, + PosixFilePermission.OWNER_WRITE, + PosixFilePermission.GROUP_READ, + PosixFilePermission.GROUP_WRITE, + PosixFilePermission.OTHERS_READ, + ) + createDirectories(PosixFilePermissions.asFileAttribute(fileAttributes)) } } + } .toRealPath() .toFile() repoPath