File tree Expand file tree Collapse file tree 4 files changed +49
-22
lines changed
software/aws/toolkits/gradle
plugins/toolkit/jetbrains-core Expand file tree Collapse file tree 4 files changed +49
-22
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ version = "$toolkitVersion-${ideProfile.shortName}"
2222if (! 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" ) {
Original file line number Diff line number Diff line change @@ -60,8 +60,8 @@ tasks.compileJava {
6060PatchPluginXmlTask .register(project)
6161val patchPluginXml = tasks.named<PatchPluginXmlTask >(" patchPluginXml" )
6262patchPluginXml.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
6767tasks.jar {
@@ -82,8 +82,8 @@ tasks.integrationTest {
8282}
8383
8484val 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
8989val patchGatewayPluginXml by tasks.registering {
You can’t perform that action at this time.
0 commit comments