Skip to content

Commit 578e121

Browse files
committed
Downloading opamp protos
1 parent 9304779 commit 578e121

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

opamp-client/build.gradle.kts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import de.undercouch.gradle.tasks.download.Download
2+
import de.undercouch.gradle.tasks.download.DownloadExtension
3+
import groovy.json.JsonSlurper
4+
15
plugins {
26
id("otel.java-conventions")
7+
id("de.undercouch.download") version "5.6.0"
38
id("com.google.protobuf") version "0.9.4"
49
}
510

@@ -40,3 +45,53 @@ dependencies {
4045
annotationProcessor("com.google.auto.value:auto-value")
4146
compileOnly("com.google.auto.value:auto-value-annotations")
4247
}
48+
49+
val opampReleaseInfo = tasks.register<Download>("opampLastReleaseInfo") {
50+
group = "opamp"
51+
src("https://api.github.com/repos/open-telemetry/opamp-spec/releases/latest")
52+
dest(project.layout.buildDirectory.file("$name/release.json"))
53+
}
54+
55+
tasks.register<DownloadOpampProtos>("opampProtoDownload", download).configure {
56+
group = "opamp"
57+
dependsOn(opampReleaseInfo)
58+
lastReleaseInfoJson.set {
59+
opampReleaseInfo.get().dest
60+
}
61+
outputProtosDir.set(project.layout.buildDirectory.dir(name))
62+
downloadedZipFile.set(project.layout.buildDirectory.file("intermediate/$name/release.zip"))
63+
}
64+
65+
abstract class DownloadOpampProtos @Inject constructor(
66+
private val download: DownloadExtension,
67+
private val archiveOps: ArchiveOperations,
68+
private val fileOps: FileSystemOperations,
69+
) : DefaultTask() {
70+
71+
@get:InputFile
72+
abstract val lastReleaseInfoJson: RegularFileProperty
73+
74+
@get:OutputDirectory
75+
abstract val outputProtosDir: DirectoryProperty
76+
77+
@get:Internal
78+
abstract val downloadedZipFile: RegularFileProperty
79+
80+
@Suppress("UNCHECKED_CAST")
81+
@TaskAction
82+
fun execute() {
83+
val releaseInfo = JsonSlurper().parse(lastReleaseInfoJson.get().asFile) as Map<String, String>
84+
val zipUrl = releaseInfo["zipball_url"]
85+
download.run {
86+
src(zipUrl)
87+
dest(downloadedZipFile)
88+
}
89+
val protos = archiveOps.zipTree(downloadedZipFile).matching {
90+
setIncludes(listOf("**/*.proto"))
91+
}
92+
fileOps.sync {
93+
from(protos)
94+
into(outputProtosDir)
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)