mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-04-30 06:37:29 +00:00
refactor(launch): 将 AppPaths 从 Launcher 解耦.
解耦后有助于后续改进, 以及单元测试的编写.
This commit is contained in:
parent
c94e0476b5
commit
30a2cb34d5
@ -61,7 +61,10 @@ internal fun startMetricsServer(config: MetricsConfig = Const.config.metrics): H
|
|||||||
return httpServer
|
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 {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@ -75,9 +78,7 @@ internal class Launcher(private val config: AppConfig = Const.config) : AutoClos
|
|||||||
private fun getMavenLocalRepository(): LocalRepository {
|
private fun getMavenLocalRepository(): LocalRepository {
|
||||||
val localPath =
|
val localPath =
|
||||||
if (config.mavenLocalRepository != null && config.mavenLocalRepository!!.isNotEmpty()) {
|
if (config.mavenLocalRepository != null && config.mavenLocalRepository!!.isNotEmpty()) {
|
||||||
val repoPath = AppPaths.DATA_ROOT.file.toPath()
|
val repoPath = configFile.toPath().resolve(config.mavenLocalRepository!!).apply {
|
||||||
.resolve(config.mavenLocalRepository!!)
|
|
||||||
.apply {
|
|
||||||
if (!exists()) {
|
if (!exists()) {
|
||||||
if (!parent.isWritable() || !parent.isReadable()) {
|
if (!parent.isWritable() || !parent.isReadable()) {
|
||||||
throw IOException("Unable to read and write the directory where Maven repository is located.")
|
throw IOException("Unable to read and write the directory where Maven repository is located.")
|
||||||
|
Loading…
Reference in New Issue
Block a user