diff --git a/build/dependencies/setupAndroidSdk.gradle b/build/dependencies/setupAndroidSdk.gradle index 67cf69d1fbe6..6922b44c0aa7 100644 --- a/build/dependencies/setupAndroidSdk.gradle +++ b/build/dependencies/setupAndroidSdk.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2019 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,122 +14,47 @@ * limitations under the License. */ -buildscript { - repositories { - maven { url "https://cache-redirector.jetbrains.com/plugins.gradle.org" } - } - dependencies { - classpath "de.undercouch:gradle-download-task:3.4.2" - } -} -apply plugin: "de.undercouch.download" - -import de.undercouch.gradle.tasks.download.Download - -def currentOs = org.gradle.internal.os.OperatingSystem.current() - -task downloadGradleDistribution(type: Download) { - src "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-4.10.1-bin.zip" - dest "$buildDir/android-sdk/tools/external/gradle/gradle-4.10.1-bin.zip" - onlyIf { !dest.exists() } -} - -ext.saveVersion = { Download task -> - def filename = task.dest.name.substring(0, task.dest.name.lastIndexOf('.')) - new File(task.dest.parentFile, filename).text = task.src.toString() -} - -ext.cleanUp = { Copy task -> - task.destinationDir.deleteDir() -} - -ext.isStale = { Download task -> - def filename = task.dest.name.substring(0, task.dest.name.lastIndexOf('.')) - def file = new File(task.dest.parentFile, filename) - return !file.exists() || file.text != task.src.toString() -} - -task downloadGradleDistribution2(type: Download) { - src "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-2.4-bin.zip" - dest "$buildDir/android-sdk/tools/external/gradle/gradle-2.4-bin.zip" - onlyIf { !dest.exists() } -} - -task downloadOfflineRepo(type: Download) { - src "https://cache-redirector.jetbrains.com/intellij-third-party-dependencies/android-sdk-offline-repo/3.3.2/android-sdk-offline-repo.zip" - dest "$buildDir/android-sdk/offline_repo_repo.zip" - onlyIf { - isStale(it) || !dest.exists() && isEmpty(setupOfflineRepo.destinationDir) - } - doLast { - saveVersion(it) - cleanUp(setupOfflineRepo) - } -} - -task downloadKotlinPlugin(type: Download) { - src "https://cache-redirector.jetbrains.com/intellij-third-party-dependencies/android-sdk-kotlin-plugin/1.3.21-release-IJ2019.1/android-sdk-kotlin-plugin.zip" - dest "$buildDir/android-sdk/kotlin-plugin.zip" - onlyIf { - isStale(it) || !dest.exists() && isEmpty(setupKotlinPluginForAndroid.destinationDir) - } - doLast { - saveVersion(it) - cleanUp(setupKotlinPluginForAndroid) - } -} - -task setupKotlinPluginForAndroid(dependsOn: downloadKotlinPlugin, type: Copy) { - from zipTree(downloadKotlinPlugin.outputs.files.singleFile) - into "$buildDir/android-sdk/prebuilts/tools/common/kotlin-plugin" - onlyIf { - isStale(downloadKotlinPlugin) || isEmpty(destinationDir) - } -} - -task setupOfflineRepo(dependsOn: downloadOfflineRepo, type: Copy) { - from zipTree(downloadOfflineRepo.outputs.files.singleFile) - into "$buildDir/android-sdk/prebuilts/tools/common/m2/repository" - onlyIf { - isStale(downloadOfflineRepo) || isEmpty(destinationDir) - } -} - -task downloadAndroidSdk(type: Download) { - def osFamily = currentOs.familyName - src "https://cache-redirector.jetbrains.com/intellij-third-party-dependencies/android-sdk/${osFamily}.3.3.3/android-sdk.tar.gz" - dest "$buildDir/android-sdk/${osFamily}.tar.gz" - onlyIf { - isStale(it) || !dest.exists() && isEmpty(untarAndroidSdk.destinationDir) && !currentOs.isMacOsX() - } - doLast { - saveVersion(it) - cleanUp(untarAndroidSdk) - } -} - -task untarAndroidSdk(dependsOn: downloadAndroidSdk, type: Copy) { - from tarTree(downloadAndroidSdk.outputs.files.singleFile) - into "$buildDir/android-sdk/prebuilts/studio/sdk" - onlyIf { - isStale(downloadAndroidSdk) || !currentOs.isMacOsX() && isEmpty(destinationDir) - } - outputs.dir("$buildDir/android-sdk/prebuilts/tools/common") - doLast { - file("$buildDir/android-sdk/prebuilts/tools/common/offline-m2").mkdirs() - } -} - -task setupAndroidSdk(dependsOn: [untarAndroidSdk, downloadGradleDistribution, - downloadGradleDistribution2, setupOfflineRepo, - setupKotlinPluginForAndroid]) { - doLast { - [downloadAndroidSdk, downloadOfflineRepo, downloadKotlinPlugin].each { - it.outputs.files.singleFile.delete() +repositories { + maven { url 'https://cache-redirector.jetbrains.com/jetbrains.bintray.com/intellij-third-party-dependencies/' } + ivy { + // TODO: re-publish android-sdk:android-sdk using maven layout and remove Ivy repository + url 'https://cache-redirector.jetbrains.com/jetbrains.bintray.com/intellij-third-party-dependencies/' + patternLayout { + artifact "[module]/[revision]/[artifact].[ext]" } } } -static def isEmpty(File dir) { - dir.list() == null || dir.list().length == 0 -} \ No newline at end of file +configurations { + androidOfflineRepo + androidSdk +} + +def currentOs = org.gradle.internal.os.OperatingSystem.current() +def osFamily = currentOs.familyName + +dependencies { + androidOfflineRepo "org.jetbrains.intellij.deps.android.tools:android-sdk-offline-repo:26.5.0@zip" + androidSdk "android-sdk:android-sdk:${osFamily}.3.3.3:@tar.gz" +} + +/* First we setup an offline-repo. This will remove all the alien files from .../android-sdk. + Later we will create an overlay with Android SDK and KotlinPlugin artifacts */ +task syncOfflineRepo(dependsOn: configurations.androidOfflineRepo, type: Sync) { + from zipTree(configurations.androidOfflineRepo.singleFile) + into "${project.buildDir}/android-sdk" +} + +task syncKotlinPluginForAndroid(dependsOn: [setupKotlinPlugin, syncOfflineRepo], type: Sync) { + from "$buildDir/kotlin" + into "$buildDir/android-sdk/prebuilts/tools/common/kotlin-plugin" +} + +task syncAndroidSdk(dependsOn: [configurations.androidSdk, syncOfflineRepo], type: Sync) { + from tarTree(resources.gzip(configurations.androidSdk.singleFile)) + into "$buildDir/android-sdk/prebuilts/studio/sdk" +} + +task setupAndroidSdk(dependsOn: [syncOfflineRepo, syncKotlinPluginForAndroid, syncAndroidSdk]) { + // This is entry point: invoke this task to setup android sdk and all the artifacts required to run android-plugin unit tests +}