From a92dcc075b02373a98242ab3806f2012c9925c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Wed, 11 May 2022 19:58:32 +0200 Subject: [PATCH 1/6] build: Use a task to download webRtc for proper task dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `./gradlew clean [whatever] should work now` Signed-off-by: Álvaro Brey --- app/build.gradle | 49 ++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 69e7ee500..5073b36c1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,20 +33,6 @@ apply plugin: 'com.github.spotbugs' apply plugin: 'io.gitlab.arturbosch.detekt' apply plugin: "org.jlleitschuh.gradle.ktlint" -def urlFile = { url, fileName -> - File file = new File("$buildDir/download/${fileName}") - file.parentFile.mkdirs() - if (!file.exists()) { - new URL(url).withInputStream { downloadStream -> - file.withOutputStream { fileOut -> - fileOut << downloadStream - } - } - } - files(file.absolutePath) -} - - android { compileSdkVersion 30 buildToolsVersion '30.0.3' @@ -147,7 +133,6 @@ android { } check.dependsOn 'spotbugsGplayDebug', 'lint', 'ktlintCheck', 'detekt' - lint.dependsOn 'preBuild' compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -176,10 +161,12 @@ ext { powermockVersion = "2.0.9" retrofit2Version = "2.9.0" workVersion = "2.6.0" - markwonVersion = "4.6.2" + markwonVersion = "4.6.2" espressoVersion = "3.4.0" } +def webRtcVersion = "96.4664.0" + configurations.all { exclude group: 'com.google.firebase', module: 'firebase-core' exclude group: 'com.google.firebase', module: 'firebase-analytics' @@ -253,8 +240,7 @@ dependencies { kapt "com.jakewharton:butterknife-compiler:${butterknifeVersion}" implementation 'eu.davidea:flexible-adapter:5.1.0' implementation 'eu.davidea:flexible-adapter-ui:1.0.0' - implementation urlFile('https://github.com/nextcloud-releases/talk-clients-webrtc/releases/download/96.4664.0-RC1/libwebrtc-96.4664.0.aar', - 'libwebrtc-96.4664.0.aar') + implementation files("${project.buildDir}/download/libwebrtc-${webRtcVersion}.aar") implementation 'com.yarolegovich:lovely-dialog:1.1.1' implementation 'com.yarolegovich:mp:1.1.6' implementation 'me.zhanghai.android.effortlesspermissions:library:1.1.0' @@ -361,3 +347,30 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { jvmTarget = "1.8" } } + +abstract class DownloadWebRtcTask extends DefaultTask { + @Input + abstract Property getVersion() + + @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 -> + fileOut << downloadStream + } + } + } + } +} + +tasks.register('downloadWebRtc', DownloadWebRtcTask){ + version = webRtcVersion +} +preBuild.dependsOn('downloadWebRtc') \ No newline at end of file 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 2/6] 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 } } From ce3ff3f1a4eff0e0ae19d0f2cf691020afbff86a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Wed, 11 May 2022 20:43:07 +0200 Subject: [PATCH 3/6] Move DownloadWebRtcTask to buildSrc for cleaner build.gradle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Brey --- app/build.gradle | 34 +--------- buildSrc/build.gradle | 22 +++++++ .../talk/gradle/DownloadWebRtcTask.groovy | 62 +++++++++++++++++++ 3 files changed, 85 insertions(+), 33 deletions(-) create mode 100644 buildSrc/build.gradle create mode 100644 buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy diff --git a/app/build.gradle b/app/build.gradle index c8b624fe4..e5f18c638 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,6 +24,7 @@ * along with this program. If not, see . */ import com.github.spotbugs.snom.SpotBugsTask +import com.nextcloud.talk.gradle.DownloadWebRtcTask apply plugin: 'com.android.application' apply plugin: 'kotlin-android' @@ -348,39 +349,6 @@ 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() { - libFile.parentFile.mkdirs() - if (!libFile.exists()) { - new URL(getDownloadUrl()).withInputStream { downloadStream -> - libFile.withOutputStream { fileOut -> - fileOut << downloadStream - } - } - } - } -} - tasks.register('downloadWebRtc', DownloadWebRtcTask){ version = webRtcVersion } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 000000000..11e63336f --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,22 @@ +/* +* Nextcloud Talk application +* +* @author Álvaro Brey +* Copyright (C) 2022 Álvaro Brey +* Copyright (C) 2022 Nextcloud GmbH +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +apply plugin: 'groovy' \ No newline at end of file diff --git a/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy b/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy new file mode 100644 index 000000000..0c2c0f614 --- /dev/null +++ b/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy @@ -0,0 +1,62 @@ +/* + * Nextcloud Talk application + * + * @author Álvaro Brey + * Copyright (C) 2022 Álvaro Brey + * Copyright (C) 2022 Nextcloud GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.gradle + +import org.gradle.api.DefaultTask +import org.gradle.api.provider.Property +import org.gradle.api.tasks.CacheableTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction + +@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/${getFileName()}" + } + + @TaskAction + def run() { + libFile.parentFile.mkdirs() + if (!libFile.exists()) { + new URL(getDownloadUrl()).withInputStream { downloadStream -> + libFile.withOutputStream { fileOut -> + fileOut << downloadStream + } + } + } + } +} \ No newline at end of file From ff32ab1172c05cedb821c9ef54d314deed7dfca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Wed, 11 May 2022 20:53:04 +0200 Subject: [PATCH 4/6] build: Use download task output for dependency instead of hardcoding path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Brey --- app/build.gradle | 13 ++++++------- .../nextcloud/talk/gradle/DownloadWebRtcTask.groovy | 6 +++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e5f18c638..154fff78b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -167,6 +167,10 @@ ext { } def webRtcVersion = "96.4664.0" +tasks.register('downloadWebRtc', DownloadWebRtcTask){ + version = webRtcVersion +} +preBuild.dependsOn('downloadWebRtc') configurations.all { exclude group: 'com.google.firebase', module: 'firebase-core' @@ -241,7 +245,7 @@ dependencies { kapt "com.jakewharton:butterknife-compiler:${butterknifeVersion}" implementation 'eu.davidea:flexible-adapter:5.1.0' implementation 'eu.davidea:flexible-adapter-ui:1.0.0' - implementation files("${project.buildDir}/download/libwebrtc-${webRtcVersion}.aar") + implementation fileTree(downloadWebRtc.getOutputPath()) implementation 'com.yarolegovich:lovely-dialog:1.1.1' implementation 'com.yarolegovich:mp:1.1.6' implementation 'me.zhanghai.android.effortlesspermissions:library:1.1.0' @@ -347,9 +351,4 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { kotlinOptions { jvmTarget = "1.8" } -} - -tasks.register('downloadWebRtc', DownloadWebRtcTask){ - version = webRtcVersion -} -preBuild.dependsOn('downloadWebRtc') \ No newline at end of file +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy b/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy index 0c2c0f614..c0a677bec 100644 --- a/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy +++ b/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy @@ -35,7 +35,7 @@ abstract class DownloadWebRtcTask extends DefaultTask { @OutputFile File getLibFile() { - return new File("${project.buildDir}/download/${getFileName()}") + return new File(getOutputPath()) } private String getFileName() { @@ -48,6 +48,10 @@ abstract class DownloadWebRtcTask extends DefaultTask { return "https://github.com/nextcloud-releases/talk-clients-webrtc/releases/download/${webRtcVersion}-RC1/${getFileName()}" } + public String getOutputPath() { + return "${project.buildDir}/download/${getFileName()}" + } + @TaskAction def run() { libFile.parentFile.mkdirs() From f9472ab273160d0b98ff180950dc48cbb9e37062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Wed, 11 May 2022 22:30:20 +0200 Subject: [PATCH 5/6] build: Add log message when libWebRtc is downloaded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Brey --- app/build.gradle | 2 +- .../groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 154fff78b..3ecd67bde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -351,4 +351,4 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { kotlinOptions { jvmTarget = "1.8" } -} \ No newline at end of file +} diff --git a/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy b/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy index c0a677bec..3d97731b7 100644 --- a/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy +++ b/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy @@ -48,7 +48,7 @@ abstract class DownloadWebRtcTask extends DefaultTask { return "https://github.com/nextcloud-releases/talk-clients-webrtc/releases/download/${webRtcVersion}-RC1/${getFileName()}" } - public String getOutputPath() { + String getOutputPath() { return "${project.buildDir}/download/${getFileName()}" } @@ -56,6 +56,7 @@ abstract class DownloadWebRtcTask extends DefaultTask { def run() { libFile.parentFile.mkdirs() if (!libFile.exists()) { + logger.lifecycle("Downloading libWebRTC ${version.get()} from ${getDownloadUrl()}") new URL(getDownloadUrl()).withInputStream { downloadStream -> libFile.withOutputStream { fileOut -> fileOut << downloadStream From 26dfa38219d210eefca517f1405e6ec228454af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Thu, 12 May 2022 20:51:44 +0200 Subject: [PATCH 6/6] build: DownloadWebRtc: Fix newlines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Brey --- buildSrc/build.gradle | 2 +- .../groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 11e63336f..2b70f1a88 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -19,4 +19,4 @@ * along with this program. If not, see . */ -apply plugin: 'groovy' \ No newline at end of file +apply plugin: 'groovy' diff --git a/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy b/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy index 3d97731b7..36d69f1d1 100644 --- a/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy +++ b/buildSrc/src/main/groovy/com/nextcloud/talk/gradle/DownloadWebRtcTask.groovy @@ -64,4 +64,4 @@ abstract class DownloadWebRtcTask extends DefaultTask { } } } -} \ No newline at end of file +}