refactor: move package "internal" to "debug" and improve logging throughout the codebase

This commit is contained in:
2025-11-15 21:52:00 +08:00
parent 08885d5d32
commit 22e9266ce0
19 changed files with 245 additions and 116 deletions

View File

@@ -21,7 +21,7 @@
*/
@file:Suppress("UnusedReceiverParameter")
package com.highcapable.gropify.internal
package com.highcapable.gropify.debug
import com.highcapable.gropify.plugin.Gropify
import kotlin.contracts.ExperimentalContracts

View File

@@ -0,0 +1,52 @@
/*
* Gropify - A type-safe and modern properties plugin for Gradle.
* Copyright (C) 2019 HighCapable
* https://github.com/HighCapable/Gropify
*
* 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 2025/10/16.
*/
@file:Suppress("unused", "LoggingStringTemplateAsArgument")
package com.highcapable.gropify.debug
import com.highcapable.gropify.plugin.Gropify
/**
* Gropify logger.
*/
internal object Logger {
/** Debug mode flag. */
var debugMode = false
fun debug(msg: Any) {
if (!debugMode) return
println("\u001B[36m[${Gropify.TAG}][DEBUG] $msg\u001B[0m")
}
fun info(msg: Any) {
println("${Gropify.TAG}][INFO] $msg")
}
fun warn(msg: Any) {
println("\u001B[33m[${Gropify.TAG}][WARN] $msg\u001B[0m")
}
fun error(msg: Any) {
println("\u001B[31m[${Gropify.TAG}][ERROR] $msg\u001B[0m")
}
}

View File

@@ -21,8 +21,8 @@
*/
package com.highcapable.gropify.gradle.api.entity
import com.highcapable.gropify.debug.error
import com.highcapable.gropify.gradle.api.extension.getFullName
import com.highcapable.gropify.internal.error
import com.highcapable.gropify.plugin.Gropify
import org.gradle.api.Project
import org.gradle.api.initialization.Settings

View File

@@ -21,7 +21,7 @@
*/
package com.highcapable.gropify.gradle.api.extension
import com.highcapable.gropify.internal.error
import com.highcapable.gropify.debug.error
import com.highcapable.gropify.plugin.Gropify
import com.highcapable.gropify.utils.extension.camelcase
import com.highcapable.kavaref.extension.classOf

View File

@@ -1,59 +0,0 @@
/*
* Gropify - A type-safe and modern properties plugin for Gradle.
* Copyright (C) 2019 HighCapable
* https://github.com/HighCapable/Gropify
*
* 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 2025/10/16.
*/
@file:Suppress("unused", "LoggingStringTemplateAsArgument")
package com.highcapable.gropify.internal
import com.highcapable.gropify.plugin.Gropify
import org.gradle.api.Project
import org.gradle.api.logging.Logger
/**
* Gropify logger.
*/
internal class Logger private constructor() {
internal companion object {
/**
* Create logger with project.
* @param project the project.
* @return [Logger]
*/
fun with(project: Project) = Logger().apply {
logger = project.logger
}
/**
* Create empty logger instance.
* @return [Logger]
*/
fun get() = Logger()
}
private var logger: Logger? = null
internal fun debug(msg: Any) = "[${Gropify.TAG}][DEBUG] $msg".let { logger?.debug(it) ?: println(it) }
internal fun info(msg: Any) = "[${Gropify.TAG}][INFO] $msg".let { logger?.info(it) ?: println(it) }
internal fun warn(msg: Any) = "[${Gropify.TAG}][WARN] $msg".let { logger?.warn(it) ?: println(it) }
internal fun error(msg: Any) = "[${Gropify.TAG}][ERROR] $msg".let { logger?.error(it) ?: println(it) }
}

View File

