Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,8 @@ fun<T : Any> Project.withCurrentProfileName(consumer: (String) -> T): Provider<T
}
}

fun Project.buildMetadata() =
try {
val git = Git.open(rootDir)
val currentShortHash = git.repository.findRef("HEAD").objectId.abbreviate(7).name()
val isDirty = git.status().call().hasUncommittedChanges()

buildString {
append(currentShortHash)

if (isDirty) {
append(".modified")
}
}
} catch(e: Exception) {
logger.warn("Could not determine current commit", e)

"unknownCommit"
fun Project.buildMetadata() = providers.of(GitShortHashValueSource::class.java) {
parameters {
gitRootDir.set(rootDir)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.gradle

import org.eclipse.jgit.api.Git
import org.gradle.api.provider.Property
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters
import org.slf4j.LoggerFactory
import java.io.File

abstract class GitShortHashValueSourceParameters : ValueSourceParameters {
abstract val gitRootDir: Property<File>
}

abstract class GitShortHashValueSource : ValueSource<String, GitShortHashValueSourceParameters> {
override fun obtain(): String =
try {
val git = Git.open(parameters.gitRootDir.get())
val currentShortHash = git.repository.findRef("HEAD").objectId.abbreviate(7).name()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we assign 7 to a variable?

val isDirty = git.status().call().hasUncommittedChanges()

buildString {
append(currentShortHash)

if (isDirty) {
append(".modified")
}
}
} catch(e: Exception) {
logger.warn("Could not determine current commit", e)

"unknownCommit"
}

companion object {
private val logger = LoggerFactory.getLogger("GitShortHashValueSource")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ version = "$toolkitVersion-${ideProfile.shortName}"
if (!project.isCi()) {
val buildMetadata = buildMetadata()
tasks.withType<PatchPluginXmlTask>().configureEach {
pluginVersion.set("${project.version}+$buildMetadata")
pluginVersion.set(buildMetadata.map { "${project.version}+$it" })
}

tasks.named<BuildPluginTask>("buildPlugin") {
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ kotlin.code.style=official
# Gradle settings
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configuration-cache.parallel=true
org.gradle.configuration-cache.problems=warn
org.gradle.jvmargs=-Xmx2048m
kotlin.daemon.jvmargs=-Xmx2048m

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
8 changes: 4 additions & 4 deletions plugins/toolkit/jetbrains-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ tasks.compileJava {
PatchPluginXmlTask.register(project)
val patchPluginXml = tasks.named<PatchPluginXmlTask>("patchPluginXml")
patchPluginXml.configure {
val buildSuffix = if (!project.isCi()) "+${buildMetadata()}" else ""
pluginVersion.set("$toolkitVersion-${ideProfile.shortName}$buildSuffix")
val buildSuffix = buildMetadata().map { if (!project.isCi()) "+$it" else "" }
pluginVersion.set(buildSuffix.map { "$toolkitVersion-${ideProfile.shortName}$it" })
}

tasks.jar {
Expand All @@ -82,8 +82,8 @@ tasks.integrationTest {
}

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

val patchGatewayPluginXml by tasks.registering {
Expand Down
Loading