Skip to content

Commit 33b00fc

Browse files
committed
refactor(fix): add custom sourceSetName and fix sourceSets conflict in LocaleAnalysisHelper
1 parent 3a600b1 commit 33b00fc

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/config/proxy/IFlexiLocaleConfigs.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ internal interface IFlexiLocaleConfigs {
3737
* "build/generated/[FlexiLocaleProperties.PROJECT_MODULE_NAME]"
3838
*/
3939
internal const val DEFAULT_GENERATE_DIR_PATH = "build/generated/${FlexiLocaleProperties.PROJECT_MODULE_NAME}"
40+
41+
/**
42+
* 默认的部署 `sourceSet` 名称
43+
*/
44+
internal const val DEFAULT_SOURCE_SET_NAME = "main"
4045
}
4146

4247
/** 是否启用插件 */
@@ -45,6 +50,9 @@ internal interface IFlexiLocaleConfigs {
4550
/** 自定义生成的目录路径 */
4651
val generateDirPath: String
4752

53+
/** 自定义部署的 `sourceSet` 名称 */
54+
val sourceSetName: String
55+
4856
/** 自定义生成的包名 */
4957
val packageName: String
5058

@@ -58,5 +66,5 @@ internal interface IFlexiLocaleConfigs {
5866
* 获取内部 [hashCode]
5967
* @return [Int]
6068
*/
61-
fun innerHashCode() = "$isEnable$generateDirPath$packageName$className$isEnableRestrictedAccess".hashCode()
69+
fun innerHashCode() = "$isEnable$generateDirPath$sourceSetName$packageName$className$isEnableRestrictedAccess".hashCode()
6270
}

flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/extension/dsl/configure/FlexiLocaleConfigureExtension.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ open class FlexiLocaleConfigureExtension internal constructor() {
5959
var generateDirPath = IFlexiLocaleConfigs.DEFAULT_GENERATE_DIR_PATH
6060
@JvmName("generateDirPath") set
6161

62+
/**
63+
* 自定义部署的 `sourceSet` 名称
64+
*
65+
* 如果你的项目源码部署名称不是默认值 - 可以在这里自定义
66+
*
67+
* 默认为 [IFlexiLocaleConfigs.DEFAULT_SOURCE_SET_NAME]
68+
*/
69+
var sourceSetName = IFlexiLocaleConfigs.DEFAULT_SOURCE_SET_NAME
70+
@JvmName("sourceSetName") set
71+
6272
/**
6373
* 自定义生成的包名
6474
*
@@ -104,12 +114,14 @@ open class FlexiLocaleConfigureExtension internal constructor() {
104114
className.checkingValidClassName()
105115
val currentEnable = isEnable
106116
val currentGenerateDirPath = project.file(generateDirPath).absolutePath
117+
val currentSourceSetName = sourceSetName
107118
val currentPackageName = packageName
108119
val currentClassName = "${className.ifBlank { project.fullName().uppercamelcase() }}Locale"
109120
val currentEnableRestrictedAccess = isEnableRestrictedAccess
110121
return object : IFlexiLocaleConfigs {
111122
override val isEnable get() = currentEnable
112123
override val generateDirPath get() = currentGenerateDirPath
124+
override val sourceSetName get() = currentSourceSetName
113125
override val packageName get() = currentPackageName
114126
override val className get() = currentClassName
115127
override val isEnableRestrictedAccess get() = currentEnableRestrictedAccess

flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/helper/LocaleAnalysisHelper.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,12 @@ internal object LocaleAnalysisHelper {
130130
*/
131131
private fun initializePlugins(project: Project) {
132132
runCatching {
133-
fun BaseExtension.updateSourceDirs() = sourceSets.configureEach { kotlin.srcDir(configs.generateDirPath) }
134-
fun KotlinProjectExtension.updateSourceDirs() = sourceSets.configureEach { kotlin.srcDir(configs.generateDirPath) }
133+
fun BaseExtension.updateSourceDirs() = sourceSets.firstOrNull {
134+
it.name == configs.sourceSetName
135+
}?.kotlin?.srcDir(configs.generateDirPath) ?: FLog.warn("Could not found source set \"${configs.sourceSetName}\"")
136+
fun KotlinProjectExtension.updateSourceDirs() = sourceSets.firstOrNull {
137+
it.name == configs.sourceSetName
138+
}?.kotlin?.srcDir(configs.generateDirPath) ?: FLog.warn("Could not found source set \"${configs.sourceSetName}\"")
135139
fun BaseVariant.updateResDirectories() = sourceSets.forEach { provide -> provide.resDirectories?.also { resDirectories.addAll(it) } }
136140
project.plugins.withId(APPLICATION_PLUGIN_NAME) {
137141
project.get<AppExtension>().also { extension ->

0 commit comments

Comments
 (0)