mirror of
https://github.com/HighCapable/SweetDependency.git
synced 2025-09-05 10:15:44 +08:00
feat: add dependencies autowire debug info
This commit is contained in:
@@ -253,7 +253,19 @@ internal object DependencyManager {
|
|||||||
forEachIndexed { index, entry ->
|
forEachIndexed { index, entry ->
|
||||||
val currentVersionFilterExclusionList = versionFilterExclusionList.depends(currentVersion)
|
val currentVersionFilterExclusionList = versionFilterExclusionList.depends(currentVersion)
|
||||||
val availableVersions = mutableListOf<DependencyVersion>()
|
val availableVersions = mutableListOf<DependencyVersion>()
|
||||||
poms.add(MavenParser.acquire(dependencyName, entry, currentVersion))
|
poms.add(MavenParser.acquire(dependencyName, entry, currentVersion).also {
|
||||||
|
if (!SweetDependencyConfigs.configs.isDebug) return@also
|
||||||
|
val isNotFound = it.versions.isEmpty()
|
||||||
|
logDoneOrWarn("$positionTagName > OBTAIN (${index + 1}/$size) ${dependencyName.description}", isNotFound)
|
||||||
|
logDoneOrWarn(
|
||||||
|
"""
|
||||||
|
- Repository (${entry.nodeName}): ${it.url}
|
||||||
|
- Last Updated: ${it.lastUpdated}
|
||||||
|
- Versions: ${it.versions}
|
||||||
|
- Adopted Versions: ${currentVersionFilterExclusionList.filter(it.versions)}
|
||||||
|
""".trimIndent(), isNotFound, noTag = true
|
||||||
|
)
|
||||||
|
})
|
||||||
if (index == lastIndex) poms.noEmpty()
|
if (index == lastIndex) poms.noEmpty()
|
||||||
?.sortedByDescending { it.lastUpdated }
|
?.sortedByDescending { it.lastUpdated }
|
||||||
?.let { if (it.all { e -> e.lastUpdated <= 0L }) it.sortedByDescending { e -> e.versions.size } else it }
|
?.let { if (it.all { e -> e.lastUpdated <= 0L }) it.sortedByDescending { e -> e.versions.size } else it }
|
||||||
@@ -333,4 +345,13 @@ internal object DependencyManager {
|
|||||||
}
|
}
|
||||||
else -> SLog.info("$positionTagName > UP-TO-DATE ${dependencyName.description} version $currentVersion", SLog.DONE)
|
else -> SLog.info("$positionTagName > UP-TO-DATE ${dependencyName.description} version $currentVersion", SLog.DONE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印完成或警告 Log
|
||||||
|
* @param msg 消息内容
|
||||||
|
* @param isWarn 是否为警告模式 - 默认否
|
||||||
|
* @param noTag 无标签 - 默认否
|
||||||
|
*/
|
||||||
|
private fun logDoneOrWarn(msg: String, isWarn: Boolean = false, noTag: Boolean = false) =
|
||||||
|
if (isWarn) SLog.warn(msg, noTag = noTag) else SLog.info(msg, SLog.DONE, noTag = noTag)
|
||||||
}
|
}
|
@@ -57,26 +57,32 @@ internal object MavenParser {
|
|||||||
val isIncludeScope = repo.isIncludeScope(dependencyName.type == DependencyName.Type.PLUGIN)
|
val isIncludeScope = repo.isIncludeScope(dependencyName.type == DependencyName.Type.PLUGIN)
|
||||||
/** 离线模式下不会自动装配、更新在线依赖 */
|
/** 离线模式下不会自动装配、更新在线依赖 */
|
||||||
if (isIncludeScope && GradleHelper.isOfflineMode) return MavenMetadata()
|
if (isIncludeScope && GradleHelper.isOfflineMode) return MavenMetadata()
|
||||||
|
var currentUrl: String
|
||||||
return when {
|
return when {
|
||||||
repo.url.isNotBlank() -> "$headerUrlOrPath$METADATA_FILE_NAME".executeUrlBody(repo.credentials.username, repo.credentials.password)
|
repo.url.isNotBlank() -> "$headerUrlOrPath$METADATA_FILE_NAME"
|
||||||
repo.path.isNotBlank() -> "$headerUrlOrPath$METADATA_LOCAL_FILE_NAME".executeFileBody()
|
.apply { currentUrl = this }
|
||||||
|
.executeUrlBody(repo.credentials.username, repo.credentials.password)
|
||||||
|
repo.path.isNotBlank() -> "$headerUrlOrPath$METADATA_LOCAL_FILE_NAME"
|
||||||
|
.apply { currentUrl = this }
|
||||||
|
.executeFileBody()
|
||||||
else -> SError.make("Could not resolve this repository \"${repo.nodeName}\"")
|
else -> SError.make("Could not resolve this repository \"${repo.nodeName}\"")
|
||||||
}.trim().toMetadata(currentVersion)
|
}.trim().toMetadata(currentUrl, currentVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析 [METADATA_FILE_NAME]、[METADATA_LOCAL_FILE_NAME] 内容到 [MavenMetadata] 实体
|
* 解析 [METADATA_FILE_NAME]、[METADATA_LOCAL_FILE_NAME] 内容到 [MavenMetadata] 实体
|
||||||
|
* @param url 当前依赖获取 URL
|
||||||
* @param currentVersion 当前依赖版本
|
* @param currentVersion 当前依赖版本
|
||||||
* @return [MavenMetadata]
|
* @return [MavenMetadata]
|
||||||
*/
|
*/
|
||||||
private fun String.toMetadata(currentVersion: DependencyVersion) = runCatching {
|
private fun String.toMetadata(url: String, currentVersion: DependencyVersion) = runCatching {
|
||||||
if (!(contains("<metadata ") || contains("<metadata>")) || !endsWith("</metadata>")) return@runCatching MavenMetadata()
|
if (!(contains("<metadata ") || contains("<metadata>")) || !endsWith("</metadata>")) return@runCatching MavenMetadata(url)
|
||||||
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(InputSource(StringReader(this))).let { document ->
|
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(InputSource(StringReader(this))).let { document ->
|
||||||
val lastUpdated = document.getElementsByTagName("lastUpdated").item(0)?.textContent?.toLongOrNull() ?: 0L
|
val lastUpdated = document.getElementsByTagName("lastUpdated").item(0)?.textContent?.toLongOrNull() ?: 0L
|
||||||
val versionNodeList = document.getElementsByTagName("version")
|
val versionNodeList = document.getElementsByTagName("version")
|
||||||
val versions = mutableListOf<DependencyVersion>()
|
val versions = mutableListOf<DependencyVersion>()
|
||||||
for (i in 0..versionNodeList.length) versionNodeList.item(i)?.textContent?.also { versions.add(currentVersion.clone(it)) }
|
for (i in 0..versionNodeList.length) versionNodeList.item(i)?.textContent?.also { versions.add(currentVersion.clone(it)) }
|
||||||
MavenMetadata(versions.noEmpty()?.reversed()?.toMutableList() ?: mutableListOf(), lastUpdated)
|
MavenMetadata(url, versions.noEmpty()?.reversed()?.toMutableList() ?: mutableListOf(), lastUpdated)
|
||||||
}
|
}
|
||||||
}.getOrNull() ?: MavenMetadata()
|
}.getOrNull() ?: MavenMetadata(url)
|
||||||
}
|
}
|
@@ -25,10 +25,12 @@ import com.highcapable.sweetdependency.gradle.entity.DependencyVersion
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Maven Metadata 实体
|
* Maven Metadata 实体
|
||||||
|
* @param url 依赖获取 URL
|
||||||
* @param versions 版本数组
|
* @param versions 版本数组
|
||||||
* @param lastUpdated 最后更新时间戳
|
* @param lastUpdated 最后更新时间戳
|
||||||
*/
|
*/
|
||||||
internal data class MavenMetadata(
|
internal data class MavenMetadata(
|
||||||
|
internal var url: String = "",
|
||||||
internal var versions: MutableList<DependencyVersion> = mutableListOf(),
|
internal var versions: MutableList<DependencyVersion> = mutableListOf(),
|
||||||
internal var lastUpdated: Long = 0L
|
internal var lastUpdated: Long = 0L
|
||||||
)
|
)
|
@@ -83,6 +83,8 @@ internal object RuntimeDebugTransaction {
|
|||||||
"Gradle Version" value GradleHelper.version,
|
"Gradle Version" value GradleHelper.version,
|
||||||
"Plugin Version" value SweetDependency.VERSION,
|
"Plugin Version" value SweetDependency.VERSION,
|
||||||
"Plugin Configuration" to mapOf(
|
"Plugin Configuration" to mapOf(
|
||||||
|
"isEnable" value configs.isEnable,
|
||||||
|
"isDebug" value configs.isDebug,
|
||||||
"configFileName" with "(path) ${configs.configFilePath}" to mapOf(
|
"configFileName" with "(path) ${configs.configFilePath}" to mapOf(
|
||||||
"preferences" to mapOf(
|
"preferences" to mapOf(
|
||||||
"autowire-on-sync-mode" value preferences.autowireOnSyncMode,
|
"autowire-on-sync-mode" value preferences.autowireOnSyncMode,
|
||||||
|
@@ -42,6 +42,9 @@ internal interface ISweetDependencyConfigs {
|
|||||||
/** 是否启用插件 */
|
/** 是否启用插件 */
|
||||||
val isEnable: Boolean
|
val isEnable: Boolean
|
||||||
|
|
||||||
|
/** 是否启用调试模式 */
|
||||||
|
val isDebug: Boolean
|
||||||
|
|
||||||
/** [SweetDependency] 的配置文件路径 */
|
/** [SweetDependency] 的配置文件路径 */
|
||||||
val configFilePath: String
|
val configFilePath: String
|
||||||
|
|
||||||
|
@@ -47,6 +47,14 @@ open class SweetDependencyConfigureExtension internal constructor() {
|
|||||||
var isEnable = true
|
var isEnable = true
|
||||||
@JvmName("enable") set
|
@JvmName("enable") set
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否启用调试模式
|
||||||
|
*
|
||||||
|
* 默认不启用 - 启用后将在自动装配时输出详细的依赖搜索信息
|
||||||
|
*/
|
||||||
|
var isDebug = false
|
||||||
|
@JvmName("debug") set
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [SweetDependency] 配置文件名称
|
* [SweetDependency] 配置文件名称
|
||||||
*
|
*
|
||||||
@@ -87,12 +95,14 @@ open class SweetDependencyConfigureExtension internal constructor() {
|
|||||||
*/
|
*/
|
||||||
internal fun build(): ISweetDependencyConfigs {
|
internal fun build(): ISweetDependencyConfigs {
|
||||||
val currentEnable = isEnable
|
val currentEnable = isEnable
|
||||||
|
val currentDebug = isDebug
|
||||||
val currentConfigFilePath = Environment.resourcesDir(configFileName).absolutePath
|
val currentConfigFilePath = Environment.resourcesDir(configFileName).absolutePath
|
||||||
val currentUseDependencyResolutionManagement = isUseDependencyResolutionManagement
|
val currentUseDependencyResolutionManagement = isUseDependencyResolutionManagement
|
||||||
val currentEnableDependenciesAutowireLog = isEnableDependenciesAutowireLog
|
val currentEnableDependenciesAutowireLog = isEnableDependenciesAutowireLog
|
||||||
val currentEnableVerboseMode = isEnableVerboseMode
|
val currentEnableVerboseMode = isEnableVerboseMode
|
||||||
return object : ISweetDependencyConfigs {
|
return object : ISweetDependencyConfigs {
|
||||||
override val isEnable get() = currentEnable
|
override val isEnable get() = currentEnable
|
||||||
|
override val isDebug get() = currentDebug
|
||||||
override val configFilePath get() = currentConfigFilePath
|
override val configFilePath get() = currentConfigFilePath
|
||||||
override val isUseDependencyResolutionManagement get() = currentUseDependencyResolutionManagement
|
override val isUseDependencyResolutionManagement get() = currentUseDependencyResolutionManagement
|
||||||
override val isEnableDependenciesAutowireLog get() = currentEnableDependenciesAutowireLog
|
override val isEnableDependenciesAutowireLog get() = currentEnableDependenciesAutowireLog
|
||||||
|
Reference in New Issue
Block a user