Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | import org.gradle.internal.os.OperatingSystem |
Sergey Vasilinets | e69e470 | 2017-02-10 02:26:10 -0800 | [diff] [blame^] | 17 | ext.integrateWithSupportLib = System.getenv("WITH_SUPPORTLIB") |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 18 | def root = ext.supportRootFolder |
Sergey Vasilinets | e69e470 | 2017-02-10 02:26:10 -0800 | [diff] [blame^] | 19 | ext.usePrebuilts = "true" // for doclava |
| 20 | if (ext.integrateWithSupportLib) { |
| 21 | apply from: "${ext.supportRootFolder}/buildSrc/init.gradle" |
| 22 | } |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 23 | def checkoutRoot = "${root}/../.." |
| 24 | ext.checkoutRoot = checkoutRoot |
| 25 | ext.prebuiltsRoot = "$checkoutRoot/prebuilts" |
| 26 | ext.prebuiltsRootUri = "file://${prebuiltsRoot}" |
| 27 | |
| 28 | |
| 29 | final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux' |
Sergey Vasilinets | c90eb81 | 2016-12-14 00:08:04 -0800 | [diff] [blame] | 30 | final String fullSdkPath = new File("${checkoutRoot}/prebuilts/fullsdk-${platform}").getCanonicalPath() |
| 31 | System.setProperty('android.home', fullSdkPath) |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 32 | File props = file("local.properties") |
| 33 | props.write "sdk.dir=${fullSdkPath}" |
| 34 | |
| 35 | def buildDir |
| 36 | def distDir |
Sergey Vasilinets | 31be41e | 2016-12-19 17:07:15 -0800 | [diff] [blame] | 37 | def supportLibBuildDir |
Yigit Boyar | beb35b4 | 2016-12-28 23:00:28 +0100 | [diff] [blame] | 38 | ext.runningInBuildServer = System.env.DIST_DIR != null && System.env.OUT_DIR != null |
| 39 | if (ext.runningInBuildServer) { |
Sergey Vasilinets | 31be41e | 2016-12-19 17:07:15 -0800 | [diff] [blame] | 40 | supportLibBuildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile(); |
| 41 | buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/app-toolkit/build').getCanonicalFile() |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 42 | distDir = new File(System.env.DIST_DIR).getCanonicalFile() |
| 43 | } else { |
Sergey Vasilinets | 31be41e | 2016-12-19 17:07:15 -0800 | [diff] [blame] | 44 | supportLibBuildDir = file("${checkoutRoot}/out/host/gradle/frameworks/support/build") |
Yigit Boyar | ed4fb5a | 2016-12-15 14:43:20 -0800 | [diff] [blame] | 45 | buildDir = file("${checkoutRoot}/out/host/gradle/frameworks/app-toolkit/build") |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 46 | distDir = file("${project.rootDir}/../../out/dist") |
| 47 | } |
Sergey Vasilinets | 25220c4 | 2016-12-20 21:14:36 -0800 | [diff] [blame] | 48 | |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 49 | def localMavenRepo = "file://${new File(buildDir, "flatfoot_repo").absolutePath}" |
| 50 | ext.testApkDistOut = distDir |
Yigit Boyar | beb35b4 | 2016-12-28 23:00:28 +0100 | [diff] [blame] | 51 | ext.testResultsDistDir = new File(distDir, "host-test-reports") |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 52 | ext.localMavenRepo = localMavenRepo |
| 53 | |
| 54 | ext.repoNames = ["$prebuiltsRootUri/maven_repo", |
| 55 | "$prebuiltsRootUri/gradle-plugin", |
| 56 | "$prebuiltsRootUri/tools/common/m2/repository", |
| 57 | "$prebuiltsRootUri/tools/common/m2/internal", |
| 58 | "$prebuiltsRootUri/tools/common/offline-m2", |
| 59 | "$prebuiltsRootUri/maven_repo/android", |
| 60 | "file://$fullSdkPath/extras/android/m2repository", |
Sergey Vasilinets | 31be41e | 2016-12-19 17:07:15 -0800 | [diff] [blame] | 61 | "file://${new File(supportLibBuildDir, "support_repo").absolutePath}"] |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 62 | |
| 63 | ext.kotlin_version = "1.0.5" |
Yigit Boyar | dabfd6d | 2016-12-16 11:26:10 -0800 | [diff] [blame] | 64 | ext.android_gradle_plugin_version = "2.2.4" |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 65 | ext.auto_common_version = "0.6" |
| 66 | ext.javapoet_version = "1.8.0" |
| 67 | ext.compile_testing_version = "0.9" |
| 68 | ext.localize_maven_version = "1.1" |
| 69 | ext.support_lib_version = "25.1.0-SNAPSHOT" |
| 70 | ext.junit_version = "4.12" |
| 71 | ext.mockito_version = "1.9.5" |
| 72 | ext.min_sdk_version = 14 |
| 73 | ext.target_sdk_version = 26 |
| 74 | ext.compile_sdk_version = 26 |
| 75 | ext.build_tools_version = "26.0.0" |
| 76 | ext.intellij_annotation = "12.0" |
| 77 | ext.espresso_version = "2.2.2" |
| 78 | ext.release_version = "1.0-SNAPSHOT" |
Yigit Boyar | fe127e5 | 2017-01-27 14:30:20 -0800 | [diff] [blame] | 79 | ext.atsl_version = "0.6-alpha" |
Yigit Boyar | 88865f7 | 2017-01-23 17:51:49 -0800 | [diff] [blame] | 80 | // this Xerial version is newer than we want but we need it to fix |
| 81 | // https://github.com/xerial/sqlite-jdbc/issues/97 |
| 82 | ext.xerial_version = "3.16.1" |
| 83 | ext.antlr_version = "4.5.3" |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 84 | ext.enablePublicRepos = System.getenv("ALLOW_PUBLIC_REPOS") |
| 85 | |
| 86 | // repository creation task |
| 87 | def createRepoDistTask = rootProject.tasks.create(name : "createArchive", type: Zip) { |
| 88 | from localMavenRepo |
| 89 | destinationDir distDir |
| 90 | into 'appToolkitRepository' |
| 91 | baseName = String.format("sdk-repo-linux-appToolkitRepository-%s", rootProject.ext.release_version) |
| 92 | } |
| 93 | |
| 94 | subprojects { |
| 95 | configurations.all { |
| 96 | resolutionStrategy { |
| 97 | force "com.google.guava:guava-jdk5:17.0" |
| 98 | } |
| 99 | } |
Sergey Vasilinets | e69e470 | 2017-02-10 02:26:10 -0800 | [diff] [blame^] | 100 | if (project.name == 'doclava' || project.name == 'jdiff') { |
| 101 | project.tasks.whenTaskAdded { task -> |
| 102 | if (task instanceof org.gradle.api.tasks.testing.Test) { |
| 103 | task.enabled = false |
| 104 | } |
| 105 | } |
| 106 | return |
| 107 | } |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 108 | def mavenGroup = project.getPath().split(":")[1] |
| 109 | project.group = "com.android.support.$mavenGroup" |
| 110 | project.version = release_version |
| 111 | addRepos(project.repositories) |
Yigit Boyar | ed4fb5a | 2016-12-15 14:43:20 -0800 | [diff] [blame] | 112 | |
Yigit Boyar | beb35b4 | 2016-12-28 23:00:28 +0100 | [diff] [blame] | 113 | // copy test results to DIST |
| 114 | project.tasks.whenTaskAdded { task -> |
| 115 | if (task instanceof org.gradle.api.tasks.testing.Test) { |
| 116 | def junitReport = task.reports.junitXml |
| 117 | if (junitReport.enabled) { |
| 118 | def zipTask = project.tasks.create(name : "zipResultsOf${task.name.capitalize()}", type : Zip) { |
| 119 | destinationDir(testResultsDistDir) |
| 120 | archiveName("${project.name}.zip") |
| 121 | } |
| 122 | if (project.rootProject.ext.runningInBuildServer) { |
| 123 | task.ignoreFailures = true |
| 124 | } |
| 125 | task.finalizedBy zipTask |
| 126 | task.doFirst { |
| 127 | zipTask.from(junitReport.destination) |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // Copy instrumentation test APKs and app APKs into the dist dir |
| 134 | // For test apks, they are uploaded only if we have java test sources. |
| 135 | // For regular app apks, they are uploaded only if they have java sources. |
| 136 | project.tasks.whenTaskAdded { task -> |
| 137 | if (task.name.startsWith("packageDebug")) { |
| 138 | def testApk = task.name.contains("AndroidTest") |
| 139 | task.doLast { |
| 140 | def source = testApk ? project.android.sourceSets.androidTest |
| 141 | : project.android.sourceSets.main |
| 142 | if (task.hasProperty("outputFile") && !source.java.sourceFiles.isEmpty()) { |
| 143 | copy { |
| 144 | from(task.outputFile) |
| 145 | into(rootProject.ext.testApkDistOut) |
| 146 | rename { String fileName -> |
| 147 | "${project.getPath().replace(':', '-').substring(1)}_${fileName}" |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
Yigit Boyar | beb35b4 | 2016-12-28 23:00:28 +0100 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | project.afterEvaluate { |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 156 | if (project.plugins.hasPlugin('maven')) { |
| 157 | def uploadArchivesTask = project.tasks.findByPath("uploadArchives") |
| 158 | if (uploadArchivesTask != null) { |
| 159 | createRepoDistTask.dependsOn(uploadArchivesTask) |
| 160 | } |
| 161 | } |
| 162 | } |
Yigit Boyar | 4d19f2e | 2017-01-23 13:29:01 -0800 | [diff] [blame] | 163 | |
| 164 | if (enablePublicRepos) { |
| 165 | project.afterEvaluate { |
| 166 | apply plugin: 'com.android.databinding.localizemaven' |
| 167 | project.localizeMaven { |
| 168 | localRepoDir = file("$prebuiltsRoot/tools/common/m2/repository") |
| 169 | otherRepoDirs = repoNames |
| 170 | } |
| 171 | } |
| 172 | } |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | |
| 176 | |
| 177 | def addRepos(RepositoryHandler handler) { |
| 178 | repoNames.each { repo -> |
| 179 | handler.maven { |
| 180 | url repo |
| 181 | } |
| 182 | if (ext.enablePublicRepos) { |
| 183 | handler.mavenCentral() |
| 184 | handler.jcenter() |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | def createKotlinCheckstyle(Project project) { |
Sergey Vasilinets | 25220c4 | 2016-12-20 21:14:36 -0800 | [diff] [blame] | 190 | def fs = files(); |
| 191 | fs += files(project.sourceSets.main.allJava.srcDirs.collect{fileTree(it)}) |
| 192 | fs += files(project.sourceSets.test.allJava.srcDirs.collect{fileTree(it)}) |
| 193 | fs = fs.filter{file -> file.name.endsWith(".kt")} |
| 194 | def kotlinCheckstyle = createCheckstyleTask(project, 'checkstyleKotlin', |
| 195 | "${project.rootProject.ext.supportRootFolder}/app-toolkit/kotlin-checkstyle.xml", |
| 196 | fs.files) |
| 197 | |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 198 | project.tasks.findByName("check").dependsOn(kotlinCheckstyle) |
| 199 | // poor man's line length check |
| 200 | def lineCheck = project.tasks.create(name : "lineLengthCheck") { |
| 201 | (project.sourceSets.main.allJava.getSourceDirectories() + |
| 202 | project.sourceSets.test.allJava.getSourceDirectories()).each { sourceDir -> |
| 203 | fileTree(dir : sourceDir, include : "**/*.kt").each{ file -> |
| 204 | file.readLines().eachWithIndex { line, index -> |
| 205 | if (line.size() > 100) { |
| 206 | throw new Exception("line too long: file: $file line:$index line: $line") |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | kotlinCheckstyle.dependsOn(lineCheck) |
| 213 | } |
| 214 | |
| 215 | def createAndroidCheckstyle(Project project) { |
Sergey Vasilinets | 25220c4 | 2016-12-20 21:14:36 -0800 | [diff] [blame] | 216 | def fs = files() |
| 217 | if (project.hasProperty('android')) { |
| 218 | fs += files(project.android.sourceSets.main.java.getSrcDirs().collect {fileTree(it)}) |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 219 | } |
Sergey Vasilinets | 25220c4 | 2016-12-20 21:14:36 -0800 | [diff] [blame] | 220 | if (project.sourceSets.hasProperty('main')) { |
| 221 | fs += files(project.sourceSets.main.allJava) |
| 222 | } |
| 223 | fs = fs.filter{file -> file.name.endsWith(".java")} |
| 224 | |
| 225 | def checkStyle = createCheckstyleTask(project, 'checkstyleAndroid', |
| 226 | "${project.rootProject.ext.checkoutRoot}/prebuilts/checkstyle/android-style.xml", |
| 227 | fs.files) |
| 228 | project.tasks.findByName("check").dependsOn(checkStyle) |
| 229 | } |
| 230 | |
| 231 | def createCheckstyleTask(project, taskName, configFile, inputFiles) { |
| 232 | def arguments = ['-c', configFile] |
| 233 | arguments.addAll(inputFiles) |
| 234 | def checkStyle = project.tasks.create(name : taskName, type: JavaExec) { |
| 235 | inputs.files(inputFiles).skipWhenEmpty() |
| 236 | main = "com.puppycrawl.tools.checkstyle.Main" |
| 237 | args = arguments |
| 238 | classpath = files(file("${project.rootProject.ext.checkoutRoot}/prebuilts/checkstyle/checkstyle.jar").path) |
| 239 | } |
| 240 | return checkStyle; |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | def buildDir |
| 244 | if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) { |
| 245 | buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile() |
| 246 | } else { |
| 247 | buildDir = file("${ext.prebuiltsRootUri}/../out/host/gradle/frameworks/support/build") |
| 248 | } |
| 249 | ext.localMavenRepo = "file://${new File(buildDir, "flatfoot_repo").absolutePath}" |
| 250 | ext.addRepos = this.&addRepos |
| 251 | ext.createKotlinCheckstyle = this.&createKotlinCheckstyle |
Sergey Vasilinets | c90eb81 | 2016-12-14 00:08:04 -0800 | [diff] [blame] | 252 | ext.createAndroidCheckstyle = this.&createAndroidCheckstyle |