Skip to content

Commit 291a578

Browse files
yuinacornoveler17
authored andcommitted
#4 Unable to execute gitLog task due to extension cannot be serial… (#8)
1 parent 02ca0c6 commit 291a578

File tree

1 file changed

+48
-39
lines changed

1 file changed

+48
-39
lines changed

recursive-git-log-plugin/src/main/kotlin/com/linecorp/support/project/multi/log/git/recursive/RecursiveGitLogPlugin.kt

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616

1717
package com.linecorp.support.project.multi.log.git.recursive
1818

19-
import org.gradle.api.Action
20-
import org.gradle.api.DefaultTask
21-
import org.gradle.api.GradleException
22-
import org.gradle.api.Plugin
23-
import org.gradle.api.Project
19+
import org.gradle.api.*
2420
import org.gradle.api.artifacts.ProjectDependency
2521
import org.gradle.api.tasks.Input
2622
import org.gradle.api.tasks.Internal
@@ -32,17 +28,31 @@ import org.gradle.kotlin.dsl.register
3228
import org.gradle.kotlin.dsl.withType
3329
import org.gradle.process.ExecSpec
3430
import java.io.ByteArrayOutputStream
31+
import javax.inject.Inject
32+
33+
interface RecursiveGitLogParams {
34+
@get:Input
35+
val moduleNameTransformer: (Project) -> String
36+
@get:Input
37+
val logClassifiers: Map<String, (Project) -> Boolean>
38+
@get:Input
39+
val tagPattern: String
40+
@get:Input
41+
val trackFilePatterns: List<String>
42+
@get:Input
43+
val logPattern: String
44+
}
3545

36-
open class RecursiveGitLogPluginExtension {
46+
open class RecursiveGitLogPluginExtension : RecursiveGitLogParams {
3747
companion object {
3848
const val EXTENSION_NAME = "recursive-git-log-plugin"
3949
}
4050

41-
var moduleNameTransformer: (Project) -> String = { it.toString() }
42-
var logClassifiers = mutableMapOf<String, (Project) -> Boolean>()
43-
var tagPattern = "v*"
44-
var trackFilePatterns = mutableListOf("build.gradl*")
45-
var logPattern = "%s\n Assignee: @%an\n Reviewed-by: @%cn\n"
51+
override var moduleNameTransformer: (Project) -> String = { it.toString() }
52+
override var logClassifiers = mutableMapOf<String, (Project) -> Boolean>()
53+
override var tagPattern = "v*"
54+
override var trackFilePatterns = mutableListOf("build.gradl*")
55+
override var logPattern = "%s\n Assignee: @%an\n Reviewed-by: @%cn\n"
4656
}
4757

4858
open class RecursiveGitLogPlugin : Plugin<Project> {
@@ -59,19 +69,12 @@ open class RecursiveGitLogPlugin : Plugin<Project> {
5969
)
6070

6171
tasks {
62-
register("gitLog", GitLogTask::class) {
63-
group = GROUP
64-
description = """
65-
Produce logs per module affected between two specific points.
66-
-Plog.git.from=<from:latestTag>
67-
-Plog.git.to=<to:HEAD>
68-
""".trimIndent()
69-
70-
extension = ext
71-
72-
(findProperty(FROM_KEY) as String?)?.let { from = it }
73-
(findProperty(TO_KEY) as String?)?.let { to = it }
74-
}
72+
register(
73+
"gitLog", GitLogTask::class,
74+
ext,
75+
(findProperty(FROM_KEY) as String?) ?: "",
76+
(findProperty(TO_KEY) as String?) ?: ""
77+
)
7578
}
7679
}
7780
}
@@ -110,17 +113,23 @@ open class GitAwareTask : DefaultTask() {
110113
}
111114
}
112115

113-
open class GitLogTask : GitAwareTask() {
114-
@OutputDirectory
115-
val outputDir = project.buildDir
116+
open class GitLogTask @Inject constructor(
117+
param: RecursiveGitLogParams,
118+
@Input val from: String,
119+
@Input val to: String
120+
) : GitAwareTask(), RecursiveGitLogParams by param {
121+
@Internal
122+
override fun getGroup() = RecursiveGitLogPlugin.GROUP
116123

117-
@Input
118-
var extension: RecursiveGitLogPluginExtension = RecursiveGitLogPluginExtension()
124+
@Internal
125+
override fun getDescription() = """
126+
Produce logs per module affected between two specific points.
127+
-Plog.git.from=<from:latestTag>
128+
-Plog.git.to=<to:HEAD>
129+
""".trimIndent()
119130

120-
@Input
121-
var from = ""
122-
@Input
123-
var to = ""
131+
@OutputDirectory
132+
val outputDir = project.buildDir
124133

125134
@Internal
126135
val resolutionCache = mutableMapOf<Project, List<String>>()
@@ -167,12 +176,12 @@ open class GitLogTask : GitAwareTask() {
167176

168177
private fun Sequence<Project>.toGitLog(from: String, to: String = ""): String {
169178
return map {
170-
extension.moduleNameTransformer(it) to gitCommand(
179+
moduleNameTransformer(it) to gitCommand(
171180
"log",
172-
"--pretty=${extension.logPattern}",
181+
"--pretty=${logPattern}",
173182
"$from..$to",
174183
it.projectDir.toString(),
175-
*extension.trackFilePatterns.toTypedArray(),
184+
*trackFilePatterns.toTypedArray(),
176185
*resolveDependencies(it).toTypedArray()
177186
)
178187
}.filter { it.second.isNotBlank() }
@@ -181,12 +190,12 @@ open class GitLogTask : GitAwareTask() {
181190

182191
@TaskAction
183192
fun act() {
184-
val from = this.from.takeIf(String::isNotBlank) ?: getLastTag(extension.tagPattern)
193+
val from = this.from.takeIf(String::isNotBlank) ?: getLastTag(tagPattern)
185194
val to = this.to
186195
val diffFileName = diffFileName(from, to)
187196

188-
if (extension.logClassifiers.isNotEmpty()) {
189-
extension.logClassifiers
197+
if (logClassifiers.isNotEmpty()) {
198+
logClassifiers
190199
.mapValues { project.subprojects.asSequence().filter(it.value::invoke).toGitLog(from, to) }
191200
.forEach { (classifier, log) ->
192201
project.file("$outputDir/${diffFileName}_$classifier.log").writeText(log)

0 commit comments

Comments
 (0)