blob: fb535419088521ea99dcac7e01f763a42228e6c7 [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
17
18def root = ext.supportRootFolder
19def checkoutRoot = "${root}/../.."
20ext.checkoutRoot = checkoutRoot
21ext.prebuiltsRoot = "$checkoutRoot/prebuilts"
22ext.prebuiltsRootUri = "file://${prebuiltsRoot}"
23
24
25final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux'
Sergey Vasilinetsc90eb812016-12-14 00:08:04 -080026final String fullSdkPath = new File("${checkoutRoot}/prebuilts/fullsdk-${platform}").getCanonicalPath()
27System.setProperty('android.home', fullSdkPath)
Yigit Boyar2eb51992016-12-13 15:00:07 -080028File props = file("local.properties")
29props.write "sdk.dir=${fullSdkPath}"
30
31def buildDir
32def distDir
33if (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 Boyared4fb5a2016-12-15 14:43:20 -080037 buildDir = file("${checkoutRoot}/out/host/gradle/frameworks/app-toolkit/build")
Yigit Boyar2eb51992016-12-13 15:00:07 -080038 distDir = file("${project.rootDir}/../../out/dist")
39}
40println "dist dir: $distDir"
41def localMavenRepo = "file://${new File(buildDir, "flatfoot_repo").absolutePath}"
42ext.testApkDistOut = distDir
43ext.localMavenRepo = localMavenRepo
44
45ext.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
54ext.kotlin_version = "1.0.5"
Yigit Boyardabfd6d2016-12-16 11:26:10 -080055ext.android_gradle_plugin_version = "2.2.4"
Yigit Boyar2eb51992016-12-13 15:00:07 -080056ext.auto_common_version = "0.6"
57ext.javapoet_version = "1.8.0"
58ext.compile_testing_version = "0.9"
59ext.localize_maven_version = "1.1"
60ext.support_lib_version = "25.1.0-SNAPSHOT"
61ext.junit_version = "4.12"
62ext.mockito_version = "1.9.5"
63ext.min_sdk_version = 14
64ext.target_sdk_version = 26
65ext.compile_sdk_version = 26
66ext.build_tools_version = "26.0.0"
67ext.intellij_annotation = "12.0"
68ext.espresso_version = "2.2.2"
69ext.release_version = "1.0-SNAPSHOT"
70ext.enablePublicRepos = System.getenv("ALLOW_PUBLIC_REPOS")
71
72// repository creation task
73def 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
80subprojects {
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 Boyared4fb5a2016-12-15 14:43:20 -080090
Yigit Boyar2eb51992016-12-13 15:00:07 -080091 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 Boyared4fb5a2016-12-15 14:43:20 -0800100 // 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 Boyar2eb51992016-12-13 15:00:07 -0800116 }
117 }
118 }
119 }
120 }
Yigit Boyar2eb51992016-12-13 15:00:07 -0800121 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
132def 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
144def 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
172def createAndroidCheckstyle(Project project) {
173 def androidCheckstyle = project.tasks.create(name : 'checkstyleAndroid', type: Checkstyle) {
Yigit Boyardabfd6d2016-12-16 11:26:10 -0800174 configFile file("${project.rootProject.ext.checkoutRoot}/prebuilts/checkstyle/android-style.xml")
Yigit Boyar2eb51992016-12-13 15:00:07 -0800175 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
190def buildDir
191if (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}
196ext.localMavenRepo = "file://${new File(buildDir, "flatfoot_repo").absolutePath}"
197ext.addRepos = this.&addRepos
198ext.createKotlinCheckstyle = this.&createKotlinCheckstyle
Sergey Vasilinetsc90eb812016-12-14 00:08:04 -0800199ext.createAndroidCheckstyle = this.&createAndroidCheckstyle