blob: f88900f08cfe53e9ef029ebc547e536c164140d9 [file] [log] [blame]
Yigit Boyar2eb51992016-12-13 15:00:07 -08001/*
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 */
16import org.gradle.internal.os.OperatingSystem
Sergey Vasilinetse69e4702017-02-10 02:26:10 -080017ext.integrateWithSupportLib = System.getenv("WITH_SUPPORTLIB")
Yigit Boyar2eb51992016-12-13 15:00:07 -080018def root = ext.supportRootFolder
Sergey Vasilinetse69e4702017-02-10 02:26:10 -080019ext.usePrebuilts = "true" // for doclava
20if (ext.integrateWithSupportLib) {
21 apply from: "${ext.supportRootFolder}/buildSrc/init.gradle"
22}
Yigit Boyar2eb51992016-12-13 15:00:07 -080023def checkoutRoot = "${root}/../.."
24ext.checkoutRoot = checkoutRoot
25ext.prebuiltsRoot = "$checkoutRoot/prebuilts"
26ext.prebuiltsRootUri = "file://${prebuiltsRoot}"
27
28
29final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux'
Sergey Vasilinetsc90eb812016-12-14 00:08:04 -080030final String fullSdkPath = new File("${checkoutRoot}/prebuilts/fullsdk-${platform}").getCanonicalPath()
31System.setProperty('android.home', fullSdkPath)
Yigit Boyar2eb51992016-12-13 15:00:07 -080032File props = file("local.properties")
33props.write "sdk.dir=${fullSdkPath}"
34
35def buildDir
36def distDir
Sergey Vasilinets31be41e2016-12-19 17:07:15 -080037def supportLibBuildDir
Yigit Boyarbeb35b42016-12-28 23:00:28 +010038ext.runningInBuildServer = System.env.DIST_DIR != null && System.env.OUT_DIR != null
39if (ext.runningInBuildServer) {
Sergey Vasilinets31be41e2016-12-19 17:07:15 -080040 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 Boyar2eb51992016-12-13 15:00:07 -080042 distDir = new File(System.env.DIST_DIR).getCanonicalFile()
43} else {
Sergey Vasilinets31be41e2016-12-19 17:07:15 -080044 supportLibBuildDir = file("${checkoutRoot}/out/host/gradle/frameworks/support/build")
Yigit Boyared4fb5a2016-12-15 14:43:20 -080045 buildDir = file("${checkoutRoot}/out/host/gradle/frameworks/app-toolkit/build")
Yigit Boyar2eb51992016-12-13 15:00:07 -080046 distDir = file("${project.rootDir}/../../out/dist")
47}
Sergey Vasilinets25220c42016-12-20 21:14:36 -080048
Yigit Boyar2eb51992016-12-13 15:00:07 -080049def localMavenRepo = "file://${new File(buildDir, "flatfoot_repo").absolutePath}"
50ext.testApkDistOut = distDir
Yigit Boyarbeb35b42016-12-28 23:00:28 +010051ext.testResultsDistDir = new File(distDir, "host-test-reports")
Yigit Boyar2eb51992016-12-13 15:00:07 -080052ext.localMavenRepo = localMavenRepo
53
54ext.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 Vasilinets31be41e2016-12-19 17:07:15 -080061 "file://${new File(supportLibBuildDir, "support_repo").absolutePath}"]
Yigit Boyar2eb51992016-12-13 15:00:07 -080062
63ext.kotlin_version = "1.0.5"
Yigit Boyardabfd6d2016-12-16 11:26:10 -080064ext.android_gradle_plugin_version = "2.2.4"
Yigit Boyar2eb51992016-12-13 15:00:07 -080065ext.auto_common_version = "0.6"
66ext.javapoet_version = "1.8.0"
67ext.compile_testing_version = "0.9"
68ext.localize_maven_version = "1.1"
69ext.support_lib_version = "25.1.0-SNAPSHOT"
70ext.junit_version = "4.12"
71ext.mockito_version = "1.9.5"
72ext.min_sdk_version = 14
73ext.target_sdk_version = 26
74ext.compile_sdk_version = 26
75ext.build_tools_version = "26.0.0"
76ext.intellij_annotation = "12.0"
77ext.espresso_version = "2.2.2"
78ext.release_version = "1.0-SNAPSHOT"
Yigit Boyarfe127e52017-01-27 14:30:20 -080079ext.atsl_version = "0.6-alpha"
Yigit Boyar88865f72017-01-23 17:51:49 -080080// this Xerial version is newer than we want but we need it to fix
81// https://github.com/xerial/sqlite-jdbc/issues/97
82ext.xerial_version = "3.16.1"
83ext.antlr_version = "4.5.3"
Yigit Boyar2eb51992016-12-13 15:00:07 -080084ext.enablePublicRepos = System.getenv("ALLOW_PUBLIC_REPOS")
85
86// repository creation task
87def 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
94subprojects {
95 configurations.all {
96 resolutionStrategy {
97 force "com.google.guava:guava-jdk5:17.0"
98 }
99 }
Sergey Vasilinetse69e4702017-02-10 02:26:10 -0800100 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 Boyar2eb51992016-12-13 15:00:07 -0800108 def mavenGroup = project.getPath().split(":")[1]
109 project.group = "com.android.support.$mavenGroup"
110 project.version = release_version
111 addRepos(project.repositories)
Yigit Boyared4fb5a2016-12-15 14:43:20 -0800112
Yigit Boyarbeb35b42016-12-28 23:00:28 +0100113 // 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 Boyar2eb51992016-12-13 15:00:07 -0800148 }
149 }
150 }
151 }
152 }
Yigit Boyarbeb35b42016-12-28 23:00:28 +0100153 }
154
155 project.afterEvaluate {
Yigit Boyar2eb51992016-12-13 15:00:07 -0800156 if (project.plugins.hasPlugin('maven')) {
157 def uploadArchivesTask = project.tasks.findByPath("uploadArchives")
158 if (uploadArchivesTask != null) {
159 createRepoDistTask.dependsOn(uploadArchivesTask)
160 }
161 }
162 }
Yigit Boyar4d19f2e2017-01-23 13:29:01 -0800163
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 Boyar2eb51992016-12-13 15:00:07 -0800173}
174
175
176
177def 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
189def createKotlinCheckstyle(Project project) {
Sergey Vasilinets25220c42016-12-20 21:14:36 -0800190 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 Boyar2eb51992016-12-13 15:00:07 -0800198 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
215def createAndroidCheckstyle(Project project) {
Sergey Vasilinets25220c42016-12-20 21:14:36 -0800216 def fs = files()
217 if (project.hasProperty('android')) {
218 fs += files(project.android.sourceSets.main.java.getSrcDirs().collect {fileTree(it)})
Yigit Boyar2eb51992016-12-13 15:00:07 -0800219 }
Sergey Vasilinets25220c42016-12-20 21:14:36 -0800220 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
231def 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 Boyar2eb51992016-12-13 15:00:07 -0800241}
242
243def buildDir
244if (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}
249ext.localMavenRepo = "file://${new File(buildDir, "flatfoot_repo").absolutePath}"
250ext.addRepos = this.&addRepos
251ext.createKotlinCheckstyle = this.&createKotlinCheckstyle
Sergey Vasilinetsc90eb812016-12-14 00:08:04 -0800252ext.createAndroidCheckstyle = this.&createAndroidCheckstyle