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 |
| 17 | |
| 18 | def root = ext.supportRootFolder |
| 19 | def checkoutRoot = "${root}/../.." |
| 20 | ext.checkoutRoot = checkoutRoot |
| 21 | ext.prebuiltsRoot = "$checkoutRoot/prebuilts" |
| 22 | ext.prebuiltsRootUri = "file://${prebuiltsRoot}" |
| 23 | |
| 24 | |
| 25 | final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux' |
Sergey Vasilinets | c90eb81 | 2016-12-14 00:08:04 -0800 | [diff] [blame] | 26 | final String fullSdkPath = new File("${checkoutRoot}/prebuilts/fullsdk-${platform}").getCanonicalPath() |
| 27 | System.setProperty('android.home', fullSdkPath) |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 28 | File props = file("local.properties") |
| 29 | props.write "sdk.dir=${fullSdkPath}" |
| 30 | |
| 31 | def buildDir |
| 32 | def distDir |
| 33 | if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) { |
| 34 | buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile() |
| 35 | distDir = new File(System.env.DIST_DIR).getCanonicalFile() |
| 36 | } else { |
Yigit Boyar | ed4fb5a | 2016-12-15 14:43:20 -0800 | [diff] [blame] | 37 | buildDir = file("${checkoutRoot}/out/host/gradle/frameworks/app-toolkit/build") |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 38 | distDir = file("${project.rootDir}/../../out/dist") |
| 39 | } |
| 40 | println "dist dir: $distDir" |
| 41 | def localMavenRepo = "file://${new File(buildDir, "flatfoot_repo").absolutePath}" |
| 42 | ext.testApkDistOut = distDir |
| 43 | ext.localMavenRepo = localMavenRepo |
| 44 | |
| 45 | ext.repoNames = ["$prebuiltsRootUri/maven_repo", |
| 46 | "$prebuiltsRootUri/gradle-plugin", |
| 47 | "$prebuiltsRootUri/tools/common/m2/repository", |
| 48 | "$prebuiltsRootUri/tools/common/m2/internal", |
| 49 | "$prebuiltsRootUri/tools/common/offline-m2", |
| 50 | "$prebuiltsRootUri/maven_repo/android", |
| 51 | "file://$fullSdkPath/extras/android/m2repository", |
| 52 | "file://${new File(buildDir, "support_repo").absolutePath}"] |
| 53 | |
| 54 | ext.kotlin_version = "1.0.5" |
Yigit Boyar | dabfd6d | 2016-12-16 11:26:10 -0800 | [diff] [blame^] | 55 | ext.android_gradle_plugin_version = "2.2.4" |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 56 | ext.auto_common_version = "0.6" |
| 57 | ext.javapoet_version = "1.8.0" |
| 58 | ext.compile_testing_version = "0.9" |
| 59 | ext.localize_maven_version = "1.1" |
| 60 | ext.support_lib_version = "25.1.0-SNAPSHOT" |
| 61 | ext.junit_version = "4.12" |
| 62 | ext.mockito_version = "1.9.5" |
| 63 | ext.min_sdk_version = 14 |
| 64 | ext.target_sdk_version = 26 |
| 65 | ext.compile_sdk_version = 26 |
| 66 | ext.build_tools_version = "26.0.0" |
| 67 | ext.intellij_annotation = "12.0" |
| 68 | ext.espresso_version = "2.2.2" |
| 69 | ext.release_version = "1.0-SNAPSHOT" |
| 70 | ext.enablePublicRepos = System.getenv("ALLOW_PUBLIC_REPOS") |
| 71 | |
| 72 | // repository creation task |
| 73 | def createRepoDistTask = rootProject.tasks.create(name : "createArchive", type: Zip) { |
| 74 | from localMavenRepo |
| 75 | destinationDir distDir |
| 76 | into 'appToolkitRepository' |
| 77 | baseName = String.format("sdk-repo-linux-appToolkitRepository-%s", rootProject.ext.release_version) |
| 78 | } |
| 79 | |
| 80 | subprojects { |
| 81 | configurations.all { |
| 82 | resolutionStrategy { |
| 83 | force "com.google.guava:guava-jdk5:17.0" |
| 84 | } |
| 85 | } |
| 86 | def mavenGroup = project.getPath().split(":")[1] |
| 87 | project.group = "com.android.support.$mavenGroup" |
| 88 | project.version = release_version |
| 89 | addRepos(project.repositories) |
Yigit Boyar | ed4fb5a | 2016-12-15 14:43:20 -0800 | [diff] [blame] | 90 | |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 91 | if (enablePublicRepos) { |
| 92 | apply plugin: 'com.android.databinding.localizemaven' |
| 93 | project.localizeMaven { |
| 94 | localRepoDir = file("$prebuiltsRoot/tools/common/m2/repository") |
| 95 | otherRepoDirs = repoNames |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | project.afterEvaluate { |
Yigit Boyar | ed4fb5a | 2016-12-15 14:43:20 -0800 | [diff] [blame] | 100 | // Copy instrumentation test APKs and app APKs into the dist dir |
| 101 | // For test apks, they are uploaded only if we have java test sources. |
| 102 | // For regular app apks, they are uploaded only if they have java sources. |
| 103 | project.tasks.whenTaskAdded { task -> |
| 104 | if (task.name.startsWith("packageDebug")) { |
| 105 | def testApk = task.name.contains("AndroidTest") |
| 106 | task.doLast { |
| 107 | def source = testApk ? project.android.sourceSets.androidTest |
| 108 | : project.android.sourceSets.main |
| 109 | if (task.hasProperty("outputFile") && !source.java.sourceFiles.isEmpty()) { |
| 110 | copy { |
| 111 | from(task.outputFile) |
| 112 | into(rootProject.ext.testApkDistOut) |
| 113 | rename { String fileName -> |
| 114 | "${project.getPath().replace(':', '-').substring(1)}_${fileName}" |
| 115 | } |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 121 | if (project.plugins.hasPlugin('maven')) { |
| 122 | def uploadArchivesTask = project.tasks.findByPath("uploadArchives") |
| 123 | if (uploadArchivesTask != null) { |
| 124 | createRepoDistTask.dependsOn(uploadArchivesTask) |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | |
| 131 | |
| 132 | def addRepos(RepositoryHandler handler) { |
| 133 | repoNames.each { repo -> |
| 134 | handler.maven { |
| 135 | url repo |
| 136 | } |
| 137 | if (ext.enablePublicRepos) { |
| 138 | handler.mavenCentral() |
| 139 | handler.jcenter() |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | def createKotlinCheckstyle(Project project) { |
| 145 | def kotlinCheckstyle = project.tasks.create(name : 'checkstyleKotlin', type: Checkstyle) { |
| 146 | configFile file("${project.rootProject.ext.supportRootFolder}/app-toolkit/kotlin-checkstyle.xml") |
| 147 | source project.sourceSets.main.allJava |
| 148 | source project.sourceSets.test.allJava |
| 149 | ignoreFailures false |
| 150 | showViolations true |
| 151 | include '**/*.kt' |
| 152 | classpath = project.files() |
| 153 | checkstyleClasspath = files(file("${project.rootProject.ext.checkoutRoot}/development/tools/checkstyle/checkstyle.jar").path) |
| 154 | } |
| 155 | project.tasks.findByName("check").dependsOn(kotlinCheckstyle) |
| 156 | // poor man's line length check |
| 157 | def lineCheck = project.tasks.create(name : "lineLengthCheck") { |
| 158 | (project.sourceSets.main.allJava.getSourceDirectories() + |
| 159 | project.sourceSets.test.allJava.getSourceDirectories()).each { sourceDir -> |
| 160 | fileTree(dir : sourceDir, include : "**/*.kt").each{ file -> |
| 161 | file.readLines().eachWithIndex { line, index -> |
| 162 | if (line.size() > 100) { |
| 163 | throw new Exception("line too long: file: $file line:$index line: $line") |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | kotlinCheckstyle.dependsOn(lineCheck) |
| 170 | } |
| 171 | |
| 172 | def createAndroidCheckstyle(Project project) { |
| 173 | def androidCheckstyle = project.tasks.create(name : 'checkstyleAndroid', type: Checkstyle) { |
Yigit Boyar | dabfd6d | 2016-12-16 11:26:10 -0800 | [diff] [blame^] | 174 | configFile file("${project.rootProject.ext.checkoutRoot}/prebuilts/checkstyle/android-style.xml") |
Yigit Boyar | 2eb5199 | 2016-12-13 15:00:07 -0800 | [diff] [blame] | 175 | if (project.hasProperty('android')) { |
| 176 | source project.android.sourceSets.main.java.getSrcDirs() |
| 177 | } |
| 178 | if (project.sourceSets.hasProperty('main')) { |
| 179 | source project.sourceSets.main.allJava |
| 180 | } |
| 181 | ignoreFailures false |
| 182 | showViolations true |
| 183 | include '**/*.java' |
| 184 | classpath = project.files() |
| 185 | checkstyleClasspath = files(file("${project.rootProject.ext.checkoutRoot}/development/tools/checkstyle/checkstyle.jar").path) |
| 186 | } |
| 187 | project.tasks.findByName("check").dependsOn(androidCheckstyle) |
| 188 | } |
| 189 | |
| 190 | def buildDir |
| 191 | if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) { |
| 192 | buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile() |
| 193 | } else { |
| 194 | buildDir = file("${ext.prebuiltsRootUri}/../out/host/gradle/frameworks/support/build") |
| 195 | } |
| 196 | ext.localMavenRepo = "file://${new File(buildDir, "flatfoot_repo").absolutePath}" |
| 197 | ext.addRepos = this.&addRepos |
| 198 | ext.createKotlinCheckstyle = this.&createKotlinCheckstyle |
Sergey Vasilinets | c90eb81 | 2016-12-14 00:08:04 -0800 | [diff] [blame] | 199 | ext.createAndroidCheckstyle = this.&createAndroidCheckstyle |