mirror of
				https://github.com/LamGC/ScalaBot.git
				synced 2025-10-31 16:46:54 +00:00 
			
		
		
		
	refactor(launch): 将 AppPaths 从 Launcher 解耦.
解耦后有助于后续改进, 以及单元测试的编写.
This commit is contained in:
		| @ -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,27 +78,25 @@ 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!!) |                     if (!exists()) { | ||||||
|                     .apply { |                         if (!parent.isWritable() || !parent.isReadable()) { | ||||||
|                         if (!exists()) { |                             throw IOException("Unable to read and write the directory where Maven repository is located.") | ||||||
|                             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() | ||||||
|                             if (System.getProperty("os.name").lowercase().startsWith("windows")) { |                         } else { | ||||||
|                                 createDirectories() |                             val fileAttributes = setOf( | ||||||
|                             } else { |                                 PosixFilePermission.OWNER_READ, | ||||||
|                                 val fileAttributes = setOf( |                                 PosixFilePermission.OWNER_WRITE, | ||||||
|                                     PosixFilePermission.OWNER_READ, |                                 PosixFilePermission.GROUP_READ, | ||||||
|                                     PosixFilePermission.OWNER_WRITE, |                                 PosixFilePermission.GROUP_WRITE, | ||||||
|                                     PosixFilePermission.GROUP_READ, |                                 PosixFilePermission.OTHERS_READ, | ||||||
|                                     PosixFilePermission.GROUP_WRITE, |                             ) | ||||||
|                                     PosixFilePermission.OTHERS_READ, |                             createDirectories(PosixFilePermissions.asFileAttribute(fileAttributes)) | ||||||
|                                 ) |  | ||||||
|                                 createDirectories(PosixFilePermissions.asFileAttribute(fileAttributes)) |  | ||||||
|                             } |  | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|  |                 } | ||||||
|                     .toRealPath() |                     .toRealPath() | ||||||
|                     .toFile() |                     .toFile() | ||||||
|                 repoPath |                 repoPath | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user