1
1
package tasks
2
2
3
3
import com.javiersc.semver.project.gradle.plugin.Commit
4
- import gg.jte.ContentType
5
- import gg.jte.TemplateEngine
6
- import gg.jte.output.StringOutput
4
+ import gg.jte.generated.precompiled.StaticTemplates
7
5
import javax.inject.Inject
8
6
import org.gradle.api.DefaultTask
9
- import org.gradle.api.file.DirectoryProperty
10
7
import org.gradle.api.file.ProjectLayout
11
8
import org.gradle.api.model.ObjectFactory
12
9
import org.gradle.api.tasks.*
13
10
import org.gradle.kotlin.dsl.*
14
11
import org.gradle.language.base.plugins.LifecycleBasePlugin
15
12
16
13
@CacheableTask
17
- abstract class BuildConfig @Inject constructor(private val extn : BuildConfigExtension ) :
14
+ abstract class BuildConfig @Inject constructor(@Nested val extn : BuildConfigExtension ) :
18
15
DefaultTask () {
19
16
20
- @get:Input val version = extn.projectVersion
21
-
22
17
@get:Internal internal val templateName = " BuildConfig.kte"
23
18
24
- @get: [OutputDirectory Optional ]
25
- val generatedOutputDir: DirectoryProperty = extn.outputDir
26
-
27
19
init {
28
20
description = " Generate build config class"
29
21
group = LifecycleBasePlugin .BUILD_TASK_NAME
30
22
}
31
23
32
24
@TaskAction
33
25
fun execute () {
34
- val dir = generatedOutputDir .asFile.get()
26
+ val dir = extn.outputDir .asFile.get()
35
27
dir.deleteRecursively()
36
28
dir.mkdirs()
37
29
@@ -40,7 +32,7 @@ abstract class BuildConfig @Inject constructor(private val extn: BuildConfigExte
40
32
val pkg = fqName.substringBeforeLast(" ." , " " )
41
33
42
34
val file = dir.resolve(" $className .kt" )
43
- logger.quiet(" Generated build config file: ${file.path } " )
35
+ logger.quiet(" Generated build config file: ${file.name } " )
44
36
45
37
// Get git commit info
46
38
val gitCommit = run {
@@ -59,38 +51,39 @@ abstract class BuildConfig @Inject constructor(private val extn: BuildConfigExte
59
51
mapOf (
60
52
" name" to extn.projectName.get(),
61
53
" description" to extn.projectDesc.get(),
62
- " version" to version .get(),
54
+ " version" to extn.projectVersion .get(),
63
55
)
64
56
65
- // the<VersionCatalogsExtension>().named("libs").
66
- val params =
67
- mapOf (
68
- " className" to className,
69
- " pkg" to pkg,
70
- " projectProps" to rootProjectProps,
71
- " gitCommit" to gitCommit,
72
- " catalogVersions" to extn.catalogVersions.get(),
73
- " dependencies" to extn.dependencies.get(),
74
- )
57
+ // val content = StringOutput()
58
+ // val tmplEngine = TemplateEngine.createPrecompiled(ContentType.Plain).apply {
59
+ // setTrimControlStructures(true) }
60
+ // tmplEngine.render(templateName, params, content)
75
61
76
- val content = StringOutput ()
77
- val tmplEngine =
78
- TemplateEngine .createPrecompiled(ContentType .Plain ).apply { setTrimControlStructures(true ) }
62
+ val content =
63
+ StaticTemplates ()
64
+ .BuildConfig (
65
+ className = className,
66
+ pkg = pkg,
67
+ projectProps = rootProjectProps,
68
+ gitCommit = gitCommit,
69
+ catalogVersions = extn.catalogVersions.get(),
70
+ dependencies = extn.dependencies.get())
71
+ .render()
79
72
80
- tmplEngine.render(templateName, params, content)
81
- file.writeText(content.toString())
82
- // outputs.dirs(generatedOutputDir)
73
+ file.writeText(content)
74
+ // outputs.dirs(extn.outputDir)
83
75
}
84
76
}
85
77
86
78
open class BuildConfigExtension @Inject constructor(layout : ProjectLayout , objects : ObjectFactory ) {
87
79
@get:Input val classFqName = objects.property<String >().convention(" BuildConfig" )
80
+ @get:Input val projectVersion = objects.property<String >()
88
81
@get:Input val projectName = objects.property<String >()
89
82
@get:Input val projectDesc = objects.property<String >()
90
- @get:Input val gitCommit = objects.property<Commit >()
91
83
@get:Input val catalogVersions = objects.mapProperty<String , String >().convention(emptyMap())
92
84
@get:Input val dependencies = objects.listProperty<String >().convention(emptyList())
93
- val projectVersion = objects.property<String >()
85
+ @Internal val gitCommit = objects.property<Commit >()
86
+ @get: [OutputDirectory Optional ]
94
87
val outputDir =
95
88
objects.directoryProperty().convention(layout.buildDirectory.dir(" generated/buildconfig" ))
96
89
}
0 commit comments