Skip to content

Commit 415566e

Browse files
committed
wip
1 parent cf66c6e commit 415566e

File tree

6 files changed

+66
-36
lines changed

6 files changed

+66
-36
lines changed

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

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33

44
package software.aws.toolkits.gradle
55

6-
import org.eclipse.jgit.api.Git
76
import org.gradle.api.JavaVersion
7+
import org.gradle.api.logging.Logging
88
import org.gradle.api.Project
99
import org.gradle.api.provider.Provider
10+
import org.gradle.api.provider.ValueSource
11+
import org.gradle.api.provider.ValueSourceParameters
12+
import org.gradle.process.ExecOperations
1013
import software.aws.toolkits.gradle.intellij.IdeVersions
14+
import java.io.ByteArrayOutputStream
15+
import java.io.OutputStream
16+
import java.nio.charset.Charset
17+
import javax.inject.Inject
1118
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion as KotlinVersionEnum
1219

1320
/**
@@ -42,21 +49,37 @@ fun<T : Any> Project.withCurrentProfileName(consumer: (String) -> T): Provider<T
4249
}
4350
}
4451

45-
fun Project.buildMetadata() =
46-
try {
47-
val git = Git.open(rootDir)
48-
val currentShortHash = git.repository.findRef("HEAD").objectId.abbreviate(7).name()
49-
val isDirty = git.status().call().hasUncommittedChanges()
52+
abstract class GitHashValueSource : ValueSource<String, ValueSourceParameters.None> {
53+
@get:Inject
54+
abstract val execOperations: ExecOperations
5055

51-
buildString {
52-
append(currentShortHash)
56+
override fun obtain(): String {
57+
return try {
58+
val output = ByteArrayOutputStream()
59+
execOperations.exec {
60+
commandLine("git", "rev-parse", "--short", "HEAD")
61+
standardOutput = output
62+
}
63+
val currentShortHash = String(output.toByteArray(), Charset.defaultCharset())
64+
65+
val isDirty = execOperations.exec {
66+
commandLine("git", "status", "-s")
67+
standardOutput = OutputStream.nullOutputStream()
68+
}.exitValue != 0
5369

54-
if (isDirty) {
55-
append(".modified")
70+
buildString {
71+
append(currentShortHash)
72+
73+
if (isDirty) {
74+
append(".modified")
75+
}
5676
}
57-
}
58-
} catch(e: Exception) {
59-
logger.warn("Could not determine current commit", e)
77+
} catch(e: Exception) {
78+
Logging.getLogger(GitHashValueSource::class.java).warn("Could not determine current commit", e)
6079

61-
"unknownCommit"
80+
"unknownCommit"
81+
}
6282
}
83+
}
84+
85+
fun Project.buildMetadata() = providers.of(GitHashValueSource::class.java) {}

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") {

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ kotlin.build.report.output=file
2929

3030
# don't bundle Kotlin stdlib with plugin
3131
kotlin.stdlib.default.dependency=false
32+
33+
#org.gradle.configuration-cache=true
34+
#org.gradle.configuration-cache.problems=warn

plugins/amazonq/build.gradle.kts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ buildscript {
2121
}
2222
}
2323

24-
val changelog = tasks.register<GeneratePluginChangeLog>("pluginChangeLog") {
25-
includeUnreleased.set(true)
26-
changeLogFile.value(layout.buildDirectory.file("changelog/change-notes.xml"))
27-
}
24+
//val changelog = tasks.register<GeneratePluginChangeLog>("pluginChangeLog") {
25+
// includeUnreleased.set(true)
26+
// changeLogFile.value(layout.buildDirectory.file("changelog/change-notes.xml"))
27+
//}
2828

2929
tasks.jar {
30-
dependsOn(changelog)
31-
from(changelog) {
32-
into("META-INF")
33-
}
30+
// dependsOn(changelog)
31+
// from(changelog) {
32+
// into("META-INF")
33+
// }
3434
}
3535

3636
dependencies {
@@ -110,6 +110,8 @@ val downloadFlareArtifacts by tasks.registering(Download::class) {
110110
}
111111

112112
val prepareBundledFlare by tasks.registering(Copy::class) {
113+
// TODO: https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
114+
notCompatibleWithConfigurationCache("requires some untangling")
113115
dependsOn(downloadFlareArtifacts)
114116
inputs.files(downloadFlareArtifacts)
115117

plugins/core/resources/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ tasks.test {
2626
}
2727

2828
val download = tasks.register<Download>("downloadResources") {
29+
notCompatibleWithConfigurationCache("requires some untangling")
30+
2931
dest("$buildDir/downloaded-resources/software/aws/toolkits/resources/")
3032
src(listOf("https://idetoolkits.amazonwebservices.com/endpoints.json"))
3133
onlyIfModified(true)

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ dependencies {
4040
}
4141
}
4242

43-
val changelog = tasks.register<GeneratePluginChangeLog>("pluginChangeLog") {
44-
includeUnreleased.set(true)
45-
changeLogFile.set(project.file("$buildDir/changelog/change-notes.xml"))
46-
}
43+
//val changelog = tasks.register<GeneratePluginChangeLog>("pluginChangeLog") {
44+
// includeUnreleased.set(true)
45+
// changeLogFile.set(project.file("$buildDir/changelog/change-notes.xml"))
46+
//}
4747

4848
tasks.compileJava {
4949
// https://github.com/gradle/gradle/issues/26006
@@ -55,15 +55,15 @@ tasks.compileJava {
5555
PatchPluginXmlTask.register(project)
5656
val patchPluginXml = tasks.named<PatchPluginXmlTask>("patchPluginXml")
5757
patchPluginXml.configure {
58-
val buildSuffix = if (!project.isCi()) "+${buildMetadata()}" else ""
59-
pluginVersion.set("$toolkitVersion.${ideProfile.shortName}$buildSuffix")
58+
val buildSuffix = buildMetadata().map { if (!project.isCi()) "+${it}" else "" }
59+
pluginVersion.set(buildSuffix.map { "$toolkitVersion.${ideProfile.shortName}$it" })
6060
}
6161

6262
tasks.jar {
63-
dependsOn(patchPluginXml, changelog)
64-
from(changelog) {
65-
into("META-INF")
66-
}
63+
// dependsOn(patchPluginXml, changelog)
64+
// from(changelog) {
65+
// into("META-INF")
66+
// }
6767

6868
from(patchPluginXml) {
6969
duplicatesStrategy = DuplicatesStrategy.INCLUDE
@@ -77,8 +77,8 @@ tasks.integrationTest {
7777
}
7878

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

8484
val patchGatewayPluginXml by tasks.registering {
@@ -113,7 +113,7 @@ val gatewayArtifacts by configurations.creating {
113113
extendsFrom(configurations["implementation"], configurations["runtimeOnly"])
114114
}
115115

116-
val gatewayJar = tasks.create<Jar>("gatewayJar") {
116+
val gatewayJar = tasks.register<Jar>("gatewayJar") {
117117
// META-INF/plugin.xml is a duplicate?
118118
// unclear why the exclude() statement didn't work
119119
duplicatesStrategy = DuplicatesStrategy.WARN

0 commit comments

Comments
 (0)