mirror of
https://github.com/HighCapable/SweetProperty.git
synced 2025-09-04 01:35:37 +08:00
Compare commits
6 Commits
22b0a1be2c
...
36c7af3c52
Author | SHA1 | Date | |
---|---|---|---|
36c7af3c52
|
|||
34b11eb5b7
|
|||
72037d6f08
|
|||
cf4b59db1a
|
|||
74da386f49
|
|||
ceccd2e2cf
|
@@ -38,4 +38,12 @@
|
||||
|
||||
## 1.0.5 | 2023.11.08
|
||||
|
||||
- 修复遇到特殊字符和重复键值名称造成代码生成失败的严重问题
|
||||
- 修复遇到特殊字符和重复键值名称造成代码生成失败的严重问题
|
||||
|
||||
## 1.0.7 | 2025.08.19
|
||||
|
||||
- 修复在新版 Android Gradle Plugin 及 Android Studio/IDEA 中部署源码路径时的错误
|
||||
`removeContentEntry: removed content entry url 'build/generated/sweet-property' still exists after removing`
|
||||
- 新增 `sourceSetName` 方法,允许自定义要部署的源集名称
|
||||
- 修复在类型自动转换过程中某些 `commit id` 和 Hash 可能被识别为数值类型的问题
|
||||
- 合并 [#1](https://github.com/HighCapable/SweetProperty/pull/1) 并重新发布版本 (1.0.7)
|
@@ -39,4 +39,12 @@
|
||||
|
||||
## 1.0.5 | 2023.11.08
|
||||
|
||||
- Fix a serious issue that caused code generation failure when encountering special characters and duplicate key-value names
|
||||
- Fix a serious issue that caused code generation failure when encountering special characters and duplicate key-value names
|
||||
|
||||
## 1.0.7 | 2025.08.19
|
||||
|
||||
- Fix errors when deploying source code paths in the new version of Android Gradle Plugin and Android Studio/IDEA
|
||||
`removeContentEntry: removed content entry url 'build/generated/sweet-property' still exists after removing`
|
||||
- Added the `sourceSetName` method to allow customization of the source set name to be deployed
|
||||
- Fix an issue where some `commit id` and Hash might be recognized as numeric types during the automatic type conversion process
|
||||
- Merge [#1](https://github.com/HighCapable/SweetProperty/pull/1) and re-release the version (1.0.7)
|
@@ -155,6 +155,10 @@ sweetProperty {
|
||||
// 默认为 "build/generated/sweet-property"
|
||||
// 建议将生成的代码放置于 "build" 目录下,因为生成的代码不建议去修改它
|
||||
generateDirPath = "build/generated/sweet-property"
|
||||
// 自定义部署的 `sourceSet` 名称
|
||||
// 如果你的项目源码部署名称不是默认值,可以在这里自定义
|
||||
// 默认为 "main"
|
||||
sourceSetName = "main"
|
||||
// 自定义生成的包名
|
||||
// Android 项目默认使用 "android" 配置方法块中的 "namespace"
|
||||
// 普通的 Kotlin on Jvm 项目默认使用项目设置的 "project.group"
|
||||
|
@@ -168,6 +168,10 @@ sweetProperty {
|
||||
// It is recommended to place the generated code in the "build" directory,
|
||||
// because the generated code is not recommended to be modified
|
||||
generateDirPath = "build/generated/sweet-property"
|
||||
// Custom deployed `sourceSet` name
|
||||
// If your project source code deployment name is not the default value, you can customize it here
|
||||
// Defaults to "main"
|
||||
sourceSetName = "main"
|
||||
// Custom generated package name
|
||||
// Android projects use the "namespace" in the "android" configuration method block by default
|
||||
// Ordinary Kotlin on Jvm projects use the "project.group" of the project settings by default
|
||||
|
@@ -3,12 +3,12 @@ project.name=SweetProperty
|
||||
project.url=https://github.com/HighCapable/SweetProperty
|
||||
project.groupName=com.highcapable.sweetproperty
|
||||
project.moduleName=sweet-property
|
||||
project.version=1.0.5
|
||||
project.version=1.0.7
|
||||
# Gradle Plugin Configuration
|
||||
gradle.plugin.moduleName=${project.groupName}.gradle.plugin
|
||||
gradle.plugin.implementationClass=${project.groupName}.plugin.SweetPropertyPlugin
|
||||
# Maven Publish Configuration
|
||||
SONATYPE_HOST=S01
|
||||
SONATYPE_HOST=CENTRAL_PORTAL
|
||||
RELEASE_SIGNING_ENABLED=true
|
||||
# Maven POM Configuration
|
||||
POM_NAME=SweetProperty
|
||||
|
@@ -8,7 +8,7 @@ pluginManagement {
|
||||
}
|
||||
plugins {
|
||||
id("com.highcapable.sweetdependency") version "1.0.4"
|
||||
id("com.highcapable.sweetproperty") version "1.0.5"
|
||||
id("com.highcapable.sweetproperty") version "1.0.7"
|
||||
}
|
||||
sweetDependency {
|
||||
isEnableVerboseMode = false
|
||||
|
@@ -56,6 +56,7 @@ internal object DefaultConfigs {
|
||||
) = object : ISweetPropertyConfigs.ISourcesCodeGenerateConfigs {
|
||||
override val name get() = name
|
||||
override val generateDirPath get() = ISweetPropertyConfigs.DEFAULT_GENERATE_DIR_PATH
|
||||
override val sourceSetName get() = ISweetPropertyConfigs.DEFAULT_SOURCE_SET_NAME
|
||||
override val packageName get() = ""
|
||||
override val className get() = ""
|
||||
override val isEnableRestrictedAccess get() = false
|
||||
|
@@ -74,6 +74,10 @@ private fun SweetPropertyConfigureExtension.SourcesCodeGenerateConfigureExtensio
|
||||
get() = this@create.generateDirPath.noBlank()
|
||||
?: global?.generateDirPath?.noBlank()
|
||||
?: DefaultConfigs.sourcesCodeGenerateConfigs(name, selfBase, globalBase).generateDirPath
|
||||
override val sourceSetName
|
||||
get() = this@create.sourceSetName.noBlank()
|
||||
?: global?.sourceSetName?.noBlank()
|
||||
?: DefaultConfigs.sourcesCodeGenerateConfigs(name, selfBase, globalBase).sourceSetName
|
||||
override val packageName
|
||||
get() = this@create.packageName.noBlank()
|
||||
?: global?.packageName?.noBlank()
|
||||
|
@@ -40,6 +40,11 @@ internal interface ISweetPropertyConfigs {
|
||||
*/
|
||||
internal const val DEFAULT_GENERATE_DIR_PATH = "build/generated/${SweetPropertyProperties.PROJECT_MODULE_NAME}"
|
||||
|
||||
/**
|
||||
* 默认的部署 `sourceSet` 名称
|
||||
*/
|
||||
internal const val DEFAULT_SOURCE_SET_NAME = "main"
|
||||
|
||||
/**
|
||||
* 默认的属性配置文件名称
|
||||
*
|
||||
@@ -91,6 +96,9 @@ internal interface ISweetPropertyConfigs {
|
||||
/** 自定义生成的目录路径 */
|
||||
val generateDirPath: String
|
||||
|
||||
/** 自定义部署的 `sourceSet` 名称 */
|
||||
val sourceSetName: String
|
||||
|
||||
/** 自定义生成的包名 */
|
||||
val packageName: String
|
||||
|
||||
|
@@ -173,6 +173,16 @@ open class SweetPropertyConfigureExtension internal constructor() {
|
||||
var generateDirPath = ""
|
||||
@JvmName("generateDirPath") set
|
||||
|
||||
/**
|
||||
* 自定义部署的 `sourceSet` 名称
|
||||
*
|
||||
* 如果你的项目源码部署名称不是默认值 - 可以在这里自定义
|
||||
*
|
||||
* 默认为 [ISweetPropertyConfigs.DEFAULT_SOURCE_SET_NAME]
|
||||
*/
|
||||
var sourceSetName = ""
|
||||
@JvmName("sourceSetName") set
|
||||
|
||||
/**
|
||||
* 自定义生成的包名
|
||||
*
|
||||
|
@@ -57,17 +57,21 @@ internal fun Any.parseTypedValue(isAutoConversion: Boolean): Pair<KClass<*>, Str
|
||||
} else it.replace("\"", "\\\"")
|
||||
}
|
||||
if (!isAutoConversion) return Pair(String::class, "\"$valueString\"")
|
||||
val trimmed = valueString.trim()
|
||||
val typeSpec = when {
|
||||
isStringType -> String::class
|
||||
valueString.trim().toIntOrNull() != null -> Int::class
|
||||
valueString.trim().toLongOrNull() != null -> Long::class
|
||||
valueString.trim().toDoubleOrNull() != null -> Double::class
|
||||
valueString.trim().toFloatOrNull() != null -> Float::class
|
||||
valueString.trim() == "true" || valueString.trim() == "false" -> Boolean::class
|
||||
isStringType || trimmed.any { !it.isDigit() && it != '.' && it != '-' } -> String::class
|
||||
trimmed.toIntOrNull() != null -> Int::class
|
||||
trimmed.toLongOrNull() != null -> Long::class
|
||||
trimmed.toDoubleOrNull() != null -> Double::class
|
||||
trimmed.toFloatOrNull() != null -> Float::class
|
||||
trimmed == "true" || trimmed == "false" -> Boolean::class
|
||||
else -> String::class
|
||||
}; return Pair(typeSpec, if (typeSpec == String::class) "\"$valueString\"" else valueString.let {
|
||||
if (typeSpec == Long::class && !it.endsWith("L")) "${it}L" else it
|
||||
})
|
||||
}
|
||||
val finalValue = when (typeSpec) {
|
||||
String::class -> "\"$valueString\""
|
||||
Long::class -> if (trimmed.endsWith("L")) trimmed else "${trimmed}L"
|
||||
else -> trimmed
|
||||
}; return typeSpec to finalValue
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -41,6 +41,7 @@ import com.highcapable.sweetproperty.utils.camelcase
|
||||
import com.highcapable.sweetproperty.utils.code.entity.MavenPomData
|
||||
import com.highcapable.sweetproperty.utils.code.factory.compile
|
||||
import com.highcapable.sweetproperty.utils.debug.SError
|
||||
import com.highcapable.sweetproperty.utils.debug.SLog
|
||||
import com.highcapable.sweetproperty.utils.flatted
|
||||
import com.highcapable.sweetproperty.utils.hasInterpolation
|
||||
import com.highcapable.sweetproperty.utils.isEmpty
|
||||
@@ -49,7 +50,6 @@ import com.highcapable.sweetproperty.utils.noEmpty
|
||||
import com.highcapable.sweetproperty.utils.replaceInterpolation
|
||||
import com.highcapable.sweetproperty.utils.toStringMap
|
||||
import com.highcapable.sweetproperty.utils.uppercamelcase
|
||||
import org.gradle.api.DomainObjectCollection
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.initialization.Settings
|
||||
import java.io.File
|
||||
@@ -212,6 +212,8 @@ internal object PropertiesDeployHelper {
|
||||
if (configs.isEnable) configureSourceSets(project = this)
|
||||
return
|
||||
}; outputDir.apply { if (exists()) deleteRecursively() }
|
||||
// 每次都会重新创建目录
|
||||
outputDir.mkdirs()
|
||||
cachedProjectProperties[fullName()] = properties
|
||||
val packageName = generatedPackageName(configs, project = this)
|
||||
val className = generatedClassName(configs, project = this)
|
||||
@@ -227,16 +229,26 @@ internal object PropertiesDeployHelper {
|
||||
* @param project 当前项目
|
||||
*/
|
||||
private fun configureSourceSets(project: Project) {
|
||||
fun Project.deploySourceSets(name: String) = runCatching {
|
||||
val configs = configs.with(project).sourcesCode
|
||||
fun Project.deploySourceSet(name: String, sourceSetName: String = configs.sourceSetName) = runCatching {
|
||||
val extension = get(name)
|
||||
val collection = extension.javaClass.getMethod("getSourceSets").invoke(extension) as DomainObjectCollection<*>
|
||||
collection.configureEach {
|
||||
val kotlin = javaClass.getMethod("getKotlin").invoke(this)
|
||||
kotlin.javaClass.getMethod("srcDir", Any::class.java).invoke(kotlin, configs.with(project).sourcesCode.generateDirPath)
|
||||
}
|
||||
val collection = extension.javaClass.getMethod("getSourceSets").invoke(extension) as? Iterable<*>?
|
||||
val mainSet = collection?.firstOrNull {
|
||||
it?.javaClass?.getMethod("getName")?.invoke(it) == sourceSetName
|
||||
} ?: return@runCatching SLog.warn("Could not found source set \"$sourceSetName\" for $name extension")
|
||||
val kotlin = mainSet.javaClass.getMethod("getKotlin").invoke(mainSet)
|
||||
val generateDir = configs.generateDirPath
|
||||
val generateFile = File(generateDir)
|
||||
// 确保目录存在
|
||||
if (!generateFile.exists()) generateFile.mkdirs()
|
||||
val srcDirs = kotlin.javaClass.getMethod("getSrcDirs").invoke(kotlin) as Set<*>
|
||||
val alreadyAdded = srcDirs.any { it is File && it.canonicalPath == generateFile.canonicalPath }
|
||||
if (!alreadyAdded) kotlin.javaClass.getMethod("srcDir", Any::class.java).invoke(kotlin, generateFile)
|
||||
}.onFailure {
|
||||
SLog.error(msg = "Failed to deploy source set \"$sourceSetName\" for $name extension\n${it.stackTraceToString()}")
|
||||
}
|
||||
if (project.hasExtension("kotlin")) project.deploySourceSets(name = "kotlin")
|
||||
if (project.hasExtension("android")) project.deploySourceSets(name = "android")
|
||||
if (project.hasExtension("kotlin")) project.deploySourceSet(name = "kotlin")
|
||||
if (project.hasExtension("android")) project.deploySourceSet(name = "android")
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user