mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-04-29 22:27:31 +00:00
fix(extension): 修复 Maven 仓库扩展搜索器无法从第三方仓库获取扩展的问题.
由于在加载仓库配置时, 未设置仓库 Id, 导致 Aether 将仓库排除, 进而导致无法通过第三方仓库获取插件. 改动后, 将在未配置仓库 Id 的情况下, 为其生成一个 Id 名称.
This commit is contained in:
parent
a0afde52ac
commit
0a5313e94a
@ -13,12 +13,14 @@ import org.eclipse.aether.artifact.Artifact
|
||||
import org.eclipse.aether.repository.Authentication
|
||||
import org.eclipse.aether.repository.Proxy
|
||||
import org.eclipse.aether.repository.RemoteRepository
|
||||
import org.eclipse.aether.repository.RepositoryPolicy
|
||||
import org.telegram.telegrambots.bots.DefaultBotOptions
|
||||
import org.telegram.telegrambots.meta.ApiConstants
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
private val log = KotlinLogging.logger { }
|
||||
@ -100,6 +102,7 @@ internal data class MetricsConfig(
|
||||
* @property layout 仓库布局版本, Maven 2 及以上使用 `default`, Maven 1 使用 `legacy`.
|
||||
*/
|
||||
internal data class MavenRepositoryConfig(
|
||||
val id: String? = null,
|
||||
val url: URL,
|
||||
val proxy: Proxy? = Proxy("http", "127.0.0.1", 1080),
|
||||
val layout: String = "default",
|
||||
@ -108,12 +111,29 @@ internal data class MavenRepositoryConfig(
|
||||
) {
|
||||
|
||||
fun toRemoteRepository(proxyConfig: ProxyConfig): RemoteRepository {
|
||||
val builder = RemoteRepository.Builder(null, checkRepositoryLayout(layout), url.toString())
|
||||
val builder =
|
||||
RemoteRepository.Builder(id ?: createDefaultRepositoryId(), checkRepositoryLayout(layout), url.toString())
|
||||
if (proxy != null) {
|
||||
builder.setProxy(proxy)
|
||||
} else if (proxyConfig.type == DefaultBotOptions.ProxyType.HTTP) {
|
||||
builder.setProxy(proxyConfig.toAetherProxy())
|
||||
}
|
||||
|
||||
builder.setReleasePolicy(
|
||||
RepositoryPolicy(
|
||||
true,
|
||||
RepositoryPolicy.UPDATE_POLICY_NEVER,
|
||||
RepositoryPolicy.CHECKSUM_POLICY_FAIL
|
||||
)
|
||||
)
|
||||
builder.setSnapshotPolicy(
|
||||
RepositoryPolicy(
|
||||
true,
|
||||
RepositoryPolicy.UPDATE_POLICY_ALWAYS,
|
||||
RepositoryPolicy.CHECKSUM_POLICY_WARN
|
||||
)
|
||||
)
|
||||
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
@ -125,6 +145,13 @@ internal data class MavenRepositoryConfig(
|
||||
}
|
||||
return type
|
||||
}
|
||||
|
||||
private val repoNumber = AtomicInteger(1)
|
||||
|
||||
fun createDefaultRepositoryId(): String {
|
||||
return "Repository-${repoNumber.getAndIncrement()}"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,7 +207,8 @@ internal enum class AppPaths(
|
||||
AppConfig(
|
||||
mavenRepositories = listOf(
|
||||
MavenRepositoryConfig(
|
||||
URL(MavenRepositoryExtensionFinder.MAVEN_CENTRAL_URL)
|
||||
id = "central",
|
||||
url = URL(MavenRepositoryExtensionFinder.MAVEN_CENTRAL_URL)
|
||||
)
|
||||
)
|
||||
), it
|
||||
|
@ -257,9 +257,21 @@ internal class MavenRepositoryExtensionFinder(
|
||||
}
|
||||
|
||||
override fun findByArtifact(extensionArtifact: Artifact, extensionsPath: File): Set<FoundExtensionPackage> {
|
||||
log.debug {
|
||||
StringBuilder().apply {
|
||||
append("构件 $extensionArtifact 将在以下仓库拉取: \n")
|
||||
remoteRepositories.forEach {
|
||||
append("\t- ${it}\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
val extensionArtifactResult = repositorySystem.resolveArtifact(
|
||||
repoSystemSession,
|
||||
ArtifactRequest(extensionArtifact, remoteRepositories, null)
|
||||
ArtifactRequest(
|
||||
extensionArtifact,
|
||||
repositorySystem.newResolutionRepositories(repoSystemSession, remoteRepositories),
|
||||
null
|
||||
)
|
||||
)
|
||||
val extResolvedArtifact = extensionArtifactResult.artifact
|
||||
if (!extensionArtifactResult.isResolved) {
|
||||
|
@ -155,7 +155,7 @@ internal object MavenRepositoryConfigSerializer
|
||||
)
|
||||
}
|
||||
is JsonPrimitive -> {
|
||||
MavenRepositoryConfig(URL(json.asString))
|
||||
MavenRepositoryConfig(url = URL(json.asString))
|
||||
}
|
||||
else -> {
|
||||
throw JsonParseException("Unsupported Maven warehouse configuration type.")
|
||||
|
Loading…
Reference in New Issue
Block a user