blob: 8e68b508a5fd996738f0c9de9b34817c944a2c6d [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 */
Yigit Boyar450ed382017-03-02 09:48:25 -080016
Yigit Boyar2eb51992016-12-13 15:00:07 -080017import org.gradle.internal.os.OperatingSystem
Yigit Boyar2eb51992016-12-13 15:00:07 -080018def root = ext.supportRootFolder
Sergey Vasilinetse69e4702017-02-10 02:26:10 -080019ext.usePrebuilts = "true" // for doclava
Yigit Boyar450ed382017-03-02 09:48:25 -080020ext.inAppToolkitProject = rootProject.name == "app-toolkit"
21
22if (ext.inAppToolkitProject) {
Sergey Vasilinetse69e4702017-02-10 02:26:10 -080023 apply from: "${ext.supportRootFolder}/buildSrc/init.gradle"
Yigit Boyar450ed382017-03-02 09:48:25 -080024 init.loadDefaultVersions()
25 init.setSdkInLocalPropertiesFile()
Sergey Vasilinetse69e4702017-02-10 02:26:10 -080026}
Yigit Boyar450ed382017-03-02 09:48:25 -080027
Yigit Boyar2eb51992016-12-13 15:00:07 -080028def checkoutRoot = "${root}/../.."
29ext.checkoutRoot = checkoutRoot
30ext.prebuiltsRoot = "$checkoutRoot/prebuilts"
31ext.prebuiltsRootUri = "file://${prebuiltsRoot}"
32
Yigit Boyar2eb51992016-12-13 15:00:07 -080033final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux'
Sergey Vasilinetsc90eb812016-12-14 00:08:04 -080034final String fullSdkPath = new File("${checkoutRoot}/prebuilts/fullsdk-${platform}").getCanonicalPath()
35System.setProperty('android.home', fullSdkPath)
Yigit Boyar2eb51992016-12-13 15:00:07 -080036File props = file("local.properties")
37props.write "sdk.dir=${fullSdkPath}"
38
39def buildDir
40def distDir
Sergey Vasilinets31be41e2016-12-19 17:07:15 -080041def supportLibBuildDir
Yigit Boyar450ed382017-03-02 09:48:25 -080042
Yigit Boyarbeb35b42016-12-28 23:00:28 +010043if (ext.runningInBuildServer) {
Sergey Vasilinets31be41e2016-12-19 17:07:15 -080044 supportLibBuildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile();
45 buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/app-toolkit/build').getCanonicalFile()
Yigit Boyar2eb51992016-12-13 15:00:07 -080046 distDir = new File(System.env.DIST_DIR).getCanonicalFile()
47} else {
Sergey Vasilinets31be41e2016-12-19 17:07:15 -080048 supportLibBuildDir = file("${checkoutRoot}/out/host/gradle/frameworks/support/build")
Yigit Boyared4fb5a2016-12-15 14:43:20 -080049 buildDir = file("${checkoutRoot}/out/host/gradle/frameworks/app-toolkit/build")
Yigit Boyar450ed382017-03-02 09:48:25 -080050 distDir = file("${checkoutRoot}/out/dist")
Yigit Boyar2eb51992016-12-13 15:00:07 -080051}
Sergey Vasilinets25220c42016-12-20 21:14:36 -080052
Yigit Boyar2eb51992016-12-13 15:00:07 -080053def localMavenRepo = "file://${new File(buildDir, "flatfoot_repo").absolutePath}"
54ext.testApkDistOut = distDir
Yigit Boyarbeb35b42016-12-28 23:00:28 +010055ext.testResultsDistDir = new File(distDir, "host-test-reports")
Yigit Boyar2eb51992016-12-13 15:00:07 -080056ext.localMavenRepo = localMavenRepo
Yigit Boyar450ed382017-03-02 09:48:25 -080057file(localMavenRepo).delete()
58file(localMavenRepo).mkdirs()
Yigit Boyar2eb51992016-12-13 15:00:07 -080059
60ext.repoNames = ["$prebuiltsRootUri/maven_repo",
61 "$prebuiltsRootUri/gradle-plugin",
62 "$prebuiltsRootUri/tools/common/m2/repository",
63 "$prebuiltsRootUri/tools/common/m2/internal",
64 "$prebuiltsRootUri/tools/common/offline-m2",
65 "$prebuiltsRootUri/maven_repo/android",
66 "file://$fullSdkPath/extras/android/m2repository",
Sergey Vasilinets31be41e2016-12-19 17:07:15 -080067 "file://${new File(supportLibBuildDir, "support_repo").absolutePath}"]
Yigit Boyar2eb51992016-12-13 15:00:07 -080068
Yigit Boyar450ed382017-03-02 09:48:25 -080069apply from: "${ext.supportRootFolder}/app-toolkit/dependencies.gradle"
Yigit Boyar2eb51992016-12-13 15:00:07 -080070ext.enablePublicRepos = System.getenv("ALLOW_PUBLIC_REPOS")
71
72// repository creation task
Yigit Boyar450ed382017-03-02 09:48:25 -080073def buildServerAnchorTask = rootProject.tasks.create(name : "runBuildServerCompilationTasks",
74 description: "Anchor task for everything we want to run in build server.")
75
Yigit Boyar450ed382017-03-02 09:48:25 -080076if (ext.inAppToolkitProject) {
77 init.addMavenRepositories(repositories)
78 init.setupRepoOutAndBuildNumber()
79 init.configureSubProjects()
80 init.setupRelease()
81 init.enableDoclavaAndJDiff(this)
82}
83
Yigit Boyare1bbf712017-03-08 13:52:37 -080084
85// flatfoot docs
86def zipFlatfootDocsTask = rootProject.tasks.create(name : "createFlatfootDocsArchive", type : Zip) {
87 from rootProject.docsDir
88 destinationDir distDir
89 baseName = String.format("flatfoot-docs-%s", rootProject.ext.flatfoot.release_version)
90}
91
92buildServerAnchorTask.dependsOn zipFlatfootDocsTask
93zipFlatfootDocsTask.dependsOn rootProject.tasks["generateDocs"]
94
Yigit Boyar24ac5432017-03-07 11:05:12 -080095// Disable API checks for now.
96checkApiStable.enabled = false
97checkApi.enabled = false
98
Yigit Boyar450ed382017-03-02 09:48:25 -080099buildServerAnchorTask.dependsOn createArchive
Yigit Boyar450ed382017-03-02 09:48:25 -0800100
Yigit Boyar2eb51992016-12-13 15:00:07 -0800101subprojects {
102 configurations.all {
103 resolutionStrategy {
104 force "com.google.guava:guava-jdk5:17.0"
105 }
106 }
Yigit Boyar450ed382017-03-02 09:48:25 -0800107 init.addMavenRepositories(project.repositories)
Sergey Vasilinetse69e4702017-02-10 02:26:10 -0800108 if (project.name == 'doclava' || project.name == 'jdiff') {
109 project.tasks.whenTaskAdded { task ->
110 if (task instanceof org.gradle.api.tasks.testing.Test) {
111 task.enabled = false
112 }
113 }
114 return
115 }
Yigit Boyar83ebc492017-03-08 20:43:45 -0800116
Yigit Boyar450ed382017-03-02 09:48:25 -0800117 def mavenGroup = project.getPath().split(":")[1]
118 if (mavenGroup != "room" && mavenGroup != "lifecycle" && mavenGroup != "apptoolkit-core") {
119 return
Yigit Boyar2eb51992016-12-13 15:00:07 -0800120 }
Yigit Boyar54016462017-03-06 17:24:21 -0800121 project.tasks.whenTaskAdded { task ->
122 if (task.name.startsWith("assembleAndroidTest")) {
123 buildServerAnchorTask.dependsOn task
124 }
125 }
Yigit Boyar450ed382017-03-02 09:48:25 -0800126 project.group = "com.android.support.$mavenGroup"
127 project.version = flatfoot.release_version
128
Yigit Boyar4d19f2e2017-01-23 13:29:01 -0800129 if (enablePublicRepos) {
130 project.afterEvaluate {
131 apply plugin: 'com.android.databinding.localizemaven'
132 project.localizeMaven {
133 localRepoDir = file("$prebuiltsRoot/tools/common/m2/repository")
134 otherRepoDirs = repoNames
135 }
136 }
137 }
Yigit Boyar2eb51992016-12-13 15:00:07 -0800138}
139
Yigit Boyar2eb51992016-12-13 15:00:07 -0800140def createKotlinCheckstyle(Project project) {
Sergey Vasilinets25220c42016-12-20 21:14:36 -0800141 def fs = files();
142 fs += files(project.sourceSets.main.allJava.srcDirs.collect{fileTree(it)})
143 fs += files(project.sourceSets.test.allJava.srcDirs.collect{fileTree(it)})
144 fs = fs.filter{file -> file.name.endsWith(".kt")}
145 def kotlinCheckstyle = createCheckstyleTask(project, 'checkstyleKotlin',
146 "${project.rootProject.ext.supportRootFolder}/app-toolkit/kotlin-checkstyle.xml",
147 fs.files)
148
Yigit Boyar2eb51992016-12-13 15:00:07 -0800149 project.tasks.findByName("check").dependsOn(kotlinCheckstyle)
150 // poor man's line length check
151 def lineCheck = project.tasks.create(name : "lineLengthCheck") {
152 (project.sourceSets.main.allJava.getSourceDirectories() +
153 project.sourceSets.test.allJava.getSourceDirectories()).each { sourceDir ->
154 fileTree(dir : sourceDir, include : "**/*.kt").each{ file ->
155 file.readLines().eachWithIndex { line, index ->
156 if (line.size() > 100) {
157 throw new Exception("line too long: file: $file line:$index line: $line")
158 }
159 }
160 }
161 }
162 }
163 kotlinCheckstyle.dependsOn(lineCheck)
164}
165
166def createAndroidCheckstyle(Project project) {
Sergey Vasilinets25220c42016-12-20 21:14:36 -0800167 def fs = files()
168 if (project.hasProperty('android')) {
169 fs += files(project.android.sourceSets.main.java.getSrcDirs().collect {fileTree(it)})
Yigit Boyar2eb51992016-12-13 15:00:07 -0800170 }
Sergey Vasilinets25220c42016-12-20 21:14:36 -0800171 if (project.sourceSets.hasProperty('main')) {
172 fs += files(project.sourceSets.main.allJava)
173 }
174 fs = fs.filter{file -> file.name.endsWith(".java")}
175
176 def checkStyle = createCheckstyleTask(project, 'checkstyleAndroid',
177 "${project.rootProject.ext.checkoutRoot}/prebuilts/checkstyle/android-style.xml",
178 fs.files)
179 project.tasks.findByName("check").dependsOn(checkStyle)
180}
181
182def createCheckstyleTask(project, taskName, configFile, inputFiles) {
183 def arguments = ['-c', configFile]
184 arguments.addAll(inputFiles)
185 def checkStyle = project.tasks.create(name : taskName, type: JavaExec) {
186 inputs.files(inputFiles).skipWhenEmpty()
187 main = "com.puppycrawl.tools.checkstyle.Main"
188 args = arguments
189 classpath = files(file("${project.rootProject.ext.checkoutRoot}/prebuilts/checkstyle/checkstyle.jar").path)
190 }
191 return checkStyle;
Yigit Boyar2eb51992016-12-13 15:00:07 -0800192}
193
Yigit Boyar2eb51992016-12-13 15:00:07 -0800194ext.createKotlinCheckstyle = this.&createKotlinCheckstyle
Sergey Vasilinetsc90eb812016-12-14 00:08:04 -0800195ext.createAndroidCheckstyle = this.&createAndroidCheckstyle