Skip to content

Commit 826df5f

Browse files
committed
Fix configuration cache for agent-for-testing JAR construction
Create proper task types (ExtractAgentJar, ExtractAgentManifest) with explicit inputs and outputs instead of using zipTree() at task configuration time.
1 parent a7597b0 commit 826df5f

File tree

1 file changed

+64
-9
lines changed

1 file changed

+64
-9
lines changed

testing/agent-for-testing/build.gradle.kts

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,76 @@ dependencies {
2424
testImplementation("io.opentelemetry:opentelemetry-api")
2525
}
2626

27+
abstract class ExtractAgentJar : DefaultTask() {
28+
@get:InputFiles
29+
@get:PathSensitive(PathSensitivity.NONE)
30+
abstract val agentJar: ConfigurableFileCollection
31+
32+
@get:OutputDirectory
33+
abstract val extractDir: DirectoryProperty
34+
35+
@get:Inject
36+
abstract val archiveOperations: ArchiveOperations
37+
38+
@get:Inject
39+
abstract val fileSystemOperations: FileSystemOperations
40+
41+
@TaskAction
42+
fun extract() {
43+
fileSystemOperations.sync {
44+
from(archiveOperations.zipTree(agentJar.singleFile))
45+
into(extractDir)
46+
}
47+
}
48+
}
49+
50+
abstract class ExtractAgentManifest : DefaultTask() {
51+
@get:InputFiles
52+
@get:PathSensitive(PathSensitivity.NONE)
53+
abstract val agentJar: ConfigurableFileCollection
54+
55+
@get:OutputFile
56+
abstract val manifestFile: RegularFileProperty
57+
58+
@get:Inject
59+
abstract val archiveOperations: ArchiveOperations
60+
61+
@get:Inject
62+
abstract val fileSystemOperations: FileSystemOperations
63+
64+
@TaskAction
65+
fun extract() {
66+
fileSystemOperations.copy {
67+
from(archiveOperations.zipTree(agentJar.singleFile))
68+
include("META-INF/MANIFEST.MF")
69+
into(temporaryDir)
70+
}
71+
manifestFile.get().asFile.writeBytes(
72+
temporaryDir.resolve("META-INF/MANIFEST.MF").readBytes()
73+
)
74+
}
75+
}
76+
77+
val extractAgent = tasks.register<ExtractAgentJar>("extractAgent") {
78+
agentJar.from(agent)
79+
extractDir.set(layout.buildDirectory.dir("tmp/agent-extracted"))
80+
}
81+
82+
val extractManifest = tasks.register<ExtractAgentManifest>("extractManifest") {
83+
agentJar.from(agent)
84+
manifestFile.set(layout.buildDirectory.file("tmp/agent-manifest/MANIFEST.MF"))
85+
}
86+
2787
tasks {
2888
jar {
29-
dependsOn(agent)
30-
from(zipTree(agent.singleFile))
89+
dependsOn(extractAgent)
90+
from(extractAgent.flatMap { it.extractDir })
3191
from(extensionLibs) {
3292
into("extensions")
3393
}
3494

35-
manifest.from(
36-
providers.provider {
37-
zipTree(agent.singleFile).matching {
38-
include("META-INF/MANIFEST.MF")
39-
}.singleFile
40-
}
41-
)
95+
dependsOn(extractManifest)
96+
manifest.from(extractManifest.flatMap { it.manifestFile })
4297
}
4398

4499
afterEvaluate {

0 commit comments

Comments
 (0)