1- import de.undercouch.gradle.tasks.download.DownloadExtension
1+ import java.io.FileOutputStream
2+ import java.io.InputStream
3+ import java.net.URL
24
35plugins {
46 id(" otel.java-conventions" )
57 id(" otel.publish-conventions" )
68 id(" otel.animalsniffer-conventions" )
7- id(" de.undercouch.download" ) version " 5.6.0"
89 id(" com.squareup.wire" ) version " 5.4.0"
910}
1011
@@ -23,11 +24,11 @@ dependencies {
2324 testImplementation(" com.squareup.okhttp3:mockwebserver3-junit5" )
2425}
2526
26- val opampProtos = tasks.register<DownloadOpampProtos >(" opampProtoDownload" , download)
27- opampProtos.configure {
27+ val opampProtos = tasks.register<DownloadAndExtractOpampProtos >(" opampProtoDownload" ) {
2828 group = " opamp"
2929 outputProtosDir.set(project.layout.buildDirectory.dir(" opamp/protos" ))
30- downloadedZipFile.set(project.layout.buildDirectory.file(" intermediate/$name /release.zip" ))
30+ downloadedZipFile.set(project.layout.buildDirectory.file(" intermediate/opampProtoDownload/release.zip" ))
31+ zipUrl.set(" https://github.com/open-telemetry/opamp-spec/zipball/v0.14.0" )
3132}
3233
3334wire {
3738 }
3839}
3940
40- abstract class DownloadOpampProtos @Inject constructor(
41- private val download : DownloadExtension ,
41+ abstract class DownloadAndExtractOpampProtos @Inject constructor(
4242 private val archiveOps : ArchiveOperations ,
4343 private val fileOps : FileSystemOperations ,
4444) : DefaultTask() {
@@ -49,14 +49,20 @@ abstract class DownloadOpampProtos @Inject constructor(
4949 @get:Internal
5050 abstract val downloadedZipFile: RegularFileProperty
5151
52+ @get:Input
53+ abstract val zipUrl: Property <String >
54+
5255 @TaskAction
5356 fun execute () {
54- val zipUrl = " https://github.com/open-telemetry/opamp-spec/zipball/v0.14.0"
57+ val url = URL (zipUrl.get())
58+ downloadedZipFile.get().asFile.parentFile.mkdirs()
5559
56- download.run {
57- src(zipUrl)
58- dest(downloadedZipFile)
60+ url.openStream().use { input: InputStream ->
61+ downloadedZipFile.get().asFile.outputStream().use { output: FileOutputStream ->
62+ input.copyTo(output)
63+ }
5964 }
65+
6066 val protos = archiveOps.zipTree(downloadedZipFile).matching {
6167 setIncludes(listOf (" **/*.proto" ))
6268 }
0 commit comments