mirror of
https://github.com/HighCapable/SweetProperty.git
synced 2025-09-06 02:35:28 +08:00
Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
db2817a85a
|
|||
ebb1b95658
|
|||
68116f9f1f
|
|||
bd22e7b134
|
|||
416522a673
|
|||
d59e6feaab
|
|||
f08d25912d
|
|||
1bcd23113d
|
|||
22b4228a46
|
|||
7485b13e7c
|
|||
e24f6d0df1
|
|||
10ae6ed17a
|
|||
d41347066d
|
|||
b6507c0e99
|
|||
c3481acb2d
|
|||
d3ff5689ae
|
|||
fb7682d963
|
|||
9a91fdb0bf
|
|||
4ab7eef69c
|
|||
180f475562
|
|||
9e2c26ae73
|
|||
f66cdc1f31
|
|||
2e73f36bf0
|
|||
8594bca9a6
|
|||
8cc09e7fcd
|
|||
6297cb9919
|
@@ -50,6 +50,12 @@
|
||||
|
||||
本项目同样使用了 **SweetDependency**。
|
||||
|
||||
## 捐赠支持
|
||||
|
||||
工作不易,无意外情况此项目将继续维护下去,提供更多可能,欢迎打赏。
|
||||
|
||||
<img src="https://github.com/fankes/fankes/blob/main/img-src/payment_code.jpg?raw=true" width = "500" alt="Payment Code"/>
|
||||
|
||||
## Star History
|
||||
|
||||

