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 | */ |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 16 | |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 17 | import org.gradle.internal.os.OperatingSystem |
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 |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 20 | ext.inAppToolkitProject = rootProject.name == "app-toolkit" |
| 21 | |
| 22 | if (ext.inAppToolkitProject) { |
Sergey Vasilinets | e69e470 | 2017-02-10 02:26:10 -0800 | [diff] [blame] | 23 | apply from: "${ext.supportRootFolder}/buildSrc/init.gradle" |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 24 | init.loadDefaultVersions() |
| 25 | init.setSdkInLocalPropertiesFile() |
Sergey Vasilinets | e69e470 | 2017-02-10 02:26:10 -0800 | [diff] [blame] | 26 | } |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 27 | |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 28 | def checkoutRoot = "${root}/../.." |
| 29 | ext.checkoutRoot = checkoutRoot |
| 30 | ext.prebuiltsRoot = "$checkoutRoot/prebuilts" |
| 31 | ext.prebuiltsRootUri = "file://${prebuiltsRoot}" |
| 32 | |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 33 | final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux' |
Sergey Vasilinets | c90eb81 | 2016-12-14 00:08:04 -0800 | [diff] [blame] | 34 | final String fullSdkPath = new File("${checkoutRoot}/prebuilts/fullsdk-${platform}").getCanonicalPath() |
| 35 | System.setProperty('android.home', fullSdkPath) |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 36 | File props = file("local.properties") |
| 37 | props.write "sdk.dir=${fullSdkPath}" |
| 38 | |
| 39 | def buildDir |
| 40 | def distDir |
Sergey Vasilinets | 31be41e | 2016-12-19 17:07:15 -0800 | [diff] [blame] | 41 | def supportLibBuildDir |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 42 | |
Yigit Boyar | beb35b4 | 2016-12-28 23:00:28 +0100 | [diff] [blame] | 43 | if (ext.runningInBuildServer) { |
Sergey Vasilinets | 31be41e | 2016-12-19 17:07:15 -0800 | [diff] [blame] | 44 | 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 Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 46 | distDir = new File(System.env.DIST_DIR).getCanonicalFile() |
| 47 | } else { |
Sergey Vasilinets | 31be41e | 2016-12-19 17:07:15 -0800 | [diff] [blame] | 48 | supportLibBuildDir = file("${checkoutRoot}/out/host/gradle/frameworks/support/build") |
Yigit Boyar | ed4fb5a | 2016-12-15 14:43:20 -0800 | [diff] [blame] | 49 | buildDir = file("${checkoutRoot}/out/host/gradle/frameworks/app-toolkit/build") |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 50 | distDir = file("${checkoutRoot}/out/dist") |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 51 | } |
Sergey Vasilinets | 25220c4 | 2016-12-20 21:14:36 -0800 | [diff] [blame] | 52 | |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 53 | def localMavenRepo = "file://${new File(buildDir, "flatfoot_repo").absolutePath}" |
| 54 | ext.testApkDistOut = distDir |
Yigit Boyar | beb35b4 | 2016-12-28 23:00:28 +0100 | [diff] [blame] | 55 | ext.testResultsDistDir = new File(distDir, "host-test-reports") |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 56 | ext.localMavenRepo = localMavenRepo |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 57 | file(localMavenRepo).delete() |
| 58 | file(localMavenRepo).mkdirs() |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 59 | |
| 60 | ext.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 Vasilinets | 31be41e | 2016-12-19 17:07:15 -0800 | [diff] [blame] | 67 | "file://${new File(supportLibBuildDir, "support_repo").absolutePath}"] |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 68 | |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 69 | apply from: "${ext.supportRootFolder}/app-toolkit/dependencies.gradle" |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 70 | ext.enablePublicRepos = System.getenv("ALLOW_PUBLIC_REPOS") |
| 71 | |
| 72 | // repository creation task |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 73 | def buildServerAnchorTask = rootProject.tasks.create(name : "runBuildServerCompilationTasks", |
| 74 | description: "Anchor task for everything we want to run in build server.") |
| 75 | |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 76 | if (ext.inAppToolkitProject) { |
| 77 | init.addMavenRepositories(repositories) |
| 78 | init.setupRepoOutAndBuildNumber() |
| 79 | init.configureSubProjects() |
| 80 | init.setupRelease() |
| 81 | init.enableDoclavaAndJDiff(this) |
| 82 | } |
| 83 | |
Yigit Boyar | e1bbf71 | 2017-03-08 13:52:37 -0800 | [diff] [blame] | 84 | |
| 85 | // flatfoot docs |
| 86 | def 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 | |
| 92 | buildServerAnchorTask.dependsOn zipFlatfootDocsTask |
| 93 | zipFlatfootDocsTask.dependsOn rootProject.tasks["generateDocs"] |
| 94 | |
Yigit Boyar | 24ac543 | 2017-03-07 11:05:12 -0800 | [diff] [blame] | 95 | // Disable API checks for now. |
| 96 | checkApiStable.enabled = false |
| 97 | checkApi.enabled = false |
| 98 | |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 99 | buildServerAnchorTask.dependsOn createArchive |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 100 | |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 101 | subprojects { |
| 102 | configurations.all { |
| 103 | resolutionStrategy { |
| 104 | force "com.google.guava:guava-jdk5:17.0" |
| 105 | } |
| 106 | } |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 107 | init.addMavenRepositories(project.repositories) |
Sergey Vasilinets | e69e470 | 2017-02-10 02:26:10 -0800 | [diff] [blame] | 108 | 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 Boyar | 83ebc49 | 2017-03-08 20:43:45 -0800 | [diff] [blame^] | 116 | |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 117 | def mavenGroup = project.getPath().split(":")[1] |
| 118 | if (mavenGroup != "room" && mavenGroup != "lifecycle" && mavenGroup != "apptoolkit-core") { |
| 119 | return |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 120 | } |
Yigit Boyar | 5401646 | 2017-03-06 17:24:21 -0800 | [diff] [blame] | 121 | project.tasks.whenTaskAdded { task -> |
| 122 | if (task.name.startsWith("assembleAndroidTest")) { |
| 123 | buildServerAnchorTask.dependsOn task |
| 124 | } |
| 125 | } |
Yigit Boyar | 450ed38 | 2017-03-02 09:48:25 -0800 | [diff] [blame] | 126 | project.group = "com.android.support.$mavenGroup" |
| 127 | project.version = flatfoot.release_version |
| 128 | |
Yigit Boyar | 4d19f2e | 2017-01-23 13:29:01 -0800 | [diff] [blame] | 129 | 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 Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 140 | def createKotlinCheckstyle(Project project) { |
Sergey Vasilinets | 25220c4 | 2016-12-20 21:14:36 -0800 | [diff] [blame] | 141 | 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 Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 149 | 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 | |
| 166 | def createAndroidCheckstyle(Project project) { |
Sergey Vasilinets | 25220c4 | 2016-12-20 21:14:36 -0800 | [diff] [blame] | 167 | def fs = files() |
| 168 | if (project.hasProperty('android')) { |
| 169 | fs += files(project.android.sourceSets.main.java.getSrcDirs().collect {fileTree(it)}) |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 170 | } |
Sergey Vasilinets | 25220c4 | 2016-12-20 21:14:36 -0800 | [diff] [blame] | 171 | 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 | |
| 182 | def 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 Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 194 | ext.createKotlinCheckstyle = this.&createKotlinCheckstyle |
Sergey Vasilinets | c90eb81 | 2016-12-14 00:08:04 -0800 | [diff] [blame] | 195 | ext.createAndroidCheckstyle = this.&createAndroidCheckstyle |