From bcc1b4ed2bd4a19ecf250ccf760c6e0e1e658a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Wed, 11 May 2022 20:19:31 +0200 Subject: [PATCH] build: Make the DownloadWebRtcTask cacheable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids having to redownload lib after clean (if build cache is enabled) Signed-off-by: Álvaro Brey --- app/build.gradle | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5073b36c1..c8b624fe4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -348,21 +348,32 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { } } +@CacheableTask abstract class DownloadWebRtcTask extends DefaultTask { @Input abstract Property getVersion() + @OutputFile + File getLibFile() { + return new File("${project.buildDir}/download/${getFileName()}") + } + + private String getFileName() { + def webRtcVersion = version.get() + return "libwebrtc-${webRtcVersion}.aar" + } + + private String getDownloadUrl() { + def webRtcVersion = version.get() + return "https://github.com/nextcloud-releases/talk-clients-webrtc/releases/download/${webRtcVersion}-RC1/libwebrtc-${webRtcVersion}.aar" + } + @TaskAction def run() { - def webRtcVersion = version.get() - def fileName = "libwebrtc-${webRtcVersion}.aar" - def url = "https://github.com/nextcloud-releases/talk-clients-webrtc/releases/download/${webRtcVersion}-RC1/libwebrtc-${webRtcVersion}.aar" - - File file = new File("${project.buildDir}/download/${fileName}") - file.parentFile.mkdirs() - if (!file.exists()) { - new URL(url).withInputStream { downloadStream -> - file.withOutputStream { fileOut -> + libFile.parentFile.mkdirs() + if (!libFile.exists()) { + new URL(getDownloadUrl()).withInputStream { downloadStream -> + libFile.withOutputStream { fileOut -> fileOut << downloadStream } }