|
||||
|
@@ -7,4 +7,23 @@
|
||||
## 1.0.1 | 2023.09.04
|
||||
|
||||
- 新增启用 `isEnableTypeAutoConversion` 后可以使用 '' 或 "" 强制设置一个键值内容为字符串类型
|
||||
- 修改生成的代码中属性键值的内容使用优化后的类型呈现
|
||||
- 修改生成的代码中属性键值的内容使用优化后的类型呈现
|
||||
|
||||
## 1.0.2 | 2023.09.07
|
||||
|
||||
- 使用 `net.lingala.zip4j` 取代 JDK 默认创建压缩文档功能修复在 Windows 平台中 Gradle 8.0.2+ 版本创建的 JAR 损坏导致找不到生成的 Class 问题
|
||||
- 重构自动生成代码部分的装载功能,增加可能找不到 Class 的错误提示
|
||||
- 作废了 ~~`propertiesFileName`~~ 方法
|
||||
- 新增 `propertiesFileNames` 方法,现在你可以同时设置一组属性配置文件名称了
|
||||
- 新增 `includeKeys` 方法,现在你可以设置仅包含的属性键值名称数组了
|
||||
- 新增 `keyValuesRules` 方法,现在你可以在属性键值装载过程中修改键值内容的实际解析结果
|
||||
|
||||
## 1.0.3 | 2023.09.26
|
||||
|
||||
- 自动生成代码功能将始终输出源码文件,以方便在生成失败的时候进行调试
|
||||
- 修复 Gradle 生命周期问题
|
||||
- 修复根项目大小写变化后识别为两个项目的问题
|
||||
- 修复在全局配置中使用过其它配置方法后,子项目的 `all` 方法失效问题
|
||||
- 改进并采用 Gradle 项目命名规范
|
||||
- 新增插件自身检查更新功能
|
||||
- 一些其它功能性的改进
|
@@ -7,4 +7,24 @@
|
||||
## 1.0.1 | 2023.09.04
|
||||
|
||||
- After enabling `isEnableTypeAutoConversion`, you can use '' or "" to force the content of a value to be a string type
|
||||
- Modify the content of the properties key-values in the generated code to use the optimized type to render
|
||||
- Modify the content of the properties key-values in the generated code to use the optimized type to render
|
||||
|
||||
## 1.0.2 | 2023.09.07
|
||||
|
||||
- Use `net.lingala.zip4j` to replace JDK's default function of creating compressed files and fix the problem that the JAR created by Gradle 8.0.2+
|
||||
version on Windows platform is broken and the generated classes cannot be found
|
||||
- Refactor the loading function of the automatically generated code part, and add an error message that classes may not be found
|
||||
- Deprecated ~~`propertiesFileName`~~ method
|
||||
- Added `propertiesFileNames` method, now you can set a group of properties file names at the same time
|
||||
- Added `includeKeys` method, now you can set an array of properties key names to include only
|
||||
- Added `keyValuesRules` method, now you can modify the actual parsing result of the value content during the properties key-values loading process
|
||||
|
||||
## 1.0.3 | 2023.09.26
|
||||
|
||||
- The automatic code generation function will always output source code files to facilitate debugging when the generation fails
|
||||
- Fix Gradle lifecycle problem
|
||||
- Fix root project was recognized as two projects after the case was changed
|
||||
- Fix `all` function of the sub-project fails after using other configuration functions in the global configuration
|
||||
- Improve and adopt Gradle project naming convention
|
||||
- Added plugin own update function
|
||||
- Some other functional improvements
|
@@ -70,11 +70,6 @@ sweetProperty {
|
||||
// 启用功能
|
||||
// 你可以分别对 "sourcesCode"、"buildScript" 进行设置
|
||||
isEnable = true
|
||||
// 设置属性配置文件名称
|
||||
// 一般情况下不需要修改此设置,错误的文件名将导致获取到空键值内容
|
||||
// 如果你有一个自定义名称的属性键值文件,你可以修改这里的设置
|
||||
// 注意:建议为每个项目单独配置,而不是在全局中修改,以防发生问题
|
||||
propertiesFileName = "gradle.properties"
|
||||
// 是否启用排除非字符串类型键值内容
|
||||
// 默认启用,启用后将从属性键值中排除不是字符串类型的键值及内容
|
||||
// 这可以排除例如一些系统环境变量的配置或内存中的数据
|
||||
@@ -90,6 +85,18 @@ sweetProperty {
|
||||
// 默认启用,启用后将自动识别属性键值内容中的 ${...} 内容并进行替换
|
||||
// 注意:插值的内容仅会从当前 (当前配置文件) 属性键值列表进行查找
|
||||
isEnableValueInterpolation = true
|
||||
// 设置属性配置文件名称数组
|
||||
// 属性配置文件将根据你设置的文件名称自动从当前根项目、子项目以及用户目录的根目录进行获取
|
||||
// 你可以添加多组属性配置文件名称,将按照顺序依次进行读取
|
||||
// 一般情况下不需要修改此设置,错误的文件名将导致获取到空键值内容
|
||||
// 你可以配置 "isAddDefault" 参数来决定是否添加默认的 "gradle.properties" 文件名称
|
||||
// 如果你有一个或多个自定义名称的属性键值文件,你可以修改这里的设置
|
||||
// 注意:建议为每个项目单独配置,而不是在全局中修改,以防发生问题
|
||||
propertiesFileNames(
|
||||
"some_other_1.properties",
|
||||
"some_other_2.properties",
|
||||
isAddDefault = true
|
||||
)
|
||||
// 设置固定存在的属性键值数组
|
||||
// 在这里可以设置一些一定存在的键值,这些键值无论能否从属性键值中得到都会进行生成
|
||||
// 这些键值在属性键值存在时使用属性键值的内容,不存在时使用这里设置的内容
|
||||
@@ -111,6 +118,21 @@ sweetProperty {
|
||||
"exclude.some.key1",
|
||||
"exclude.some.key2"
|
||||
)
|
||||
// 设置需要包含的属性键值名称数组
|
||||
// 在这里可以设置一些你希望从已知的属性键值中包含的键值名称
|
||||
// 这些键值在属性键值存在它们时被包含,未被包含的键值不会出现在生成的代码中
|
||||
// 你可以传入 Regex 或使用 String.toRegex 以使用正则功能
|
||||
includeKeys(
|
||||
"include.some.key1",
|
||||
"include.some.key2"
|
||||
)
|
||||
// 设置属性键值规则数组
|
||||
// 你可以设置一组键值规则,使用 "createValueRule" 创建新的规则,用于解析得到的键值内容
|
||||
// 这些键值规则在属性键值存在它们时被应用
|
||||
keyValuesRules(
|
||||
"some.key1" to createValueRule { if (it.contains("_")) it.replace("_", "-") else it },
|
||||
"some.key2" to createValueRule { "$it-value" }
|
||||
)
|
||||
// 设置从何处生成属性键值
|
||||
// 默认为 "CURRENT_PROJECT" 和 "ROOT_PROJECT"
|
||||
// 你可以使用以下类型来进行设置
|
||||
@@ -172,13 +194,15 @@ sweetProperty {
|
||||
// 配置 "buildScript"
|
||||
}
|
||||
}
|
||||
// 子项目配置
|
||||
// 其它项目与子项目配置
|
||||
// 在方法参数中填入需要配置的项目完整名称来配置对应的项目
|
||||
// 如果你的项目为嵌套型子项目,例如 app → sub
|
||||
// 此时你需要使用 ":" 来分隔多个子项目,例如 "app:sub"
|
||||
// 你不需要再填写子项目前面的 ":",例如 ":app"
|
||||
// 如果当前项目是子项目,你必须填写子项目前面的 ":",例如 ":app"
|
||||
// 如果当前项目为嵌套型子项目,例如 app → sub
|
||||
// 此时你需要使用 ":" 来分隔多个子项目,例如 ":app:sub"
|
||||
// 注意:在 1.0.2 版本及以前是不需要添加 ":" 来标识子项目的,且添加后会报错
|
||||
// 这是一个错误做法,目前统一了 Gradle 的项目命名规范,请使用新的规范
|
||||
// 根项目的名称不能直接用来配置子项目,请使用 "rootProject"
|
||||
project("app") {
|
||||
project(":app") {
|
||||
all {
|
||||
// 配置 "all"
|
||||
}
|
||||
|
@@ -73,11 +73,6 @@ sweetProperty {
|
||||
// Enable functionality
|
||||
// You can set "sourcesCode" and "buildScript" respectively
|
||||
isEnable = true
|
||||
// Set properties name
|
||||
// In general, you don't need to modify this setting, the wrong file name will lead to getting empty key-values content
|
||||
// If you have a properties file with a custom name, you can modify the settings here
|
||||
// Note: It is recommended to configure each project individually, rather than modifying globally, in case of problems
|
||||
propertiesFileName = "gradle.properties"
|
||||
// Whether to enable the exclusion of non-string type key-values content
|
||||
// Enabled by default, when enabled, key-values and content that are not string types will be excluded from the properties key-values
|
||||
// This can exclude e.g. configuration of some system environment variables or data in memory
|
||||
@@ -96,7 +91,20 @@ sweetProperty {
|
||||
// will be automatically recognized and replaced
|
||||
// Note: The interpolated content will only be searching from the current (current configuration file) properties key-values list
|
||||
isEnableValueInterpolation = true
|
||||
// Set a fixed attribute key-value array
|
||||
// Set properties names array
|
||||
// The properties file will be automatically obtained from the root directory of
|
||||
// the current root project, subproject and user directory according to the file name you set
|
||||
// You can add multiple sets of properties file names, which will be read in order
|
||||
// In general, you don't need to modify this setting, the wrong file name will lead to getting empty key-values content
|
||||
// You can configure the "isAddDefault" parameter to decide whether to add the default "gradle.properties" file name
|
||||
// If you have one or more properties files with custom names, you can modify the settings here
|
||||
// Note: It is recommended to configure each project individually, rather than modifying globally, in case of problems
|
||||
propertiesFileNames(
|
||||
"some_other_1.properties",
|
||||
"some_other_2.properties",
|
||||
isAddDefault = true
|
||||
)
|
||||
// Set fixed properties key-values array
|
||||
// Here you can set some key values that must exist,
|
||||
// and these key values will be generated regardless of whether they can be obtained from the properties key-values
|
||||
// These key-values use the content of the properties key-values when the properties key-values exists,
|
||||
@@ -110,7 +118,7 @@ sweetProperty {
|
||||
"permanent.some.key1" to "some_value_1",
|
||||
"permanent.some.key2" to "some_value_2"
|
||||
)
|
||||
// Set an array of properties key-values names that need to be excluded
|
||||
// Set properties key-values array names that need to be excluded
|
||||
// Here you can set some key names that you want to exclude from the known properties keys
|
||||
// These keys are excluded when they exist in the properties keys and will not appear in the generated code
|
||||
// Note: If you exclude the key-values set in "permanentKeyValues",
|
||||
@@ -120,6 +128,22 @@ sweetProperty {
|
||||
"exclude.some.key1",
|
||||
"exclude.some.key2"
|
||||
)
|
||||
// Set properties key-values array names that need to be included
|
||||
// Here you can set some key-values names that you want to include from known properties keys
|
||||
// These keys are included when the properties key-values exists
|
||||
// Key-values that are not included will not appear in the generated code
|
||||
// You can pass in a Regex or use String.toRegex to use the regex function
|
||||
includeKeys(
|
||||
"include.some.key1",
|
||||
"include.some.key2"
|
||||
)
|
||||
// Set properties key-values rules array
|
||||
// You can set a set of key-values rules and use "createValueRule" to create new rules for parsing the obtained value content
|
||||
// These key-values rules are applied when the properties key-values exists
|
||||
keyValuesRules(
|
||||
"some.key1" to createValueRule { if (it.contains("_")) it.replace("_", "-") else it },
|
||||
"some.key2" to createValueRule { "$it-value" }
|
||||
)
|
||||
// Set where to generate properties key-values
|
||||
// Defaults to "CURRENT_PROJECT" and "ROOT_PROJECT"
|
||||
// You can use the following types to set
|
||||
@@ -184,13 +208,15 @@ sweetProperty {
|
||||
// Configure "buildScript"
|
||||
}
|
||||
}
|
||||
// Sub-projects configuration
|
||||
// Other projects and sub-projects configurations
|
||||
// Fill in the full name of the project that needs to be configured in the method parameters to configure the corresponding project
|
||||
// If your project is a nested sub-projects, such as app → sub
|
||||
// At this point you need to use ":" to separate multiple sub-projects, such as "app:sub"
|
||||
// You don't need to fill in the ":" in front of the sub-projects, such as ":app"
|
||||
// If the current project is a sub-project, you must fill in the ":" in front of the sub-project, such as ":app"
|
||||
// If the current project is a nested sub-project, such as app → sub
|
||||
// At this time you need to use ":" to separate multiple sub-projects, such as ":app:sub"
|
||||
// Note: In version 1.0.2 and before, there is no need to add ":" to identify sub-projects, and an error will be thrown after adding it
|
||||
// This is a wrong approach, Gradle's project naming convention is currently unified, please use the new convention
|
||||
// The name of the root project cannot be used directly to configure sub-projects, please use "rootProject"
|
||||
project("app") {
|
||||
project(":app") {
|
||||
all {
|
||||
// Configure "all"
|
||||
}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
# Project Configuration
|
||||
project.name=SweetProperty
|
||||
project.description=An easy get project properties anywhere Gradle plugin
|
||||
project.description=An easy get project properties anywhere Gradle plugin.
|
||||
project.url=https://github.com/HighCapable/SweetProperty
|
||||
project.groupName=com.highcapable.sweetproperty
|
||||
project.moduleName=sweet-property
|
||||
project.version=1.0.1
|
||||
project.version=1.0.3
|
||||
project.licence.name=Apache License 2.0
|
||||
project.licence.url=https://github.com/HighCapable/SweetProperty/blob/master/LICENSE
|
||||
project.developer.id=0
|
||||
project.developer.id="0"
|
||||
project.developer.name=fankes
|
||||
project.developer.email=qzmmcn@163.com
|
||||
# Gradle Plugin Configuration
|
||||
|
@@ -18,8 +18,14 @@ plugins:
|
||||
version: 0.25.3
|
||||
|
||||
libraries:
|
||||
com.squareup.okhttp3:
|
||||
okhttp:
|
||||
version: 4.11.0
|
||||
com.squareup:
|
||||
kotlinpoet:
|
||||
version: 1.14.2
|
||||
javapoet:
|
||||
version: 1.13.0
|
||||
version: 1.13.0
|
||||
net.lingala.zip4j:
|
||||
zip4j:
|
||||
version: 2.11.5
|
@@ -1,4 +1,3 @@
|
||||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
@@ -8,8 +7,8 @@ pluginManagement {
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
id("com.highcapable.sweetdependency") version "1.0.0"
|
||||
id("com.highcapable.sweetproperty") version "1.0.1"
|
||||
id("com.highcapable.sweetdependency") version "1.0.2"
|
||||
id("com.highcapable.sweetproperty") version "1.0.3"
|
||||
}
|
||||
sweetDependency {
|
||||
isEnableVerboseMode = false
|
||||
@@ -21,10 +20,7 @@ sweetProperty {
|
||||
isEnableRestrictedAccess = true
|
||||
}
|
||||
}
|
||||
rootProject { sourcesCode { isEnable = false } }
|
||||
project("sweetproperty-gradle-plugin") {
|
||||
buildScript { isEnableTypeAutoConversion = false }
|
||||
}
|
||||
rootProject { all { isEnable = false } }
|
||||
}
|
||||
rootProject.name = "SweetProperty"
|
||||
include(":sweetproperty-gradle-plugin")
|
@@ -21,8 +21,10 @@ kotlin {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(com.squareup.okhttp3.okhttp)
|
||||
implementation(com.squareup.kotlinpoet)
|
||||
implementation(com.squareup.javapoet)
|
||||
implementation(net.lingala.zip4j.zip4j)
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/25.
|
||||
* This file is created by fankes on 2023/8/25.
|
||||
*/
|
||||
package com.highcapable.sweetproperty
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/28.
|
||||
* This file is created by fankes on 2023/8/28.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.gradle.entity
|
||||
|
||||
@@ -43,11 +43,12 @@ internal class ProjectDescriptor private constructor() {
|
||||
* @return [ProjectDescriptor]
|
||||
*/
|
||||
internal fun create(settings: Settings, name: String = "") = ProjectDescriptor().also {
|
||||
val isRootProject = name.isBlank() || name == settings.rootProject.name
|
||||
val isRootProject = name.isBlank() || name.lowercase() == settings.rootProject.name.lowercase()
|
||||
val subProjectNotice = "if this is a sub-project, please set it like \":$name\""
|
||||
it.type = Type.SETTINGS
|
||||
it.name = name.noBlank() ?: settings.rootProject.name
|
||||
it.currentDir = (if (isRootProject) settings.rootProject else settings.findProject(":$name"))?.projectDir
|
||||
?: SError.make("Project \"$name\" not found")
|
||||
it.currentDir = (if (isRootProject) settings.rootProject else settings.findProject(name))?.projectDir
|
||||
?: SError.make("Project \"$name\" not found${if (name.startsWith(":").not()) ", $subProjectNotice" else ""}")
|
||||
it.rootDir = settings.rootDir
|
||||
it.homeDir = settings.gradle.gradleUserHomeDir
|
||||
}
|
||||
@@ -59,7 +60,7 @@ internal class ProjectDescriptor private constructor() {
|
||||
*/
|
||||
internal fun create(project: Project) = ProjectDescriptor().also {
|
||||
it.type = Type.PROJECT
|
||||
it.name = project.fullName
|
||||
it.name = project.fullName()
|
||||
it.currentDir = project.projectDir
|
||||
it.rootDir = project.rootDir
|
||||
it.homeDir = project.gradle.gradleUserHomeDir
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
@file:Suppress("unused", "USELESS_CAST", "KotlinRedundantDiagnosticSuppress")
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.gradle.factory
|
||||
|
||||
@@ -29,23 +29,23 @@ import org.gradle.kotlin.dsl.repositories
|
||||
|
||||
/**
|
||||
* 获取指定项目的完整名称
|
||||
* @param isUseColon 是否在子项目前使用冒号 - 默认是
|
||||
* @return [String]
|
||||
*/
|
||||
internal val Project.fullName
|
||||
get(): String {
|
||||
val baseNames = mutableListOf<String>()
|
||||
internal fun Project.fullName(isUseColon: Boolean = true): String {
|
||||
val isRoot = this == rootProject
|
||||
val baseNames = mutableListOf<String>()
|
||||
|
||||
/**
|
||||
* 递归子项目
|
||||
* @param project 当前项目
|
||||
*/
|
||||
fun fetchChild(project: Project) {
|
||||
project.parent?.also { if (it != it.rootProject) fetchChild(it) }
|
||||
baseNames.add(project.name)
|
||||
}
|
||||
fetchChild(project = this)
|
||||
return buildString { baseNames.onEach { append(":$it") }.clear() }.drop(1)
|
||||
}
|
||||
/**
|
||||
* 递归子项目
|
||||
* @param project 当前项目
|
||||
*/
|
||||
fun fetchChild(project: Project) {
|
||||
project.parent?.also { if (it != it.rootProject) fetchChild(it) }
|
||||
baseNames.add(project.name)
|
||||
}; fetchChild(project = this)
|
||||
return buildString { baseNames.onEach { append(":$it") }.clear() }.let { if (isUseColon && isRoot.not()) it else it.drop(1) }
|
||||
}
|
||||
|
||||
/**
|
||||
* 向构建脚本添加自定义依赖
|
||||
@@ -67,4 +67,4 @@ internal fun Project.addDependencyToBuildScript(repositoryPath: String, pomData:
|
||||
* @param name [Class] 完整名称
|
||||
* @return [Class]
|
||||
*/
|
||||
internal fun Project.loadBuildScriptClass(name: String) = buildscript.classLoader.loadClass(name)
|
||||
internal fun Project.loadBuildScriptClass(name: String) = runCatching { buildscript.classLoader.loadClass(name) }.getOrNull()
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.gradle.proxy
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.plugin
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.highcapable.sweetproperty.SweetProperty
|
||||
import com.highcapable.sweetproperty.gradle.factory.getOrCreate
|
||||
import com.highcapable.sweetproperty.gradle.proxy.IGradleLifecycle
|
||||
import com.highcapable.sweetproperty.plugin.extension.dsl.configure.SweetPropertyConfigureExtension
|
||||
import com.highcapable.sweetproperty.plugin.helper.PluginUpdateHelper
|
||||
import com.highcapable.sweetproperty.plugin.helper.PropertiesDeployHelper
|
||||
import com.highcapable.sweetproperty.utils.debug.SError
|
||||
import org.gradle.api.Project
|
||||
@@ -44,6 +45,7 @@ internal class SweetPropertyExtension internal constructor() : IGradleLifecycle
|
||||
|
||||
override fun onSettingsEvaluate(settings: Settings) {
|
||||
val configs = configure?.build(settings) ?: SError.make("Extension \"${SweetPropertyConfigureExtension.NAME}\" create failed")
|
||||
PluginUpdateHelper.checkingForUpdate(settings)
|
||||
PropertiesDeployHelper.initialize(settings, configs)
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/25.
|
||||
* This file is created by fankes on 2023/8/25.
|
||||
*/
|
||||
@file:Suppress("unused")
|
||||
|
||||
@@ -42,10 +42,10 @@ class SweetPropertyPlugin<T : ExtensionAware> internal constructor() : Plugin<T>
|
||||
extension.onSettingsLoaded(target)
|
||||
target.gradle.settingsEvaluated { extension.onSettingsEvaluate(target) }
|
||||
target.gradle.projectsLoaded {
|
||||
extension.onProjectLoaded(rootProject)
|
||||
rootProject.afterEvaluate { extension.onProjectEvaluate(rootProject) }
|
||||
rootProject.beforeEvaluate { extension.onProjectLoaded(rootProject = this) }
|
||||
rootProject.afterEvaluate { extension.onProjectEvaluate(rootProject = this) }
|
||||
}
|
||||
}
|
||||
else -> SError.make("${SweetProperty.TAG} can only applied in settings.gradle/settings.gradle.kts, but current is $target")
|
||||
else -> SError.make("${SweetProperty.TAG} can only applied in settings.gradle or settings.gradle.kts, but current is $target")
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,13 +17,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/28.
|
||||
* This file is created by fankes on 2023/8/28.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.plugin.config.default
|
||||
|
||||
import com.highcapable.sweetproperty.plugin.config.proxy.ISweetPropertyConfigs
|
||||
import com.highcapable.sweetproperty.plugin.extension.dsl.configure.SweetPropertyConfigureExtension
|
||||
import com.highcapable.sweetproperty.utils.noBlank
|
||||
import com.highcapable.sweetproperty.plugin.generator.factory.PropertyValueRule
|
||||
|
||||
/**
|
||||
* 默认配置类实现类
|
||||
@@ -63,10 +63,10 @@ internal object DefaultConfigs {
|
||||
get() = selfBase?.isEnable
|
||||
?: globalBase?.isEnable
|
||||
?: baseGenerateConfigs(name).isEnable
|
||||
override val propertiesFileName
|
||||
get() = selfBase?.propertiesFileName?.noBlank()
|
||||
?: globalBase?.propertiesFileName?.noBlank()
|
||||
?: baseGenerateConfigs(name).propertiesFileName
|
||||
override val propertiesFileNames
|
||||
get() = selfBase?.propertiesFileNames
|
||||
?: globalBase?.propertiesFileNames
|
||||
?: baseGenerateConfigs(name).propertiesFileNames
|
||||
override val permanentKeyValues
|
||||
get() = selfBase?.permanentKeyValues
|
||||
?: globalBase?.permanentKeyValues
|
||||
@@ -75,6 +75,14 @@ internal object DefaultConfigs {
|
||||
get() = selfBase?.excludeKeys
|
||||
?: globalBase?.excludeKeys
|
||||
?: baseGenerateConfigs(name).excludeKeys
|
||||
override val includeKeys
|
||||
get() = selfBase?.includeKeys
|
||||
?: globalBase?.includeKeys
|
||||
?: baseGenerateConfigs(name).includeKeys
|
||||
override val keyValuesRules
|
||||
get() = selfBase?.keyValuesRules
|
||||
?: globalBase?.keyValuesRules
|
||||
?: baseGenerateConfigs(name).keyValuesRules
|
||||
override val isEnableExcludeNonStringValue
|
||||
get() = selfBase?.isEnableExcludeNonStringValue
|
||||
?: globalBase?.isEnableExcludeNonStringValue
|
||||
@@ -111,10 +119,10 @@ internal object DefaultConfigs {
|
||||
get() = selfBase?.isEnable
|
||||
?: globalBase?.isEnable
|
||||
?: baseGenerateConfigs(name).isEnable
|
||||
override val propertiesFileName
|
||||
get() = selfBase?.propertiesFileName?.noBlank()
|
||||
?: globalBase?.propertiesFileName?.noBlank()
|
||||
?: baseGenerateConfigs(name).propertiesFileName
|
||||
override val propertiesFileNames
|
||||
get() = selfBase?.propertiesFileNames
|
||||
?: globalBase?.propertiesFileNames
|
||||
?: baseGenerateConfigs(name).propertiesFileNames
|
||||
override val permanentKeyValues
|
||||
get() = selfBase?.permanentKeyValues
|
||||
?: globalBase?.permanentKeyValues
|
||||
@@ -123,6 +131,14 @@ internal object DefaultConfigs {
|
||||
get() = selfBase?.excludeKeys
|
||||
?: globalBase?.excludeKeys
|
||||
?: baseGenerateConfigs(name).excludeKeys
|
||||
override val includeKeys
|
||||
get() = selfBase?.includeKeys
|
||||
?: globalBase?.includeKeys
|
||||
?: baseGenerateConfigs(name).includeKeys
|
||||
override val keyValuesRules
|
||||
get() = selfBase?.keyValuesRules
|
||||
?: globalBase?.keyValuesRules
|
||||
?: baseGenerateConfigs(name).keyValuesRules
|
||||
override val isEnableExcludeNonStringValue
|
||||
get() = selfBase?.isEnableExcludeNonStringValue
|
||||
?: globalBase?.isEnableExcludeNonStringValue
|
||||
@@ -149,9 +165,11 @@ internal object DefaultConfigs {
|
||||
private fun baseGenerateConfigs(name: String) = object : ISweetPropertyConfigs.IBaseGenerateConfigs {
|
||||
override val name get() = name
|
||||
override val isEnable get() = true
|
||||
override val propertiesFileName get() = ISweetPropertyConfigs.DEFAULT_PROPERTIES_FILE_NAME
|
||||
override val propertiesFileNames get() = mutableListOf(ISweetPropertyConfigs.DEFAULT_PROPERTIES_FILE_NAME)
|
||||
override val permanentKeyValues get() = mutableMapOf<String, Any>()
|
||||
override val excludeKeys get() = mutableListOf<Any>()
|
||||
override val includeKeys get() = mutableListOf<Any>()
|
||||
override val keyValuesRules get() = mutableMapOf<String, PropertyValueRule>()
|
||||
override val isEnableExcludeNonStringValue get() = true
|
||||
override val isEnableTypeAutoConversion get() = true
|
||||
override val isEnableValueInterpolation get() = true
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/28.
|
||||
* This file is created by fankes on 2023/8/28.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.plugin.config.factory
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.gradle.api.Project
|
||||
* @param project 当前项目
|
||||
* @return [ISweetPropertyConfigs.ISubConfigs]
|
||||
*/
|
||||
internal fun ISweetPropertyConfigs.with(project: Project) = projects[project.fullName] ?: global
|
||||
internal fun ISweetPropertyConfigs.with(project: Project) = projects[project.fullName()] ?: global
|
||||
|
||||
/**
|
||||
* 创建 [ISweetPropertyConfigs.ISubConfigs] 实例
|
||||
@@ -47,12 +47,12 @@ internal fun SweetPropertyConfigureExtension.SubConfigureExtension.create(
|
||||
) = object : ISweetPropertyConfigs.ISubConfigs {
|
||||
override val sourcesCode
|
||||
get() = this@create.sourcesCodeConfigure?.create(name, global.sourcesCodeConfigure, this@create.allConfigure, global.allConfigure)
|
||||
?: global.sourcesCodeConfigure?.create(name, globalBase = global.allConfigure)
|
||||
?: DefaultConfigs.subConfigs(name, global.allConfigure).sourcesCode
|
||||
?: global.sourcesCodeConfigure?.create(name, globalBase = this@create.allConfigure ?: global.allConfigure)
|
||||
?: DefaultConfigs.subConfigs(name, base = this@create.allConfigure ?: global.allConfigure).sourcesCode
|
||||
override val buildScript
|
||||
get() = this@create.buildScriptConfigure?.create(name, global.buildScriptConfigure, this@create.allConfigure, global.allConfigure)
|
||||
?: global.buildScriptConfigure?.create(name, globalBase = global.allConfigure)
|
||||
?: DefaultConfigs.subConfigs(name, global.allConfigure).buildScript
|
||||
?: global.buildScriptConfigure?.create(name, globalBase = this@create.allConfigure ?: global.allConfigure)
|
||||
?: DefaultConfigs.subConfigs(name, base = this@create.allConfigure ?: global.allConfigure).buildScript
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,10 +92,10 @@ private fun SweetPropertyConfigureExtension.SourcesCodeGenerateConfigureExtensio
|
||||
?: global?.isEnable
|
||||
?: globalBase?.isEnable
|
||||
?: DefaultConfigs.sourcesCodeGenerateConfigs(name, selfBase, globalBase).isEnable
|
||||
override val propertiesFileName
|
||||
get() = this@create.propertiesFileName.noBlank()
|
||||
?: global?.propertiesFileName?.noBlank()
|
||||
?: DefaultConfigs.sourcesCodeGenerateConfigs(name, selfBase, globalBase).propertiesFileName
|
||||
override val propertiesFileNames
|
||||
get() = this@create.propertiesFileNames
|
||||
?: global?.propertiesFileNames
|
||||
?: DefaultConfigs.sourcesCodeGenerateConfigs(name, selfBase, globalBase).propertiesFileNames
|
||||
override val permanentKeyValues
|
||||
get() = this@create.permanentKeyValues
|
||||
?: global?.permanentKeyValues
|
||||
@@ -104,6 +104,14 @@ private fun SweetPropertyConfigureExtension.SourcesCodeGenerateConfigureExtensio
|
||||
get() = this@create.excludeKeys
|
||||
?: global?.excludeKeys
|
||||
?: DefaultConfigs.sourcesCodeGenerateConfigs(name, selfBase, globalBase).excludeKeys
|
||||
override val includeKeys
|
||||
get() = this@create.includeKeys
|
||||
?: global?.includeKeys
|
||||
?: DefaultConfigs.sourcesCodeGenerateConfigs(name, selfBase, globalBase).includeKeys
|
||||
override val keyValuesRules
|
||||
get() = this@create.keyValuesRules
|
||||
?: global?.keyValuesRules
|
||||
?: DefaultConfigs.sourcesCodeGenerateConfigs(name, selfBase, globalBase).keyValuesRules
|
||||
override val isEnableExcludeNonStringValue
|
||||
get() = this@create.isEnableExcludeNonStringValue
|
||||
?: selfBase?.isEnableExcludeNonStringValue
|
||||
@@ -155,10 +163,10 @@ private fun SweetPropertyConfigureExtension.BuildScriptGenerateConfigureExtensio
|
||||
?: global?.isEnable
|
||||
?: globalBase?.isEnable
|
||||
?: DefaultConfigs.buildScriptGenerateConfigs(name, selfBase, globalBase).isEnable
|
||||
override val propertiesFileName
|
||||
get() = this@create.propertiesFileName.noBlank()
|
||||
?: global?.propertiesFileName?.noBlank()
|
||||
?: DefaultConfigs.buildScriptGenerateConfigs(name, selfBase, globalBase).propertiesFileName
|
||||
override val propertiesFileNames
|
||||
get() = this@create.propertiesFileNames
|
||||
?: global?.propertiesFileNames
|
||||
?: DefaultConfigs.buildScriptGenerateConfigs(name, selfBase, globalBase).propertiesFileNames
|
||||
override val permanentKeyValues
|
||||
get() = this@create.permanentKeyValues
|
||||
?: global?.permanentKeyValues
|
||||
@@ -167,6 +175,14 @@ private fun SweetPropertyConfigureExtension.BuildScriptGenerateConfigureExtensio
|
||||
get() = this@create.excludeKeys
|
||||
?: global?.excludeKeys
|
||||
?: DefaultConfigs.buildScriptGenerateConfigs(name, selfBase, globalBase).excludeKeys
|
||||
override val includeKeys
|
||||
get() = this@create.includeKeys
|
||||
?: global?.includeKeys
|
||||
?: DefaultConfigs.buildScriptGenerateConfigs(name, selfBase, globalBase).includeKeys
|
||||
override val keyValuesRules
|
||||
get() = this@create.keyValuesRules
|
||||
?: global?.keyValuesRules
|
||||
?: DefaultConfigs.buildScriptGenerateConfigs(name, selfBase, globalBase).keyValuesRules
|
||||
override val isEnableExcludeNonStringValue
|
||||
get() = this@create.isEnableExcludeNonStringValue
|
||||
?: selfBase?.isEnableExcludeNonStringValue
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,13 +17,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/25.
|
||||
* This file is created by fankes on 2023/8/25.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.plugin.config.proxy
|
||||
|
||||
import com.highcapable.sweetproperty.SweetProperty
|
||||
import com.highcapable.sweetproperty.generated.SweetPropertyProperties
|
||||
import com.highcapable.sweetproperty.plugin.config.type.GenerateLocationType
|
||||
import com.highcapable.sweetproperty.plugin.generator.factory.PropertyValueRule
|
||||
|
||||
/**
|
||||
* [SweetProperty] 配置类接口类
|
||||
@@ -120,8 +121,8 @@ internal interface ISweetPropertyConfigs {
|
||||
/** 是否为当前功能生成代码 */
|
||||
val isEnable: Boolean
|
||||
|
||||
/** 属性配置文件名称 */
|
||||
val propertiesFileName: String
|
||||
/** 属性配置文件名称数组 */
|
||||
val propertiesFileNames: MutableList<String>
|
||||
|
||||
/** 固定存在的属性键值数组 */
|
||||
val permanentKeyValues: MutableMap<String, Any>
|
||||
@@ -129,6 +130,12 @@ internal interface ISweetPropertyConfigs {
|
||||
/** 被排除的属性键值名称数组 */
|
||||
val excludeKeys: MutableList<Any>
|
||||
|
||||
/** 被包含的属性键值名称数组 */
|
||||
val includeKeys: MutableList<Any>
|
||||
|
||||
/** 属性键值规则数组 */
|
||||
val keyValuesRules: MutableMap<String, PropertyValueRule>
|
||||
|
||||
/** 是否启用排除非字符串类型键值内容 */
|
||||
val isEnableExcludeNonStringValue: Boolean
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/25.
|
||||
* This file is created by fankes on 2023/8/25.
|
||||
*/
|
||||
@file:Suppress("unused")
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.plugin.extension.accessors.proxy
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,9 +17,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/25.
|
||||
* This file is created by fankes on 2023/8/25.
|
||||
*/
|
||||
@file:Suppress("unused", "MemberVisibilityCanBePrivate", "PropertyName")
|
||||
@file:Suppress("unused", "MemberVisibilityCanBePrivate", "PropertyName", "DeprecatedCallableAddReplaceWith")
|
||||
|
||||
package com.highcapable.sweetproperty.plugin.extension.dsl.configure
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.highcapable.sweetproperty.gradle.factory.isUnSafeExtName
|
||||
import com.highcapable.sweetproperty.plugin.config.factory.create
|
||||
import com.highcapable.sweetproperty.plugin.config.proxy.ISweetPropertyConfigs
|
||||
import com.highcapable.sweetproperty.plugin.config.type.GenerateLocationType
|
||||
import com.highcapable.sweetproperty.plugin.generator.factory.PropertyValueRule
|
||||
import com.highcapable.sweetproperty.utils.debug.SError
|
||||
import com.highcapable.sweetproperty.utils.noEmpty
|
||||
import org.gradle.api.Action
|
||||
@@ -91,14 +92,22 @@ open class SweetPropertyConfigureExtension internal constructor() {
|
||||
* 配置根项目
|
||||
* @param action 配置方法体
|
||||
*/
|
||||
fun rootProject(action: Action<SubConfigureExtension>) = project(ROOT_PROJECT_TAG, action)
|
||||
fun rootProject(action: Action<SubConfigureExtension>) = configureProject(ROOT_PROJECT_TAG, action)
|
||||
|
||||
/**
|
||||
* 配置指定项目
|
||||
* @param name 项目完整名称
|
||||
* @param action 配置方法体
|
||||
*/
|
||||
fun project(name: String, action: Action<SubConfigureExtension>) = action.execute(SubConfigureExtension().also { projectConfigures[name] = it })
|
||||
fun project(name: String, action: Action<SubConfigureExtension>) = configureProject(name, action)
|
||||
|
||||
/**
|
||||
* 配置项目
|
||||
* @param name 项目完整名称
|
||||
* @param action 配置方法体
|
||||
*/
|
||||
private fun configureProject(name: String, action: Action<SubConfigureExtension>) =
|
||||
action.execute(SubConfigureExtension().also { projectConfigures[name] = it })
|
||||
|
||||
/**
|
||||
* 子配置方法体实现类
|
||||
@@ -114,6 +123,16 @@ open class SweetPropertyConfigureExtension internal constructor() {
|
||||
/** 当前构建脚本生成代码功能配置实例 */
|
||||
internal var buildScriptConfigure: BuildScriptGenerateConfigureExtension? = null
|
||||
|
||||
/**
|
||||
* 错误的调用会导致关闭整个插件的功能
|
||||
*
|
||||
* 请使用 [all]、[sourcesCode]、[buildScript]
|
||||
* @throws [IllegalStateException]
|
||||
*/
|
||||
@Deprecated(message = "Do not use", level = DeprecationLevel.ERROR)
|
||||
val isEnable: Boolean
|
||||
get() = SError.make("Please called all { isEnable = ... }, sourcesCode { isEnable = ... }, buildScript { isEnable = ... }")
|
||||
|
||||
/**
|
||||
* 配置通用生成代码功能
|
||||
* @param action 配置方法体
|
||||
@@ -200,12 +219,21 @@ open class SweetPropertyConfigureExtension internal constructor() {
|
||||
*/
|
||||
open inner class BaseGenerateConfigureExtension internal constructor() {
|
||||
|
||||
/** 当前属性配置文件路径数组 */
|
||||
internal var propertiesFileNames: MutableList<String>? = null
|
||||
|
||||
/** 当前固定存在的属性键值数组 */
|
||||
internal var permanentKeyValues: MutableMap<String, Any>? = null
|
||||
|
||||
/** 当前被排除的属性键值名称数组 */
|
||||
internal var excludeKeys: MutableList<Any>? = null
|
||||
|
||||
/** 当前被包含的属性键值名称数组 */
|
||||
internal var includeKeys: MutableList<Any>? = null
|
||||
|
||||
/** 当前属性键值规则数组 */
|
||||
internal var keyValuesRules: MutableMap<String, PropertyValueRule>? = null
|
||||
|
||||
/** 当前生成位置类型数组 */
|
||||
internal var generateLocationTypes: Array<GenerateLocationType>? = null
|
||||
|
||||
@@ -226,10 +254,11 @@ open class SweetPropertyConfigureExtension internal constructor() {
|
||||
/**
|
||||
* 设置属性配置文件名称
|
||||
*
|
||||
* 默认为 [ISweetPropertyConfigs.DEFAULT_PROPERTIES_FILE_NAME]
|
||||
* - 此方法已弃用 - 在之后的版本中将直接被删除
|
||||
*
|
||||
* - 注意:一般情况下不需要修改此设置 - 错误的文件名将导致获取到空键值内容
|
||||
* - 请现在迁移到 [propertiesFileNames]
|
||||
*/
|
||||
@Deprecated(message = "Migrate to propertiesFileNames(...)")
|
||||
var propertiesFileName = ""
|
||||
@JvmName("propertiesFileName") set
|
||||
|
||||
@@ -263,6 +292,27 @@ open class SweetPropertyConfigureExtension internal constructor() {
|
||||
var isEnableValueInterpolation: Boolean? = null
|
||||
@JvmName("enableValueInterpolation") set
|
||||
|
||||
/**
|
||||
* 设置属性配置文件名称数组
|
||||
*
|
||||
* 属性配置文件将根据你设置的文件名称自动从当前根项目、子项目以及用户目录的根目录进行获取
|
||||
*
|
||||
* 默认为 [ISweetPropertyConfigs.DEFAULT_PROPERTIES_FILE_NAME]
|
||||
*
|
||||
* 你可以添加多组属性配置文件名称 - 将按照顺序依次进行读取
|
||||
*
|
||||
* - 注意:一般情况下不需要修改此设置 - 错误的文件名称将导致获取到空键值内容
|
||||
* @param names 要添加的属性配置文件名称数组
|
||||
* @param isAddDefault 是否添加默认的属性配置文件名称 - 默认是
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun propertiesFileNames(vararg names: String, isAddDefault: Boolean = true) {
|
||||
if (names.isEmpty()) SError.make("Properties file names must not be empty")
|
||||
if (names.any { it.isBlank() }) SError.make("Properties file names must not have blank contents")
|
||||
propertiesFileNames = names.distinct().toMutableList()
|
||||
if (isAddDefault) propertiesFileNames?.add(0, ISweetPropertyConfigs.DEFAULT_PROPERTIES_FILE_NAME)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置固定存在的属性键值数组
|
||||
*
|
||||
@@ -313,6 +363,65 @@ open class SweetPropertyConfigureExtension internal constructor() {
|
||||
excludeKeys = keys.distinct().toMutableList()
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置需要包含的属性键值名称数组
|
||||
*
|
||||
* 在这里可以设置一些你希望从已知的属性键值中包含的键值名称
|
||||
*
|
||||
* 这些键值在属性键值存在它们时被包含 - 未被包含的键值不会出现在生成的代码中
|
||||
* @param keys 键值名称数组 - 你可以传入 [Regex] 或使用 [String.toRegex] 以使用正则功能
|
||||
*/
|
||||
fun includeKeys(vararg keys: Any) {
|
||||
if (keys.isEmpty()) SError.make("Include keys must not be empty")
|
||||
if (keys.any { it.toString().isBlank() }) SError.make("Include keys must not have blank contents")
|
||||
includeKeys = keys.distinct().toMutableList()
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置属性键值规则数组
|
||||
*
|
||||
* 你可以设置一组键值规则 - 使用 [createValueRule] 创建新的规则 - 用于解析得到的键值内容
|
||||
*
|
||||
* 示例如下 ↓
|
||||
*
|
||||
* ```kotlin
|
||||
* keyValuesRules(
|
||||
* "some.key1" to createValueRule { if (it.contains("_")) it.replace("_", "-") else it },
|
||||
* "some.key2" to createValueRule { "$it-value" }
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* 这些键值规则在属性键值存在它们时被应用
|
||||
* @param pairs 属性键值规则数组
|
||||
*/
|
||||
@JvmName("-kotlin-dsl-only-keyValuesRules-")
|
||||
fun keyValuesRules(vararg pairs: Pair<String, PropertyValueRule>) {
|
||||
if (pairs.isEmpty()) SError.make("Key-values rules must not be empty")
|
||||
if (pairs.any { it.first.isBlank() }) SError.make("Key-values rules must not have blank contents")
|
||||
keyValuesRules = mutableMapOf(*pairs)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置属性键值规则数组 (Groovy 兼容方法)
|
||||
*
|
||||
* 你可以设置一组键值规则 - 使用 [createValueRule] 创建新的规则 - 用于解析得到的键值内容
|
||||
*
|
||||
* 这些键值规则在属性键值存在它们时被应用
|
||||
* @param rules 属性键值规则数组
|
||||
*/
|
||||
fun keyValuesRules(rules: Map<String, PropertyValueRule>) {
|
||||
if (rules.isEmpty()) SError.make("Key-values rules must not be empty")
|
||||
if (rules.any { it.key.isBlank() }) SError.make("Key-values rules must not have blank contents")
|
||||
keyValuesRules = rules.toMutableMap()
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新的属性键值规则
|
||||
* @param rule 回调当前规则
|
||||
* @return [PropertyValueRule]
|
||||
*/
|
||||
fun createValueRule(rule: PropertyValueRule) = rule
|
||||
|
||||
/**
|
||||
* 设置从何处生成属性键值
|
||||
*
|
||||
@@ -392,14 +501,14 @@ open class SweetPropertyConfigureExtension internal constructor() {
|
||||
val currentGlobal = globalConfigure.create()
|
||||
val currentProjects = mutableMapOf<String, ISweetPropertyConfigs.ISubConfigs>()
|
||||
val rootName = settings.rootProject.name
|
||||
if (projectConfigures.containsKey(rootName))
|
||||
if (projectConfigures.any { (name, _) -> name.lowercase() == rootName.lowercase() })
|
||||
SError.make("This name \"$rootName\" is a root project, please use rootProject function to configure it, not project(\"$rootName\")")
|
||||
if (projectConfigures.containsKey(ROOT_PROJECT_TAG)) {
|
||||
projectConfigures[rootName] = projectConfigures[ROOT_PROJECT_TAG] ?: SError.make("Internal error")
|
||||
projectConfigures.remove(ROOT_PROJECT_TAG)
|
||||
}
|
||||
projectConfigures.forEach { (name, subConfigure) ->
|
||||
name.checkingStartWithLetter(description = "Project")
|
||||
name.replaceFirst(":", "").checkingStartWithLetter(description = "Project")
|
||||
subConfigure.checkingNames()
|
||||
currentProjects[name] = subConfigure.create(name, globalConfigure)
|
||||
}; return object : ISweetPropertyConfigs {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.plugin.generator
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.plugin.generator
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.plugin.generator.factory
|
||||
|
||||
@@ -26,6 +26,9 @@ import kotlin.reflect.KClass
|
||||
/** 属性键值数组类型定义 */
|
||||
internal typealias PropertyMap = MutableMap<String, Any>
|
||||
|
||||
/** 属性键值规则类型定义 */
|
||||
internal typealias PropertyValueRule = (value: String) -> String
|
||||
|
||||
/**
|
||||
* 解析到键值内容类型
|
||||
* @param isAutoConversion 是否自动转换类型
|
||||
|
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
* Apache License Version 2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is created by fankes on 2023/9/26.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.plugin.helper
|
||||
|
||||
import com.highcapable.sweetproperty.SweetProperty
|
||||
import com.highcapable.sweetproperty.generated.SweetPropertyProperties
|
||||
import com.highcapable.sweetproperty.utils.debug.SLog
|
||||
import com.highcapable.sweetproperty.utils.executeUrlBody
|
||||
import org.gradle.api.initialization.Settings
|
||||
import org.xml.sax.InputSource
|
||||
import java.io.StringReader
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
|
||||
/**
|
||||
* 插件自身检查更新工具类
|
||||
*/
|
||||
internal object PluginUpdateHelper {
|
||||
|
||||
/** OSS Release URL 地址 */
|
||||
private const val SONATYPE_OSS_RELEASES_URL = "https://s01.oss.sonatype.org/content/repositories/releases"
|
||||
|
||||
/** 依赖配置文件名 */
|
||||
private const val METADATA_FILE_NAME = "maven-metadata.xml"
|
||||
|
||||
/** 插件自身依赖 URL 名称 */
|
||||
private val groupUrlNotation =
|
||||
"${SweetPropertyProperties.PROJECT_GROUP_NAME.replace(".","/")}/${SweetPropertyProperties.GRADLE_PLUGIN_MODULE_NAME}"
|
||||
|
||||
/** 检查更新 URL 地址 */
|
||||
private val releaseUrl = "$SONATYPE_OSS_RELEASES_URL/$groupUrlNotation/$METADATA_FILE_NAME"
|
||||
|
||||
/**
|
||||
* 检查更新
|
||||
* @param settings 当前设置
|
||||
*/
|
||||
internal fun checkingForUpdate(settings: Settings) {
|
||||
if (settings.gradle.startParameter.isOffline) return
|
||||
val latestVersion = releaseUrl.executeUrlBody(isShowFailure = false).trim().findLatest()
|
||||
if (latestVersion.isNotBlank() && latestVersion != SweetProperty.VERSION) SLog.note(
|
||||
"""
|
||||
Plugin update is available, the current version is ${SweetProperty.VERSION}, please update to $latestVersion
|
||||
You can modify your plugin version in your project's settings.gradle or settings.gradle.kts
|
||||
plugins {
|
||||
id("${SweetPropertyProperties.PROJECT_GROUP_NAME}") version "$latestVersion"
|
||||
...
|
||||
}
|
||||
For more information, you can visit ${SweetProperty.PROJECT_URL}
|
||||
""".trimIndent(), SLog.UP
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 [METADATA_FILE_NAME] 内容并获取 "latest"
|
||||
* @return [String]
|
||||
*/
|
||||
private fun String.findLatest() = runCatching {
|
||||
if ((contains("<metadata ") || contains("<metadata>")).not() || endsWith("</metadata>").not()) return@runCatching ""
|
||||
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(InputSource(StringReader(this))).let { document ->
|
||||
document.getElementsByTagName("latest")?.let { if (it.length > 0) it.item(0)?.textContent ?: "" else "" }
|
||||
}
|
||||
}.getOrNull() ?: ""
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/30.
|
||||
* This file is created by fankes on 2023/8/30.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.plugin.helper
|
||||
|
||||
@@ -45,8 +45,8 @@ import com.highcapable.sweetproperty.utils.hasInterpolation
|
||||
import com.highcapable.sweetproperty.utils.isEmpty
|
||||
import com.highcapable.sweetproperty.utils.noBlank
|
||||
import com.highcapable.sweetproperty.utils.noEmpty
|
||||
import com.highcapable.sweetproperty.utils.parseFileSeparator
|
||||
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
|
||||
@@ -156,7 +156,10 @@ internal object PropertiesDeployHelper {
|
||||
allProperties.add(generatedProperties(subConfigs.buildScript, ProjectDescriptor.create(settings, name)))
|
||||
allConfigs.add(subConfigs.buildScript)
|
||||
}
|
||||
if (isConfigsModified.not() && allProperties == cachedSettingsProperties && accessorsDir.isEmpty().not()) return
|
||||
if (isConfigsModified.not() &&
|
||||
allProperties == cachedSettingsProperties &&
|
||||
accessorsDir.resolve(accessorsPomData.relativePomPath).isEmpty().not()
|
||||
) return
|
||||
cachedSettingsProperties = allProperties
|
||||
accessorsGenerator.build(allConfigs, allProperties).compile(accessorsPomData, accessorsDir.absolutePath, accessorsGenerator.compileStubFiles)
|
||||
}
|
||||
@@ -166,7 +169,8 @@ internal object PropertiesDeployHelper {
|
||||
* @param rootProject 当前根项目
|
||||
*/
|
||||
private fun resolveAccessors(rootProject: Project) {
|
||||
if (accessorsDir.isEmpty().not()) rootProject.addDependencyToBuildScript(accessorsDir.absolutePath, accessorsPomData)
|
||||
if (accessorsDir.resolve(accessorsPomData.relativePomPath).isEmpty().not())
|
||||
rootProject.addDependencyToBuildScript(accessorsDir.absolutePath, accessorsPomData)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +182,15 @@ internal object PropertiesDeployHelper {
|
||||
fun Project.deploy() {
|
||||
val configs = configs.with(this).buildScript
|
||||
if (configs.isEnable.not()) return
|
||||
getOrCreate(configs.extensionName.camelcase(), loadBuildScriptClass(accessorsGenerator.propertiesClass(configs.name)))
|
||||
val className = accessorsGenerator.propertiesClass(configs.name)
|
||||
val accessorsClass = loadBuildScriptClass(className) ?: SError.make(
|
||||
"""
|
||||
Generated class "$className" not found, stop loading $this
|
||||
Please check whether the initialization process is interrupted and re-run Gradle Sync
|
||||
If this doesn't work, please manually delete the entire "${accessorsDir.absolutePath}" directory
|
||||
""".trimIndent()
|
||||
)
|
||||
getOrCreate(configs.extensionName.camelcase(), accessorsClass)
|
||||
}
|
||||
rootProject.deploy()
|
||||
rootProject.subprojects.forEach { it.deploy() }
|
||||
@@ -195,11 +207,11 @@ internal object PropertiesDeployHelper {
|
||||
val outputDir = file(configs.generateDirPath)
|
||||
if (configs.isEnable.not()) return
|
||||
val properties = generatedProperties(configs, ProjectDescriptor.create(project = this))
|
||||
if (isConfigsModified.not() && properties == cachedProjectProperties[fullName] && outputDir.isEmpty().not()) {
|
||||
if (isConfigsModified.not() && properties == cachedProjectProperties[fullName()] && outputDir.isEmpty().not()) {
|
||||
if (configs.isEnable) configureSourceSets(project = this)
|
||||
return
|
||||
}; outputDir.apply { if (exists()) deleteRecursively() }
|
||||
cachedProjectProperties[fullName] = properties
|
||||
cachedProjectProperties[fullName()] = properties
|
||||
val packageName = generatedPackageName(configs, project = this)
|
||||
val className = generatedClassName(configs, project = this)
|
||||
sourcesGenerator.build(configs, properties, packageName, className).writeTo(outputDir)
|
||||
@@ -244,43 +256,52 @@ internal object PropertiesDeployHelper {
|
||||
val propteries = mutableMapOf<String, Any>()
|
||||
configs.permanentKeyValues.forEach { (key, value) -> propteries[key] = value }
|
||||
configs.generateLocationTypes.forEach {
|
||||
val nativeKeyValues = when (it) {
|
||||
GenerateLocationType.CURRENT_PROJECT -> createProperties(configs, descriptor.currentDir)
|
||||
GenerateLocationType.ROOT_PROJECT -> createProperties(configs, descriptor.rootDir)
|
||||
GenerateLocationType.GLOBAL -> createProperties(configs, descriptor.homeDir)
|
||||
GenerateLocationType.SYSTEM -> System.getProperties()
|
||||
GenerateLocationType.SYSTEM_ENV -> System.getenv()
|
||||
} ?: emptyMap()
|
||||
val resolveKeyValues = mutableMapOf<String, Any>()
|
||||
nativeKeyValues.forEach native@{ (key, value) ->
|
||||
val hasExcludeKeys = configs.excludeKeys.noEmpty()?.any { content ->
|
||||
when (content) {
|
||||
is Regex -> content.toString().isNotBlank() && content.matches(key.toString())
|
||||
else -> content.toString() == key
|
||||
}
|
||||
} ?: false
|
||||
if (hasExcludeKeys) return@native
|
||||
val isAvailableKeyValue = if (configs.isEnableExcludeNonStringValue)
|
||||
mutableMapOf<Any?, Any?>().apply {
|
||||
when (it) {
|
||||
GenerateLocationType.CURRENT_PROJECT -> createProperties(configs, descriptor.currentDir).forEach { putAll(it) }
|
||||
GenerateLocationType.ROOT_PROJECT -> createProperties(configs, descriptor.rootDir).forEach { putAll(it) }
|
||||
GenerateLocationType.GLOBAL -> createProperties(configs, descriptor.homeDir).forEach { putAll(it) }
|
||||
GenerateLocationType.SYSTEM -> putAll(System.getProperties())
|
||||
GenerateLocationType.SYSTEM_ENV -> putAll(System.getenv())
|
||||
}
|
||||
}.filter { (key, value) ->
|
||||
if (configs.isEnableExcludeNonStringValue)
|
||||
key is CharSequence && key.isNotBlank() && value is CharSequence
|
||||
else key.toString().isNotBlank() && value != null
|
||||
if (isAvailableKeyValue) resolveKeyValues[key.toString()] = value
|
||||
}
|
||||
resolveKeyValues.forEach { (key, value) ->
|
||||
val resolveKeys = mutableListOf<String>()
|
||||
}.toStringMap().filter { (key, _) ->
|
||||
configs.includeKeys.noEmpty()?.any { content ->
|
||||
when (content) {
|
||||
is Regex -> content.matches(key)
|
||||
else -> content.toString() == key
|
||||
}
|
||||
} ?: true
|
||||
}.filter { (key, _) ->
|
||||
configs.excludeKeys.noEmpty()?.none { content ->
|
||||
when (content) {
|
||||
is Regex -> content.matches(key)
|
||||
else -> content.toString() == key
|
||||
}
|
||||
} ?: true
|
||||
}.toMutableMap().also { resolveKeyValues ->
|
||||
resolveKeyValues.onEach { (key, value) ->
|
||||
val resolveKeys = mutableListOf<String>()
|
||||
|
||||
/**
|
||||
* 处理键值内容
|
||||
* @return [String]
|
||||
*/
|
||||
fun String.resolveValue(): String = replaceInterpolation { matchKey ->
|
||||
if (resolveKeys.size > 5) SError.make("Key \"$key\" has been called recursively multiple times of those $resolveKeys")
|
||||
resolveKeys.add(matchKey)
|
||||
val resolveValue = if (configs.isEnableValueInterpolation) resolveKeyValues[matchKey]?.toString() ?: "" else matchKey
|
||||
if (resolveValue.hasInterpolation()) resolveValue.resolveValue()
|
||||
else resolveValue
|
||||
}
|
||||
if (value.toString().hasInterpolation()) resolveKeyValues[key] = value.toString().resolveValue()
|
||||
}; propteries.putAll(resolveKeyValues)
|
||||
/**
|
||||
* 处理键值内容
|
||||
* @return [String]
|
||||
*/
|
||||
fun String.resolveValue(): String = replaceInterpolation { matchKey ->
|
||||
if (resolveKeys.size > 5) SError.make("Key \"$key\" has been called recursively multiple times of those $resolveKeys")
|
||||
resolveKeys.add(matchKey)
|
||||
val resolveValue = if (configs.isEnableValueInterpolation) resolveKeyValues[matchKey] ?: "" else matchKey
|
||||
if (resolveValue.hasInterpolation()) resolveValue.resolveValue()
|
||||
else resolveValue
|
||||
}
|
||||
if (value.hasInterpolation()) resolveKeyValues[key] = value.resolveValue()
|
||||
}.takeIf { configs.keyValuesRules.isNotEmpty() }?.forEach { (key, value) ->
|
||||
configs.keyValuesRules[key]?.also { resolveKeyValues[key] = it(value) }
|
||||
}; propteries.putAll(resolveKeyValues)
|
||||
}
|
||||
}; return propteries
|
||||
}
|
||||
|
||||
@@ -302,7 +323,7 @@ internal object PropertiesDeployHelper {
|
||||
val packageName = configs.packageName.noBlank()
|
||||
?: project.namespace()
|
||||
?: project.group.toString().noBlank()
|
||||
?: "$DEFAULT_PACKAGE_NAME.${project.fullName.replace(":", "").flatted()}"
|
||||
?: "$DEFAULT_PACKAGE_NAME.${project.fullName(isUseColon = false).replace(":", "").flatted()}"
|
||||
return "$packageName.generated"
|
||||
}
|
||||
|
||||
@@ -314,18 +335,23 @@ internal object PropertiesDeployHelper {
|
||||
*/
|
||||
private fun generatedClassName(configs: ISweetPropertyConfigs.ISourcesCodeGenerateConfigs, project: Project): String {
|
||||
val className = configs.className.noBlank()
|
||||
?: project.fullName.replace(":", "_").uppercamelcase().noBlank()
|
||||
?: project.fullName(isUseColon = false).replace(":", "_").uppercamelcase().noBlank()
|
||||
?: "Undefined"
|
||||
return "${className.uppercamelcase()}Properties"
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新的 [Properties]
|
||||
* 创建新的 [Properties] 数组
|
||||
* @param configs 当前配置
|
||||
* @param dir 当前目录
|
||||
* @return [Properties] or null
|
||||
* @return [MutableList]<[Properties]>
|
||||
*/
|
||||
private fun createProperties(configs: ISweetPropertyConfigs.IBaseGenerateConfigs, dir: File?) = runCatching {
|
||||
Properties().apply { load(FileReader(dir?.resolve(configs.propertiesFileName)?.absolutePath?.parseFileSeparator() ?: "")) }
|
||||
}.getOrNull()
|
||||
mutableListOf<Properties>().apply {
|
||||
configs.propertiesFileNames.forEach {
|
||||
val propertiesFile = dir?.resolve(it)
|
||||
if (propertiesFile?.exists() == true) add(Properties().apply { load(FileReader(propertiesFile.absolutePath)) })
|
||||
}
|
||||
}
|
||||
}.getOrNull() ?: mutableListOf()
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
@file:Suppress("unused")
|
||||
|
||||
|
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
* Apache License Version 2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is created by fankes on 2023/9/26.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.utils
|
||||
|
||||
import com.highcapable.sweetproperty.utils.debug.SError
|
||||
import com.highcapable.sweetproperty.utils.debug.SLog
|
||||
import okhttp3.Credentials
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* 获取当前 URL 地址的请求体字符串内容 (GET) (同步)
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @param isShowFailure 是否显示错误 - 默认是
|
||||
* @return [String]
|
||||
*/
|
||||
internal fun String.executeUrlBody(username: String = "", password: String = "", isShowFailure: Boolean = true) = runCatching {
|
||||
OkHttpClient()
|
||||
.newBuilder()
|
||||
.connectTimeout(10000, TimeUnit.MILLISECONDS)
|
||||
.authenticator { _, response ->
|
||||
if (response.code == 400 || response.code == 401)
|
||||
response.request.newBuilder()
|
||||
.header("Authorization", Credentials.basic(username, password))
|
||||
.build()
|
||||
else null
|
||||
}.build().newCall(
|
||||
Request.Builder().url(when {
|
||||
startsWith("https://") -> "https://" + replace("https://", "").replace("//", "/")
|
||||
startsWith("http://") -> "http://" + replace("http://", "").replace("//", "/")
|
||||
else -> SError.make("Invalid URL: $this")
|
||||
}).get().build()
|
||||
).execute().let {
|
||||
if (it.code == 200 || it.code == 404) it.body?.string() ?: ""
|
||||
else SError.make("Request failed with code ${it.code}")
|
||||
}
|
||||
}.onFailure { if (isShowFailure) SLog.error("Failed to connect to $this\n$it") }.getOrNull() ?: ""
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,10 +17,16 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/26.
|
||||
* This file is created by fankes on 2023/8/26.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.utils
|
||||
|
||||
/**
|
||||
* 转换当前 [Map] 键值到字符串类型
|
||||
* @return [Map]<[String], [String]>
|
||||
*/
|
||||
internal inline fun <reified K, V> Map<K, V>.toStringMap() = mapKeys { e -> e.key.toString() }.mapValues { e -> e.value.toString() }
|
||||
|
||||
/**
|
||||
* 当数组不为空时返回非空
|
||||
* @return [T] or null
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,18 +17,17 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.utils.code
|
||||
|
||||
import com.highcapable.sweetproperty.utils.code.entity.MavenPomData
|
||||
import com.highcapable.sweetproperty.utils.debug.SError
|
||||
import com.highcapable.sweetproperty.utils.deleteEmptyRecursively
|
||||
import com.highcapable.sweetproperty.utils.parseFileSeparator
|
||||
import com.highcapable.sweetproperty.utils.toFile
|
||||
import net.lingala.zip4j.ZipFile
|
||||
import net.lingala.zip4j.model.ZipParameters
|
||||
import java.io.File
|
||||
import java.util.jar.JarEntry
|
||||
import java.util.jar.JarOutputStream
|
||||
import javax.tools.DiagnosticCollector
|
||||
import javax.tools.JavaFileObject
|
||||
import javax.tools.StandardLocation
|
||||
@@ -76,16 +75,17 @@ internal object CodeCompiler {
|
||||
diagnosticsMessage += " ${diagnostic.getMessage(null)}\n"
|
||||
}
|
||||
runCatching { fileManager.close() }
|
||||
compileOnlyFiles.forEach { "${outputClassesDir.absolutePath}/${it.name}".replace(".java", ".class").toFile().delete() }
|
||||
files.forEach {
|
||||
it.toFiles(outputSourcesDir).also { (sourceDir, sourceFile) ->
|
||||
sourceDir.mkdirs()
|
||||
sourceFile.writeText(it.getCharContent(true).toString())
|
||||
}
|
||||
}
|
||||
if (result) {
|
||||
compileOnlyFiles.forEach { "${outputClassesDir.absolutePath}/${it.name}".replace(".java", ".class").toFile().delete() }
|
||||
files.forEach {
|
||||
it.toFiles(outputSourcesDir).also { (sourceDir, sourceFile) ->
|
||||
sourceDir.mkdirs()
|
||||
sourceFile.writeText(it.getCharContent(true).toString())
|
||||
}
|
||||
}; outputClassesDir.deleteEmptyRecursively()
|
||||
writeMetaInf(outputClassesDir.absolutePath)
|
||||
writeMetaInf(outputSourcesDir.absolutePath)
|
||||
outputClassesDir.deleteEmptyRecursively()
|
||||
writeMetaInf(outputClassesDir)
|
||||
writeMetaInf(outputSourcesDir)
|
||||
createJarAndPom(pomData, outputDir, outputBuildDir, outputClassesDir, outputSourcesDir)
|
||||
} else SError.make("Failed to compile java files into path: $outputDirPath\n$diagnosticsMessage")
|
||||
}
|
||||
@@ -99,30 +99,29 @@ internal object CodeCompiler {
|
||||
* @param sourcesDir 编译源码目录
|
||||
*/
|
||||
private fun createJarAndPom(pomData: MavenPomData, outputDir: File, buildDir: File, classesDir: File, sourcesDir: File) {
|
||||
val pomPath = "${pomData.groupId.toPomPathName()}/${pomData.artifactId}/${pomData.version}"
|
||||
val pomDir = "${outputDir.absolutePath}/$pomPath".toFile().also { if (it.exists().not()) it.mkdirs() }
|
||||
val pomDir = outputDir.resolve(pomData.relativePomPath).also { if (it.exists().not()) it.mkdirs() }
|
||||
packageToJar(classesDir, pomDir, pomData, isSourcesJar = false)
|
||||
packageToJar(sourcesDir, pomDir, pomData, isSourcesJar = true)
|
||||
writePom(pomDir.absolutePath, pomData)
|
||||
writePom(pomDir, pomData)
|
||||
buildDir.deleteRecursively()
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入 META-INF/MANIFEST.MF
|
||||
* @param dirPath 当前目录路径
|
||||
* @param dir 当前目录
|
||||
*/
|
||||
private fun writeMetaInf(dirPath: String) {
|
||||
val metaInfFile = "$dirPath/META-INF".toFile().apply { mkdirs() }
|
||||
"${metaInfFile.absolutePath}/MANIFEST.MF".toFile().writeText("Manifest-Version: 1.0")
|
||||
private fun writeMetaInf(dir: File) {
|
||||
val metaInfDir = dir.resolve("META-INF").apply { mkdirs() }
|
||||
metaInfDir.resolve("MANIFEST.MF").writeText("Manifest-Version: 1.0")
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入 POM
|
||||
* @param dirPath 当前目录路径
|
||||
* @param dir 当前目录
|
||||
* @param pomData Maven POM 实体
|
||||
*/
|
||||
private fun writePom(dirPath: String, pomData: MavenPomData) =
|
||||
"$dirPath/${pomData.artifactId}-${pomData.version}.pom".toFile().writeText(
|
||||
private fun writePom(dir: File, pomData: MavenPomData) =
|
||||
dir.resolve("${pomData.artifactId}-${pomData.version}.pom").writeText(
|
||||
"""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project
|
||||
@@ -137,12 +136,6 @@ internal object CodeCompiler {
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
/**
|
||||
* 转换到 [MavenPomData] 目录名称
|
||||
* @return [String]
|
||||
*/
|
||||
private fun String.toPomPathName() = trim().replace(".", "/").replace("_", "/").replace(":", "/").replace("-", "/")
|
||||
|
||||
/**
|
||||
* 转换到文件
|
||||
* @param outputDir 输出目录
|
||||
@@ -167,26 +160,8 @@ internal object CodeCompiler {
|
||||
*/
|
||||
private fun packageToJar(buildDir: File, outputDir: File, pomData: MavenPomData, isSourcesJar: Boolean) {
|
||||
if (buildDir.exists().not()) SError.make("Jar file output path not found: ${buildDir.absolutePath}")
|
||||
/**
|
||||
* 添加文件到 JAR
|
||||
* @param jos 当前输出流
|
||||
* @param parentPath 父级路径
|
||||
*/
|
||||
fun File.addToJar(jos: JarOutputStream, parentPath: String = "") {
|
||||
val currentPath = "$parentPath$name".replace("${buildDir.name}|", "").replace("|", "/").parseFileSeparator()
|
||||
if (isFile) {
|
||||
if (name.startsWith(".")) return
|
||||
jos.putNextEntry(JarEntry(currentPath))
|
||||
inputStream().use { fis ->
|
||||
val buffer = ByteArray(4096)
|
||||
var bytesRead: Int
|
||||
while (fis.read(buffer).also { bytesRead = it } != -1) jos.write(buffer, 0, bytesRead)
|
||||
}
|
||||
jos.closeEntry()
|
||||
} else listFiles()?.forEach { it.addToJar(jos, parentPath = "$currentPath|") }
|
||||
}
|
||||
val jarFile = "${outputDir.absolutePath}/${pomData.artifactId}-${pomData.version}${if (isSourcesJar) "-sources" else ""}.jar".toFile()
|
||||
val jarFile = outputDir.resolve("${pomData.artifactId}-${pomData.version}${if (isSourcesJar) "-sources" else ""}.jar")
|
||||
if (jarFile.exists()) jarFile.delete()
|
||||
jarFile.outputStream().use { fos -> JarOutputStream(fos).use { jos -> buildDir.addToJar(jos) } }
|
||||
ZipFile(jarFile).addFolder(buildDir, ZipParameters().apply { isIncludeRootFolder = false })
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.utils.code.entity
|
||||
|
||||
@@ -27,4 +27,17 @@ package com.highcapable.sweetproperty.utils.code.entity
|
||||
* @param artifactId Artifact Id
|
||||
* @param version 版本
|
||||
*/
|
||||
internal data class MavenPomData(internal val groupId: String, internal val artifactId: String, internal val version: String)
|
||||
internal data class MavenPomData(internal val groupId: String, internal val artifactId: String, internal val version: String) {
|
||||
|
||||
/**
|
||||
* 获取 [MavenPomData] 相对路径
|
||||
* @return [String]
|
||||
*/
|
||||
internal val relativePomPath get() = "${groupId.toPomPathName()}/$artifactId/$version"
|
||||
|
||||
/**
|
||||
* 转换到 [MavenPomData] 目录名称
|
||||
* @return [String]
|
||||
*/
|
||||
private fun String.toPomPathName() = trim().replace(".", "/").replace("_", "/").replace(":", "/").replace("-", "/")
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
@file:Suppress("unused")
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.utils.debug
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,22 +17,87 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
@file:Suppress("unused")
|
||||
@file:Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||
|
||||
package com.highcapable.sweetproperty.utils.debug
|
||||
|
||||
import com.highcapable.sweetproperty.SweetProperty
|
||||
import org.apache.log4j.Logger
|
||||
|
||||
/**
|
||||
* 全局 Log 管理类
|
||||
*/
|
||||
internal object SLog {
|
||||
|
||||
internal const val DONE = "✅"
|
||||
internal const val IGNORE = "❎"
|
||||
internal const val ERROR = "❌"
|
||||
internal const val WARN = "⚠️"
|
||||
internal const val LINK = "➡️"
|
||||
internal const val WIRE = "⚙️"
|
||||
internal const val UP = "⬆️"
|
||||
internal const val ROTATE = "\uD83D\uDD04"
|
||||
internal const val ANLZE = "\uD83D\uDD0D"
|
||||
internal const val STRNG = "\uD83D\uDCAA"
|
||||
|
||||
/** 当前日志输出对象 */
|
||||
private val logger = Logger.getLogger(SLog::class.java)
|
||||
|
||||
/**
|
||||
* 打印 Info (提醒) 级别 Log (绿色)
|
||||
* @param msg 消息内容
|
||||
* @param symbol 前缀符号 - 仅限非 [noTag] - 默认无
|
||||
* @param noTag 无标签 - 默认否
|
||||
*/
|
||||
internal fun note(msg: Any, symbol: String = "", noTag: Boolean = false) =
|
||||
log(if (noTag) msg else msg.createSymbolMsg(symbol), color = "38;5;10")
|
||||
|
||||
/**
|
||||
* 打印 Info 级别 Log (无颜色)
|
||||
* @param msg 消息内容
|
||||
* @param symbol 前缀符号 - 仅限非 [noTag] - 默认无
|
||||
* @param noTag 无标签 - 默认否
|
||||
*/
|
||||
internal fun info(msg: Any, symbol: String = "", noTag: Boolean = false) =
|
||||
log(if (noTag) msg else msg.createSymbolMsg(symbol))
|
||||
|
||||
/**
|
||||
* 打印 Warn 级别 Log (黄色)
|
||||
* @param msg 消息内容
|
||||
* @param symbol 前缀符号 - 仅限非 [noTag] - 默认 [WARN]
|
||||
* @param noTag 无标签 - 默认否
|
||||
*/
|
||||
internal fun warn(msg: Any, symbol: String = WARN, noTag: Boolean = false) =
|
||||
log(if (noTag) msg else msg.createSymbolMsg(symbol), color = "33")
|
||||
|
||||
/**
|
||||
* 打印 Error 级别 Log (红色)
|
||||
* @param msg 消息内容
|
||||
* @param symbol 前缀符号 - 仅限非 [noTag] - 默认 [ERROR]
|
||||
* @param noTag 无标签 - 默认否
|
||||
*/
|
||||
internal fun error(msg: Any, symbol: String = ERROR, noTag: Boolean = false) =
|
||||
log(if (noTag) msg else msg.createSymbolMsg(symbol), isError = true)
|
||||
|
||||
/**
|
||||
* 创建符号消息内容
|
||||
* @param symbol 前缀符号
|
||||
* @return [String]
|
||||
*/
|
||||
private fun Any.createSymbolMsg(symbol: String) =
|
||||
if (symbol.isNotBlank()) "[${SweetProperty.TAG}] $symbol $this" else "[${SweetProperty.TAG}] $this"
|
||||
|
||||
/**
|
||||
* 打印 Log
|
||||
* @param msg 消息内容
|
||||
* @param color 颜色代码 - 默认无颜色
|
||||
* @param isError 是否强制为错误日志 - 默认否
|
||||
*/
|
||||
internal fun log(msg: String) = println("[${SweetProperty.TAG}] $msg")
|
||||
private fun log(msg: Any, color: String = "0", isError: Boolean = false) = when {
|
||||
isError -> logger.error(msg)
|
||||
color != "0" -> println("\u001B[${color}m$msg\u001B[0m")
|
||||
else -> println(msg)
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin
|
||||
* SweetProperty - An easy get project properties anywhere Gradle plugin.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/HighCapable/SweetProperty
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is Created by fankes on 2023/8/27.
|
||||
* This file is created by fankes on 2023/8/27.
|
||||
*/
|
||||
@file:Suppress("unused")
|
||||
|
||||
|
Reference in New Issue
Block a user