mirror of
https://github.com/HighCapable/SweetProperty.git
synced 2025-09-06 02:35:28 +08:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
db2817a85a
|
|||
ebb1b95658
|
|||
68116f9f1f
|
|||
bd22e7b134
|
|||
416522a673
|
|||
d59e6feaab
|
|||
f08d25912d
|
|||
1bcd23113d
|
|||
22b4228a46
|
|||
7485b13e7c
|
|||
e24f6d0df1
|
|||
10ae6ed17a
|
|||
d41347066d
|
|||
b6507c0e99
|
|||
c3481acb2d
|
|||
d3ff5689ae
|
@@ -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
|
||||
|
||||

|
||||
|
@@ -16,4 +16,14 @@
|
||||
- 作废了 ~~`propertiesFileName`~~ 方法
|
||||
- 新增 `propertiesFileNames` 方法,现在你可以同时设置一组属性配置文件名称了
|
||||
- 新增 `includeKeys` 方法,现在你可以设置仅包含的属性键值名称数组了
|
||||
- 新增 `keyValuesRules` 方法,现在你可以在属性键值装载过程中修改键值内容的实际解析结果
|
||||
- 新增 `keyValuesRules` 方法,现在你可以在属性键值装载过程中修改键值内容的实际解析结果
|
||||
|
||||
## 1.0.3 | 2023.09.26
|
||||
|
||||
- 自动生成代码功能将始终输出源码文件,以方便在生成失败的时候进行调试
|
||||
- 修复 Gradle 生命周期问题
|
||||
- 修复根项目大小写变化后识别为两个项目的问题
|
||||
- 修复在全局配置中使用过其它配置方法后,子项目的 `all` 方法失效问题
|
||||
- 改进并采用 Gradle 项目命名规范
|
||||
- 新增插件自身检查更新功能
|
||||
- 一些其它功能性的改进
|
@@ -17,4 +17,14 @@
|
||||
- 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
|
||||
- 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
|
@@ -194,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"
|
||||
}
|
||||
|
@@ -208,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.2
|
||||
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,6 +18,9 @@ plugins:
|
||||
version: 0.25.3
|
||||
|
||||
libraries:
|
||||
com.squareup.okhttp3:
|
||||
okhttp:
|
||||
version: 4.11.0
|
||||
com.squareup:
|
||||
kotlinpoet:
|
||||
version: 1.14.2
|
||||
|
@@ -1,4 +1,3 @@
|
||||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
@@ -8,8 +7,8 @@ pluginManagement {
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
id("com.highcapable.sweetdependency") version "1.0.1"
|
||||
id("com.highcapable.sweetproperty") version "1.0.2"
|
||||
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,6 +21,7 @@ kotlin {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(com.squareup.okhttp3.okhttp)
|
||||
implementation(com.squareup.kotlinpoet)
|
||||
implementation(com.squareup.javapoet)
|
||||
implementation(net.lingala.zip4j.zip4j)
|
||||
|
@@ -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) }
|
||||
}
|
||||
|
||||
/**
|
||||
* 向构建脚本添加自定义依赖
|
||||
|
@@ -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,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.default
|
||||
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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.plugin.config.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/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
|
||||
|
||||
@@ -92,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 })
|
||||
|
||||
/**
|
||||
* 子配置方法体实现类
|
||||
@@ -115,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 配置方法体
|
||||
@@ -483,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
|
||||
|
||||
|
@@ -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
|
||||
|
||||
@@ -207,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)
|
||||
@@ -323,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"
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ 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"
|
||||
}
|
||||
|
@@ -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,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/26.
|
||||
* This file is created by fankes on 2023/8/26.
|
||||
*/
|
||||
package com.highcapable.sweetproperty.utils
|
||||
|
||||
|
@@ -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
|
||||
|
||||
@@ -75,14 +75,15 @@ 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()
|
||||
outputClassesDir.deleteEmptyRecursively()
|
||||
writeMetaInf(outputClassesDir)
|
||||
writeMetaInf(outputSourcesDir)
|
||||
createJarAndPom(pomData, outputDir, outputBuildDir, outputClassesDir, outputSourcesDir)
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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