mirror of
https://github.com/HighCapable/SweetDependency.git
synced 2025-09-04 01:35:46 +08:00
feat: add enable / disable auto generate dependencies namespace function
This commit is contained in:
@@ -48,30 +48,43 @@ internal data class PreferencesDocument(
|
||||
internal var versionFilter: VersionFilterDocument = VersionFilterDocument()
|
||||
) : IYamlDocument {
|
||||
|
||||
/**
|
||||
* 依赖命名空间文档实体
|
||||
* @param plugins 插件依赖
|
||||
* @param libraries 库依赖
|
||||
*/
|
||||
@Serializable
|
||||
internal data class DependenciesNamespaceDocument(
|
||||
@SerialName("plugins")
|
||||
var plugins: String = "libs",
|
||||
var plugins: NamespaceOptionDocument = NamespaceOptionDocument(name = "libs"),
|
||||
@SerialName("libraries")
|
||||
var libraries: String = ""
|
||||
var libraries: NamespaceOptionDocument = NamespaceOptionDocument()
|
||||
) : IYamlDocument {
|
||||
|
||||
init {
|
||||
if (plugins.isNotBlank() && libraries.isNotBlank() && plugins == libraries)
|
||||
if (plugins.name.isNotBlank() && libraries.name.isNotBlank() && plugins.name == libraries.name)
|
||||
SError.make("Duplicated dependencies namespace \"$plugins\"")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 命名空间选项文档实体
|
||||
* @param isEnable 是否启用
|
||||
* @param name 名称
|
||||
*/
|
||||
@Serializable
|
||||
internal data class NamespaceOptionDocument(
|
||||
@SerialName("enable")
|
||||
var isEnable: Boolean = true,
|
||||
@SerialName("name")
|
||||
var name: String = ""
|
||||
) : IYamlDocument {
|
||||
|
||||
/**
|
||||
* 获取插件依赖命名空间
|
||||
* 获取名称
|
||||
* @return [String]
|
||||
*/
|
||||
internal fun plugins() = plugins.apply { checkingName("plugins namespace", isCheckExtName = true) }.camelcase()
|
||||
|
||||
/**
|
||||
* 获取库依赖命名空间
|
||||
* @return [String]
|
||||
*/
|
||||
internal fun libraries() = libraries.apply { checkingName("libraries namespace", isCheckExtName = true) }.camelcase()
|
||||
internal fun name() = name.apply { checkingName("dependencies namespace", isCheckExtName = true) }.camelcase()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -76,9 +76,9 @@ internal object DependencyDeployHelper {
|
||||
* @param settings 当前设置
|
||||
*/
|
||||
internal fun generateVersionCatalogs(settings: Settings) {
|
||||
val pluginsNamespace = SweetDependencyConfigs.document.preferences().dependenciesNamespace.plugins()
|
||||
runCatching {
|
||||
settings.dependencyResolutionManagement.versionCatalogs.create(pluginsNamespace) {
|
||||
val pluginsOption = SweetDependencyConfigs.document.preferences().dependenciesNamespace.plugins
|
||||
if (pluginsOption.isEnable) runCatching {
|
||||
settings.dependencyResolutionManagement.versionCatalogs.create(pluginsOption.name()) {
|
||||
Dependencies.plugins().forEach { (dependencyName, artifact) ->
|
||||
if (GradleTaskManager.isInternalRunningTask && artifact.version().isAutowire) SError.make(
|
||||
"""
|
||||
@@ -140,8 +140,14 @@ internal object DependencyDeployHelper {
|
||||
* @param rootProject 当前根项目
|
||||
*/
|
||||
internal fun resolveAccessors(rootProject: Project) {
|
||||
val librariesOption = SweetDependencyConfigs.document.preferences().dependenciesNamespace.libraries
|
||||
if (librariesOption.isEnable.not()) {
|
||||
accessorsPomData.relativePomPath.toFile().takeIf { it.exists() }?.deleteRecursively()
|
||||
accessorsGenerator.clearGeneratedData()
|
||||
return
|
||||
}
|
||||
if (Dependencies.isOutdate || accessorsDir.resolve(accessorsPomData.relativePomPath).isEmpty())
|
||||
accessorsGenerator.build().compile(accessorsPomData, accessorsDir.absolutePath, accessorsGenerator.compileStubFiles)
|
||||
accessorsGenerator.build(librariesOption.name()).compile(accessorsPomData, accessorsDir.absolutePath, accessorsGenerator.compileStubFiles)
|
||||
rootProject.addDependencyToBuildScript(accessorsDir.absolutePath, accessorsPomData)
|
||||
}
|
||||
|
||||
|
@@ -88,8 +88,14 @@ internal object RuntimeDebugTransaction {
|
||||
"autowire-on-sync-mode" value preferences.autowireOnSyncMode,
|
||||
"repositories-mode" value preferences.repositoriesMode,
|
||||
"dependencies-namespace" to mapOf(
|
||||
"plugins" value preferences.dependenciesNamespace.plugins().ifBlank { NONE },
|
||||
"libraries" value preferences.dependenciesNamespace.libraries().ifBlank { NONE }
|
||||
"plugins" to mapOf(
|
||||
"enable" value preferences.dependenciesNamespace.plugins.isEnable,
|
||||
"name" value preferences.dependenciesNamespace.plugins.name().ifBlank { NONE }
|
||||
),
|
||||
"libraries" to mapOf(
|
||||
"enable" value preferences.dependenciesNamespace.libraries.isEnable,
|
||||
"name" value preferences.dependenciesNamespace.libraries.name().ifBlank { NONE }
|
||||
)
|
||||
),
|
||||
"version-filter" with (if (vfExclusionList.isEmpty()) "(disabled)" else "") to versionFilterMap
|
||||
),
|
||||
|
@@ -29,7 +29,6 @@ import com.highcapable.sweetdependency.generated.SweetDependencyProperties
|
||||
import com.highcapable.sweetdependency.gradle.delegate.entity.ExternalDependencyDelegate
|
||||
import com.highcapable.sweetdependency.gradle.entity.ExternalDependency
|
||||
import com.highcapable.sweetdependency.manager.content.Dependencies
|
||||
import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs
|
||||
import com.highcapable.sweetdependency.plugin.extension.accessors.proxy.IExtensionAccessors
|
||||
import com.highcapable.sweetdependency.utils.camelcase
|
||||
import com.highcapable.sweetdependency.utils.capitalize
|
||||
@@ -91,6 +90,9 @@ internal class LibrariesAccessorsGenerator {
|
||||
/** 生成的依赖库不重复 TAG 数组 */
|
||||
private val usedSuccessiveTags = mutableSetOf<String>()
|
||||
|
||||
/** 当前库依赖的命名空间 */
|
||||
private var librariesNamespace = ""
|
||||
|
||||
/**
|
||||
* 不重复调用
|
||||
* @param tags 当前 TAG 数组
|
||||
@@ -395,7 +397,7 @@ internal class LibrariesAccessorsGenerator {
|
||||
}
|
||||
|
||||
/** 清空所有已生成的数据 */
|
||||
private fun clearGeneratedData() {
|
||||
internal fun clearGeneratedData() {
|
||||
classSpecs.clear()
|
||||
constructorSpecs.clear()
|
||||
preAddConstructorSpecNames.clear()
|
||||
@@ -403,14 +405,17 @@ internal class LibrariesAccessorsGenerator {
|
||||
grandSuccessiveNames.clear()
|
||||
grandSuccessiveDuplicateIndexs.clear()
|
||||
usedSuccessiveTags.clear()
|
||||
librariesNamespace = ""
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 [JavaFile]
|
||||
* @param namespace 依赖命名空间
|
||||
* @return [JavaFile]
|
||||
* @throws SweetDependencyUnresolvedException 如果生成失败
|
||||
*/
|
||||
internal fun build() = runCatching {
|
||||
internal fun build(namespace: String) = runCatching {
|
||||
librariesNamespace = namespace
|
||||
clearGeneratedData()
|
||||
createTopClassSpec()
|
||||
Dependencies.libraries().forEach { (dependencyName, artifact) ->
|
||||
@@ -454,8 +459,7 @@ internal class LibrariesAccessorsGenerator {
|
||||
* @return [List]<[Pair]<[String], [String]>>
|
||||
*/
|
||||
internal val librariesClasses get() =
|
||||
SweetDependencyConfigs.document.preferences().dependenciesNamespace.libraries().let { namespace ->
|
||||
if (namespace.isNotBlank()) listOf(namespace to createAccessorsName())
|
||||
else memoryExtensionClasses
|
||||
}
|
||||
if (librariesNamespace.isNotBlank())
|
||||
listOf(librariesNamespace to createAccessorsName())
|
||||
else memoryExtensionClasses
|
||||
}
|
Reference in New Issue
Block a user