Skip to content

Commit c64ccba

Browse files
committed
Convert CreateGitTag to Kotlin
Signed-off-by: Goooler <[email protected]>
1 parent 73b1e0f commit c64ccba

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

buildSrc/build.gradle.kts

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
19
java {
210
toolchain {
311
languageVersion = JavaLanguageVersion.of(11)

buildSrc/src/main/groovy/CreateGitTag.groovy renamed to buildSrc/src/main/kotlin/CreateGitTag.kt

+18-20
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,38 @@ import org.gradle.work.DisableCachingByDefault
99
import javax.inject.Inject
1010

1111
@DisableCachingByDefault(because = "Produces no cacheable output")
12-
abstract class CreateGitTag extends DefaultTask {
12+
abstract class CreateGitTag @Inject constructor(
13+
private val objects: ObjectFactory,
14+
private val execOperations: ExecOperations
15+
) : DefaultTask() {
1316

14-
@Inject
15-
abstract ObjectFactory getObjects()
17+
@get:Input
18+
val tagName: Property<String> = objects.property(String::class.java)
1619

17-
@Inject
18-
abstract ExecOperations getExecOperations()
19-
20-
@Input
21-
abstract Property<String> getTagName()
22-
23-
@Input
24-
@Optional
25-
final abstract Property<Boolean> overwriteExisting = objects.property(Boolean).convention(false)
20+
@get:Input
21+
@get:Optional
22+
val overwriteExisting: Property<Boolean> = objects.property(Boolean::class.java).apply {
23+
value(false)
24+
}
2625

2726
@TaskAction
28-
def tag() {
27+
fun applyArgbash() {
2928
logger.info("Tagging HEAD as ${tagName.get()}")
30-
execOperations.exec { execSpec ->
31-
def args = ["git", "tag"]
29+
execOperations.exec {
30+
val args = mutableListOf("git", "tag")
3231
if (overwriteExisting.get()) {
3332
args.add("-f")
3433
}
3534
args.add(tagName.get())
36-
execSpec.commandLine(args)
35+
commandLine(args)
3736
}
38-
execOperations.exec { execSpec ->
39-
def args = ["git", "push", "origin"]
37+
execOperations.exec {
38+
val args = mutableListOf("git", "push", "origin")
4039
if (overwriteExisting.get()) {
4140
args.add("-f")
4241
}
4342
args.add("--tags")
44-
execSpec.commandLine(args)
43+
commandLine(args)
4544
}
4645
}
47-
4846
}

0 commit comments

Comments
 (0)