@@ -21,8 +21,9 @@
*/
package com.highcapable.gropify.plugin
import com.highcapable.gropify.debug.Logger
import com.highcapable.gropify.debug.require
import com.highcapable.gropify.gradle.api.entity.ProjectDescriptor
import com.highcapable.gropify.internal.require
import com.highcapable.gropify.plugin.config.proxy.GropifyConfig
import com.highcapable.gropify.plugin.config.type.GropifyLocation
import com.highcapable.gropify.plugin.deployer.BuildscriptDeployer
@@ -69,10 +70,11 @@ internal object DefaultDeployer {
*/
fun init(settings: Settings, config: GropifyConfig) {
DefaultDeployer.config = config
if (!config.isEnabled) return
if (!isEnabled()) return
checkingConfigModified(settings)
Logger.debug("Initializing deployers, config modified: $configModified")
deployers.forEach { it.init(settings, configModified) }
}
@@ -81,8 +83,9 @@ internal object DefaultDeployer {
* @param rootProject the current root project.
*/
fun resolve(rootProject: Project) {
if (!config.isEnabled) return
if (!isEnabled()) return
Logger.debug("Resolving deployers, config modified: $configModified")
deployers.forEach { it.resolve(rootProject, configModified) }
}
@@ -91,8 +94,9 @@ internal object DefaultDeployer {
* @param rootProject the current root project.
*/
fun deploy(rootProject: Project) {
if (!config.isEnabled) return
if (!isEnabled()) return
Logger.debug("Deploying deployers, config modified: $configModified")
deployers.forEach { it.deploy(rootProject, configModified) }
}
@@ -106,16 +110,41 @@ internal object DefaultDeployer {
val properties = mutableMapOf<String, PropertyTypeValue>()
val resolveProperties = mutableMapOf<Any?, Any?>()
val locations = mutableMapOf<String, String>()
config.permanentKeyValues.forEach { (key, value) ->
properties[key] = value.createTypeValueByType(config.useTypeAutoConversion, key)
locations[key] = "Permanent Key-Value"
}
config.locations.forEach { location ->
when (location) {
GropifyLocation.CurrentProject -> createProperties(config, descriptor.currentDir).forEach { resolveProperties.putAll(it) }
GropifyLocation.RootProject -> createProperties(config, descriptor.rootDir).forEach { resolveProperties.putAll(it) }
GropifyLocation.Global -> createProperties(config, descriptor.homeDir).forEach { resolveProperties.putAll(it) }
GropifyLocation.System -> resolveProperties.putAll(System.getProperties())
GropifyLocation.SystemEnv -> resolveProperties.putAll(System.getenv())
GropifyLocation.CurrentProject -> createProperties(config, descriptor.currentDir).forEach {
resolveProperties.putAll(it)
it.forEach { (key, _) -> locations[key.toString()] = location.name }
}
GropifyLocation.RootProject -> createProperties(config, descriptor.rootDir).forEach {
resolveProperties.putAll(it)
it.forEach { (key, _) -> locations[key.toString()] = location.name }
}
GropifyLocation.Global -> createProperties(config, descriptor.homeDir).forEach {
resolveProperties.putAll(it)
it.forEach { (key, _) -> locations[key.toString()] = location.name }
}
GropifyLocation.System -> {
val system = System.getProperties()
resolveProperties.putAll(system)
system.forEach { (key, _) -> locations[key.toString()] = location.name }
}
GropifyLocation.SystemEnv -> {
val systemEnv = System.getenv()
resolveProperties.putAll(systemEnv)
systemEnv.forEach { (key, _) -> locations[key] = location.name }
}
}
}
@@ -167,6 +196,7 @@ internal object DefaultDeployer {
// Replace all key-values if exists.
config.replacementKeyValues.forEach { (key, value) ->
properties[key] = value.createTypeValueByType(config.useTypeAutoConversion, key)
locations[key] = "Replacement Key-Value${locations[key]?.let { ", $it" }}"
}
// Apply key-values rules.
@@ -175,6 +205,23 @@ internal object DefaultDeployer {
val resolveValue = mapper(value.raw).createTypeValue(config.useTypeAutoConversion, key, type)
properties[key] = resolveValue
locations[key] = "Rule-based Key-Value${locations[key]?.let { ", $it" }}"
}
properties.forEach { (key, value) ->
Logger.debug(
"""
Generated property for ${config.name}
----------
[Key]: $key
[Value]: ${value.raw}
[Code Value]: ${value.codeValue}
[Type]: ${value.type.simpleName}
[Location]: ${locations[key] ?: "Unknown"}
----------
""".trimIndent()
)
}
return properties
@@ -200,4 +247,9 @@ internal object DefaultDeployer {
lastModifiedHashCode = gradleHashCode
}
}
private fun isEnabled(): Boolean {
if (!config.isEnabled) Logger.debug("Gropify is disabled, skipping deployment process.")
return config.isEnabled
}
}

View File

@@ -21,10 +21,11 @@
*/
package com.highcapable.gropify.plugin
import com.highcapable.gropify.debug.Logger
import com.highcapable.gropify.debug.error
import com.highcapable.gropify.gradle.api.GradleDescriptor
import com.highcapable.gropify.gradle.api.extension.getOrCreate
import com.highcapable.gropify.gradle.api.plugin.PluginLifecycle
import com.highcapable.gropify.internal.error
import com.highcapable.gropify.plugin.extension.dsl.configure.GropifyConfigureExtension
import org.gradle.api.Project
import org.gradle.api.initialization.Settings
@@ -45,14 +46,22 @@ internal class GropifyLifecycle : PluginLifecycle {
override fun onSettingsEvaluated(settings: Settings) {
val config = configure?.build(settings) ?: Gropify.error("Extension \"${GropifyConfigureExtension.NAME}\" create failed.")
Logger.debugMode = config.debugMode
Logger.debug("Gropify ${Gropify.VERSION} running on Gradle ${GradleDescriptor.version}")
Logger.debug("Loaded configuration.")
DefaultDeployer.init(settings, config)
}
override fun beforeProjectEvaluate(rootProject: Project) {
Logger.debug("Before project evaluate: $rootProject")
DefaultDeployer.resolve(rootProject)
}
override fun afterProjectEvaluate(rootProject: Project) {
Logger.debug("After project evaluate: $rootProject")
DefaultDeployer.deploy(rootProject)
}
}

View File

@@ -23,8 +23,8 @@
package com.highcapable.gropify.plugin
import com.highcapable.gropify.internal.Logger
import com.highcapable.gropify.internal.error
import com.highcapable.gropify.debug.Logger
import com.highcapable.gropify.debug.error
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.initialization.Settings
@@ -56,7 +56,7 @@ class GropifyPlugin<T : ExtensionAware> internal constructor() : Plugin<T> {
}
}
}
is Project -> Logger.with(target).error(
is Project -> Logger.error(
"Gropify can only applied in settings.gradle or settings.gradle.kts, but current is $target, stop loading.",
)
else -> Gropify.error("Gropify applied to an unknown target: $target, stop loading.")

View File

@@ -21,9 +21,10 @@
*/
package com.highcapable.gropify.plugin.compiler
import com.highcapable.gropify.debug.Logger
import com.highcapable.gropify.debug.error
import com.highcapable.gropify.debug.require
import com.highcapable.gropify.gradle.api.entity.Dependency
import com.highcapable.gropify.internal.error
import com.highcapable.gropify.internal.require
import com.highcapable.gropify.plugin.Gropify
import com.highcapable.gropify.utils.extension.deleteEmptyRecursively
import com.highcapable.gropify.utils.extension.toFile
@@ -111,7 +112,20 @@ internal object CodeCompiler {
writeMetaInf(outputSourcesDir)
createJar(dependency, outputDir, outputBuildDir, outputClassesDir, outputSourcesDir)
} else Gropify.error("Failed to compile java files into path: $outputDirPath\n$diagnosticsMessage")
} else {
Logger.debug("Compilation process failed, dumping source file content.")
files.forEach {
Logger.debug(
"Check this Java file: ${it.name}\n" +
"====== BEGIN FILE CONTENT ======\n" +
"${it.getCharContent(true)}\n" +
"====== END FILE CONTENT ======"
)
}
Logger.debug("Please report those file content to us, you can remove sensitive information before this.")
Gropify.error("Failed to compile Java files into path: $outputDirPath\n$diagnosticsMessage")
}
}
private fun createJar(dependency: Dependency, outputDir: File, buildDir: File, classesDir: File, sourcesDir: File) {

View File

@@ -25,7 +25,9 @@ import com.highcapable.gropify.gradle.api.entity.Dependency
import com.highcapable.gropify.gradle.api.entity.ProjectDescriptor
import com.highcapable.gropify.gradle.api.extension.addDependencyToBuildscript
import com.highcapable.gropify.gradle.api.extension.getOrCreate
import com.highcapable.gropify.gradle.api.extension.hasExtension
import com.highcapable.gropify.gradle.api.extension.toClassOrNull
import com.highcapable.gropify.debug.Logger
import com.highcapable.gropify.plugin.DefaultDeployer
import com.highcapable.gropify.plugin.Gropify
import com.highcapable.gropify.plugin.compiler.extension.compile
@@ -82,7 +84,7 @@ internal class BuildscriptDeployer(private val _config: () -> GropifyConfig) : D
) return
cachedSettingsProperties = allProperties
buildscriptGenerator.build(config, allConfig, allProperties).compile(
buildscriptGenerator.build(allConfig, allProperties).compile(
buildscriptAccessorsDependency,
buildscriptAccessorsDir.absolutePath,
buildscriptGenerator.compileStubFiles
@@ -90,14 +92,16 @@ internal class BuildscriptDeployer(private val _config: () -> GropifyConfig) : D
}
override fun resolve(rootProject: Project, configModified: Boolean) {
if (!buildscriptAccessorsDir.resolve(buildscriptAccessorsDependency.relativePath).isEmpty())
rootProject.addDependencyToBuildscript(buildscriptAccessorsDir.absolutePath, buildscriptAccessorsDependency)
if (buildscriptAccessorsDir.resolve(buildscriptAccessorsDependency.relativePath).isEmpty()) return
Logger.debug("Resolving classpath for $buildscriptAccessorsDependency")
rootProject.addDependencyToBuildscript(buildscriptAccessorsDir.absolutePath, buildscriptAccessorsDependency)
}
override fun deploy(rootProject: Project, configModified: Boolean) {
fun Project.deploy() {
val config = config.from(this).buildscript
if (!config.isEnabled) return
if (!isEnabled(config)) return
val className = buildscriptGenerator.propertiesClass(config.name)
val accessorsClass = className.toClassOrNull(this) ?: throw RuntimeException(
@@ -108,7 +112,13 @@ internal class BuildscriptDeployer(private val _config: () -> GropifyConfig) : D
""".trimIndent()
)
getOrCreate(config.extensionName.camelcase(), accessorsClass)
val extensionName = config.extensionName.camelcase()
getOrCreate(extensionName, accessorsClass)
if (hasExtension(extensionName))
Logger.debug("Created buildscript extension \"$extensionName\" for $this")
else Logger.warn("Failed to create buildscript extension \"$extensionName\" for $this")
}
rootProject.deploy()
@@ -120,4 +130,9 @@ internal class BuildscriptDeployer(private val _config: () -> GropifyConfig) : D
.resolve(GropifyConfigureExtension.NAME)
.resolve(GropifyConfig.ARTIFACTS_NAME)
.apply { mkdirs() }
private fun isEnabled(config: GropifyConfig.BuildscriptGenerateConfig): Boolean {
if (!config.isEnabled) Logger.debug("Config buildscript is disabled in ${config.name}, skipping deployment process.")
return config.isEnabled
}
}

View File

@@ -21,11 +21,11 @@
*/
package com.highcapable.gropify.plugin.deployer
import com.highcapable.gropify.debug.Logger
import com.highcapable.gropify.debug.error
import com.highcapable.gropify.gradle.api.entity.ProjectDescriptor
import com.highcapable.gropify.gradle.api.extension.getFullName
import com.highcapable.gropify.gradle.api.extension.getOrNull
import com.highcapable.gropify.internal.Logger
import com.highcapable.gropify.internal.error
import com.highcapable.gropify.plugin.DefaultDeployer.generateMap
import com.highcapable.gropify.plugin.Gropify
import com.highcapable.gropify.plugin.config.extension.from
@@ -85,7 +85,7 @@ internal class SourceCodeDeployer(private val _config: () -> GropifyConfig) : De
val sourceCodeType = decideSourceCodeType(config, projectType)
val generateDirPath = resolveGenerateDirPath(config)
if (!config.isEnabled) return
if (!isEnabled(config)) return
val outputDir = file(generateDirPath)
val properties = generateMap(config, ProjectDescriptor.create(project = this))
@@ -107,7 +107,7 @@ internal class SourceCodeDeployer(private val _config: () -> GropifyConfig) : De
val generateConfig = GenerateConfig(packageName, className)
sourceCodeGenerator.build(config, generateConfig, properties).let { generator ->
sourceCodeGenerator.build(projectType, config, generateConfig, properties).let { generator ->
generator.first { it.type == sourceCodeType }
}.writeTo(outputDir)
configureSourceSets(project = this)
@@ -133,6 +133,8 @@ internal class SourceCodeDeployer(private val _config: () -> GropifyConfig) : De
} ?: return
}
Logger.debug("Configuring source sets in project '${project.getFullName()}' (${projectType.name}).")
val sourceCodeType = decideSourceCodeType(config, projectType)
val resolveSourceCodeType = if (projectType == ProjectType.Java) SourceCodeSpec.Type.Java else sourceCodeType
val generateDirPath = resolveGenerateDirPath(config)
@@ -147,7 +149,9 @@ internal class SourceCodeDeployer(private val _config: () -> GropifyConfig) : De
ProjectType.Java -> javaExtension
ProjectType.KMP -> kotlinExtension
else -> return
} ?: return
} ?: return Logger.debug("No supportable extension found for configuring source sets in $project")
Logger.debug("Found $extension: ${extension.javaClass}")
val collection = extension.asResolver().optional(!debugMode).firstMethodOrNull {
name = "getSourceSets"
@@ -157,8 +161,8 @@ internal class SourceCodeDeployer(private val _config: () -> GropifyConfig) : De
it?.asResolver()?.optional(!debugMode)?.firstMethodOrNull {
name = "getName"
}?.invokeQuietly<String>() == config.sourceSetName
} ?: return Logger.with(project).warn(
"Could not found source sets \"${config.sourceSetName}\" in project '${project.getFullName()}' ($projectType)."
} ?: return Logger.warn(
"Could not found source set \"${config.sourceSetName}\" in project '${project.getFullName()}' ($projectType)."
)
val directorySet = sourceSet.asResolver().optional(!debugMode).firstMethodOrNull {
@@ -172,6 +176,8 @@ internal class SourceCodeDeployer(private val _config: () -> GropifyConfig) : De
name = "getSrcDirs"
}?.invokeQuietly<Set<*>>()
Logger.debug("Deploying generated source to \"$generateDirPath\".")
val alreadyAdded = srcDirs?.any { it is File && it.canonicalPath.endsWith(generateDirPath) } == true
if (!alreadyAdded) {
val resolver = directorySet?.asResolver()?.optional(!debugMode)?.firstMethodOrNull {
@@ -179,10 +185,10 @@ internal class SourceCodeDeployer(private val _config: () -> GropifyConfig) : De
parameters(Any::class)
superclass()
}
resolver?.invokeQuietly(generateDirPath) ?: Logger.with(project).error(
resolver?.invokeQuietly(generateDirPath) ?: Logger.error(
"Project '${project.getFullName()}' source sets deployed failed, method \"srcDir\" maybe failed during the processing."
)
}
} else Logger.debug("Source directory \"$generateDirPath\" already added to source set \"${config.sourceSetName}\", skipping.")
}
private fun decideSourceCodeType(config: GropifyConfig.CommonCodeGenerateConfig, type: ProjectType) = when (type) {
@@ -213,4 +219,16 @@ internal class SourceCodeDeployer(private val _config: () -> GropifyConfig) : De
return "${className.upperCamelcase()}Properties"
}
private fun isEnabled(config: GropifyConfig.SourceCodeGenerateConfig): Boolean {
if (!config.isEnabled) Logger.debug("Config ${
when (config){
is GropifyConfig.AndroidGenerateConfig -> "android"
is GropifyConfig.JvmGenerateConfig -> "jvm"
is GropifyConfig.KmpGenerateConfig -> "kmp"
else -> "unknown"
}
} is disabled in ${config.name}, skipping deployment process.")
return config.isEnabled
}
}

View File

@@ -23,9 +23,9 @@
package com.highcapable.gropify.plugin.extension.dsl.configure
import com.highcapable.gropify.debug.error
import com.highcapable.gropify.debug.require
import com.highcapable.gropify.gradle.api.extension.isUnSafeExtName
import com.highcapable.gropify.internal.error
import com.highcapable.gropify.internal.require
import com.highcapable.gropify.plugin.Gropify
import com.highcapable.gropify.plugin.config.extension.create
import com.highcapable.gropify.plugin.config.proxy.GropifyConfig
@@ -67,6 +67,10 @@ open class GropifyConfigureExtension internal constructor() {
*
* You can help us identify the problem by enabling this option
* to print more debugging information in the logs.
*
* - Note: THIS IS ONLY FOR DEBUGGING!
* The debug log will contain your local environment,
* which may contain sensitive information. Please be sure to protect this information.
*/
var debugMode = false
@JvmName("debugMode") set
@@ -109,6 +113,17 @@ open class GropifyConfigureExtension internal constructor() {
)
val isEnabled: Boolean get() = Gropify.error("No getter available.")
/**
* Please call it from top level [GropifyConfigureExtension].
* @throws IllegalStateException
*/
@Suppress("unused")
@Deprecated(
message = "Please call it from top level `GropifyConfigureExtension`.",
level = DeprecationLevel.ERROR
)
val debugMode: Boolean get() = Gropify.error("No getter available.")
/**
* Configure common.
*

View File

@@ -21,10 +21,10 @@
*/
package com.highcapable.gropify.plugin.generator
import com.highcapable.gropify.debug.Logger
import com.highcapable.gropify.debug.error
import com.highcapable.gropify.debug.require
import com.highcapable.gropify.gradle.api.GradleDescriptor
import com.highcapable.gropify.internal.Logger
import com.highcapable.gropify.internal.error
import com.highcapable.gropify.internal.require
import com.highcapable.gropify.plugin.Gropify
import com.highcapable.gropify.plugin.config.proxy.GropifyConfig
import com.highcapable.gropify.plugin.extension.accessors.proxy.ExtensionAccessors
@@ -293,7 +293,6 @@ internal class BuildscriptGenerator {
* - Note: [allConfig] and [allKeyValues] must be equal in number.
*/
fun build(
config: GropifyConfig,
allConfig: MutableList<GropifyConfig.BuildscriptGenerateConfig>,
allKeyValues: MutableList<PropertyMap>
) = runCatching {
@@ -303,7 +302,7 @@ internal class BuildscriptGenerator {
val files = mutableListOf<JavaFile>()
if (allConfig.isEmpty()) return@runCatching let {
if (config.debugMode) Logger.get().debug("No buildscript accessors classes to generate.")
Logger.debug("No buildscript accessors classes to generate.")
files
}
@@ -322,12 +321,7 @@ internal class BuildscriptGenerator {
files.add(buildTypeSpec().createJavaFile(ACCESSORS_PACKAGE_NAME))
}
if (config.debugMode) files.forEach {
Logger.get().debug(
"Generated buildscript accessors class: ${it.typeSpec().name()}\n" +
"====== BEGIN FILE CONTENT ======\n$it\n====== END FILE CONTENT ======"
)
}
Logger.debug("Generated buildscript accessors classes: [${files.joinToString { it.typeSpec().name() }}]")
files
}.getOrElse { Gropify.error("Failed to generated accessors classes.\n${it.stackTraceToString()}") }

View File

@@ -21,7 +21,7 @@
*/
package com.highcapable.gropify.plugin.generator
import com.highcapable.gropify.internal.error
import com.highcapable.gropify.debug.error
import com.highcapable.gropify.plugin.Gropify
import com.highcapable.gropify.plugin.config.proxy.GropifyConfig
import com.highcapable.gropify.plugin.generator.config.GenerateConfig

View File

@@ -21,7 +21,7 @@
*/
package com.highcapable.gropify.plugin.generator
import com.highcapable.gropify.internal.error
import com.highcapable.gropify.debug.error
import com.highcapable.gropify.plugin.Gropify
import com.highcapable.gropify.plugin.config.proxy.GropifyConfig
import com.highcapable.gropify.plugin.generator.config.GenerateConfig

View File

@@ -21,9 +21,11 @@
*/
package com.highcapable.gropify.plugin.generator
import com.highcapable.gropify.internal.require
import com.highcapable.gropify.debug.Logger
import com.highcapable.gropify.debug.require
import com.highcapable.gropify.plugin.Gropify
import com.highcapable.gropify.plugin.config.proxy.GropifyConfig
import com.highcapable.gropify.plugin.deployer.extension.ProjectType
import com.highcapable.gropify.plugin.generator.config.GenerateConfig
import com.highcapable.gropify.plugin.generator.config.SourceCodeSpec
import com.highcapable.gropify.plugin.generator.extension.PropertyMap
@@ -38,16 +40,33 @@ internal class SourceCodeGenerator {
/**
* Build source code specs.
* @param projectType the project type.
* @param config the current generate config.
* @param generateConfig the generate config.
* @param keyValues the properties' key-values map.
* @return [List]<[SourceCodeSpec]>
*/
fun build(config: GropifyConfig.SourceCodeGenerateConfig, generateConfig: GenerateConfig, keyValues: PropertyMap): List<SourceCodeSpec> {
fun build(
projectType: ProjectType,
config: GropifyConfig.SourceCodeGenerateConfig,
generateConfig: GenerateConfig,
keyValues: PropertyMap
): List<SourceCodeSpec> {
Gropify.require(config is GropifyConfig.CommonCodeGenerateConfig) {
"Only Android, Jvm, Kotlin Multiplatform project is supported for now."
}
Logger.debug(
"""
Generated source for ${config.name}
----------
[Class]: ${generateConfig.packageName}.${generateConfig.className}
[Project Type]: $projectType
[Source Set]: ${config.sourceSetName}
[Generate Dir]: ${config.generateDirPath}
----------
""".trimIndent()
)
return listOf(
java.build(config, generateConfig, keyValues),
kotlin.build(config, generateConfig, keyValues)

View File

@@ -21,7 +21,7 @@
*/
package com.highcapable.gropify.plugin.generator.config
import com.highcapable.gropify.internal.error
import com.highcapable.gropify.debug.error
import com.highcapable.gropify.plugin.Gropify
import com.palantir.javapoet.JavaFile
import com.squareup.kotlinpoet.FileSpec

View File

@@ -21,8 +21,8 @@
*/
package com.highcapable.gropify.plugin.generator.extension
import com.highcapable.gropify.internal.error
import com.highcapable.gropify.internal.require
import com.highcapable.gropify.debug.error
import com.highcapable.gropify.debug.require
import com.highcapable.gropify.plugin.Gropify
import com.highcapable.gropify.utils.extension.isNumeric
import kotlin.reflect.KClass
@@ -81,7 +81,7 @@ internal fun String.createTypeValue(autoConversion: Boolean, key: String, type:
Gropify.require(doubleValue != null && !doubleValue.isInfinite()) {
"The \"$key\" value \"$this\" cannot be converted to Double type."
}
trimmed
}
Float::class -> {
@@ -89,7 +89,7 @@ internal fun String.createTypeValue(autoConversion: Boolean, key: String, type:
Gropify.require(floatValue != null && !floatValue.isInfinite()) {
"The \"$key\" value \"$this\" cannot be converted to Float type."
}
if (trimmed.endsWith("f") || trimmed.endsWith("F")) trimmed else "${trimmed}f"
}
else -> Gropify.error(

View File

@@ -21,10 +21,10 @@
*/
package com.highcapable.gropify.plugin.helper
import com.highcapable.gropify.debug.Logger
import com.highcapable.gropify.gradle.api.extension.getFullName
import com.highcapable.gropify.gradle.api.extension.getOrNull
import com.highcapable.gropify.gradle.api.extension.hasExtension
import com.highcapable.gropify.internal.Logger
import com.highcapable.gropify.plugin.deployer.extension.ExtensionName
import com.highcapable.gropify.plugin.extension.dsl.configure.GropifyConfigureExtension
import com.highcapable.kavaref.KavaRef.Companion.asResolver
@@ -73,7 +73,7 @@ internal object AndroidProjectHelper {
}.onFailure {
// If file broken, reset it.
namespacesFile.writeText("{}")
Logger.with(this).warn("Android project namespaces file was broken and has been reset.")
Logger.warn("Android project namespaces file was broken and has been reset.")
}.getOrDefault(hashMapOf())
val namespace = getExtensionNamespace()