|
| 1 | +import de.undercouch.gradle.tasks.download.Download |
| 2 | +import de.undercouch.gradle.tasks.download.DownloadExtension |
| 3 | +import groovy.json.JsonSlurper |
| 4 | + |
1 | 5 | plugins { |
2 | 6 | id("otel.java-conventions") |
| 7 | + id("de.undercouch.download") version "5.6.0" |
3 | 8 | id("com.google.protobuf") version "0.9.4" |
4 | 9 | } |
5 | 10 |
|
@@ -40,3 +45,53 @@ dependencies { |
40 | 45 | annotationProcessor("com.google.auto.value:auto-value") |
41 | 46 | compileOnly("com.google.auto.value:auto-value-annotations") |
42 | 47 | } |
| 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