Skip to content

Commit 17e4584

Browse files
committed
config cache
1 parent a89646a commit 17e4584

File tree

4 files changed

+49
-22
lines changed

4 files changed

+49
-22
lines changed

buildSrc/src/main/kotlin/software/aws/toolkits/gradle/BuildScriptUtils.kt

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,8 @@ fun<T : Any> Project.withCurrentProfileName(consumer: (String) -> T): Provider<T
4444
}
4545
}
4646

47-
fun Project.buildMetadata() =
48-
try {
49-
val git = Git.open(rootDir)
50-
val currentShortHash = git.repository.findRef("HEAD").objectId.abbreviate(7).name()
51-
val isDirty = git.status().call().hasUncommittedChanges()
52-
53-
buildString {
54-
append(currentShortHash)
55-
56-
if (isDirty) {
57-
append(".modified")
58-
}
59-
}
60-
} catch(e: Exception) {
61-
logger.warn("Could not determine current commit", e)
62-
63-
"unknownCommit"
47+
fun Project.buildMetadata() = providers.of(GitShortHashValueSource::class.java) {
48+
parameters {
49+
gitRootDir.set(rootDir)
6450
}
51+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.gradle
5+
6+
import org.eclipse.jgit.api.Git
7+
import org.gradle.api.provider.Property
8+
import org.gradle.api.provider.ValueSource
9+
import org.gradle.api.provider.ValueSourceParameters
10+
import org.slf4j.LoggerFactory
11+
import java.io.File
12+
13+
abstract class GitShortHashValueSourceParameters : ValueSourceParameters {
14+
abstract val gitRootDir: Property<File>
15+
}
16+
17+
abstract class GitShortHashValueSource : ValueSource<String, GitShortHashValueSourceParameters> {
18+
override fun obtain(): String =
19+
try {
20+
val git = Git.open(parameters.gitRootDir.get())
21+
val currentShortHash = git.repository.findRef("HEAD").objectId.abbreviate(7).name()
22+
val isDirty = git.status().call().hasUncommittedChanges()
23+
24+
buildString {
25+
append(currentShortHash)
26+
27+
if (isDirty) {
28+
append(".modified")
29+
}
30+
}
31+
} catch(e: Exception) {
32+
logger.warn("Could not determine current commit", e)
33+
34+
"unknownCommit"
35+
}
36+
37+
companion object {
38+
private val logger = LoggerFactory.getLogger("GitShortHashValueSource")
39+
}
40+
}

buildSrc/src/main/kotlin/toolkit-publishing-conventions.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ version = "$toolkitVersion-${ideProfile.shortName}"
2222
if (!project.isCi()) {
2323
val buildMetadata = buildMetadata()
2424
tasks.withType<PatchPluginXmlTask>().configureEach {
25-
pluginVersion.set("${project.version}+$buildMetadata")
25+
pluginVersion.set(buildMetadata.map { "${project.version}+$it" })
2626
}
2727

2828
tasks.named<BuildPluginTask>("buildPlugin") {

plugins/toolkit/jetbrains-core/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ tasks.compileJava {
6060
PatchPluginXmlTask.register(project)
6161
val patchPluginXml = tasks.named<PatchPluginXmlTask>("patchPluginXml")
6262
patchPluginXml.configure {
63-
val buildSuffix = if (!project.isCi()) "+${buildMetadata()}" else ""
64-
pluginVersion.set("$toolkitVersion-${ideProfile.shortName}$buildSuffix")
63+
val buildSuffix = buildMetadata().map { if (!project.isCi()) "+$it" else "" }
64+
pluginVersion.set(buildSuffix.map { "$toolkitVersion-${ideProfile.shortName}$it" })
6565
}
6666

6767
tasks.jar {
@@ -82,8 +82,8 @@ tasks.integrationTest {
8282
}
8383

8484
val gatewayPluginXml = tasks.register<PatchPluginXmlTask>("pluginXmlForGateway") {
85-
val buildSuffix = if (!project.isCi()) "+${buildMetadata()}" else ""
86-
pluginVersion.set("GW-$toolkitVersion-${ideProfile.shortName}$buildSuffix")
85+
val buildSuffix = buildMetadata().map { if (!project.isCi()) "+$it" else "" }
86+
pluginVersion.set(buildSuffix.map { "GW-$toolkitVersion-${ideProfile.shortName}$it" })
8787
}
8888

8989
val patchGatewayPluginXml by tasks.registering {

0 commit comments

Comments
 (0)