blob: 626badcc0a8002832c108b5797bbf27a00c6505f [file] [log] [blame]
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.gradle.internal.os.OperatingSystem
def root = ext.supportRootFolder
def checkoutRoot = "${root}/../.."
ext.checkoutRoot = checkoutRoot
ext.prebuiltsRoot = "$checkoutRoot/prebuilts"
ext.prebuiltsRootUri = "file://${prebuiltsRoot}"
final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux'
final String fullSdkPath = new File("${checkoutRoot}/prebuilts/fullsdk-${platform}").getCanonicalPath()
System.setProperty('android.home', fullSdkPath)
File props = file("local.properties")
props.write "sdk.dir=${fullSdkPath}"
def buildDir
def distDir
def supportLibBuildDir
ext.runningInBuildServer = System.env.DIST_DIR != null && System.env.OUT_DIR != null
if (ext.runningInBuildServer) {
supportLibBuildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile();
buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/app-toolkit/build').getCanonicalFile()
distDir = new File(System.env.DIST_DIR).getCanonicalFile()
} else {
supportLibBuildDir = file("${checkoutRoot}/out/host/gradle/frameworks/support/build")
buildDir = file("${checkoutRoot}/out/host/gradle/frameworks/app-toolkit/build")
distDir = file("${project.rootDir}/../../out/dist")
}
def localMavenRepo = "file://${new File(buildDir, "flatfoot_repo").absolutePath}"
ext.testApkDistOut = distDir
ext.testResultsDistDir = new File(distDir, "host-test-reports")
ext.localMavenRepo = localMavenRepo
ext.repoNames = ["$prebuiltsRootUri/maven_repo",
"$prebuiltsRootUri/gradle-plugin",
"$prebuiltsRootUri/tools/common/m2/repository",
"$prebuiltsRootUri/tools/common/m2/internal",
"$prebuiltsRootUri/tools/common/offline-m2",
"$prebuiltsRootUri/maven_repo/android",
"file://$fullSdkPath/extras/android/m2repository",
"file://${new File(supportLibBuildDir, "support_repo").absolutePath}"]
ext.kotlin_version = "1.0.5"
ext.android_gradle_plugin_version = "2.2.4"
ext.auto_common_version = "0.6"
ext.javapoet_version = "1.8.0"
ext.compile_testing_version = "0.9"
ext.localize_maven_version = "1.1"
ext.support_lib_version = "25.1.0-SNAPSHOT"
ext.junit_version = "4.12"
ext.mockito_version = "1.9.5"
ext.min_sdk_version = 14
ext.target_sdk_version = 26
ext.compile_sdk_version = 26
ext.build_tools_version = "26.0.0"
ext.intellij_annotation = "12.0"
ext.espresso_version = "2.2.2"
ext.release_version = "1.0-SNAPSHOT"
// this Xerial version is newer than we want but we need it to fix
// https://github.com/xerial/sqlite-jdbc/issues/97
ext.xerial_version = "3.16.1"
ext.antlr_version = "4.5.3"
ext.enablePublicRepos = System.getenv("ALLOW_PUBLIC_REPOS")
// repository creation task
def createRepoDistTask = rootProject.tasks.create(name : "createArchive", type: Zip) {
from localMavenRepo
destinationDir distDir
into 'appToolkitRepository'
baseName = String.format("sdk-repo-linux-appToolkitRepository-%s", rootProject.ext.release_version)
}
subprojects {
configurations.all {
resolutionStrategy {
force "com.google.guava:guava-jdk5:17.0"
}
}
def mavenGroup = project.getPath().split(":")[1]
project.group = "com.android.support.$mavenGroup"
project.version = release_version
addRepos(project.repositories)
// copy test results to DIST
project.tasks.whenTaskAdded { task ->
if (task instanceof org.gradle.api.tasks.testing.Test) {
def junitReport = task.reports.junitXml
if (junitReport.enabled) {
def zipTask = project.tasks.create(name : "zipResultsOf${task.name.capitalize()}", type : Zip) {
destinationDir(testResultsDistDir)
archiveName("${project.name}.zip")
}
if (project.rootProject.ext.runningInBuildServer) {
task.ignoreFailures = true
}
task.finalizedBy zipTask
task.doFirst {
zipTask.from(junitReport.destination)
}
}
}
}
// Copy instrumentation test APKs and app APKs into the dist dir
// For test apks, they are uploaded only if we have java test sources.
// For regular app apks, they are uploaded only if they have java sources.
project.tasks.whenTaskAdded { task ->
if (task.name.startsWith("packageDebug")) {
def testApk = task.name.contains("AndroidTest")
task.doLast {
def source = testApk ? project.android.sourceSets.androidTest
: project.android.sourceSets.main
if (task.hasProperty("outputFile") && !source.java.sourceFiles.isEmpty()) {
copy {
from(task.outputFile)
into(rootProject.ext.testApkDistOut)
rename { String fileName ->
"${project.getPath().replace(':', '-').substring(1)}_${fileName}"
}
}
}
}
}
}
project.afterEvaluate {
if (project.plugins.hasPlugin('maven')) {
def uploadArchivesTask = project.tasks.findByPath("uploadArchives")
if (uploadArchivesTask != null) {
createRepoDistTask.dependsOn(uploadArchivesTask)
}
}
}
if (enablePublicRepos) {
project.afterEvaluate {
apply plugin: 'com.android.databinding.localizemaven'
project.localizeMaven {
localRepoDir = file("$prebuiltsRoot/tools/common/m2/repository")
otherRepoDirs = repoNames
}
}
}
}
def addRepos(RepositoryHandler handler) {
repoNames.each { repo ->
handler.maven {
url repo
}
if (ext.enablePublicRepos) {
handler.mavenCentral()
handler.jcenter()
}
}
}
def createKotlinCheckstyle(Project project) {
def fs = files();
fs += files(project.sourceSets.main.allJava.srcDirs.collect{fileTree(it)})
fs += files(project.sourceSets.test.allJava.srcDirs.collect{fileTree(it)})
fs = fs.filter{file -> file.name.endsWith(".kt")}
def kotlinCheckstyle = createCheckstyleTask(project, 'checkstyleKotlin',
"${project.rootProject.ext.supportRootFolder}/app-toolkit/kotlin-checkstyle.xml",
fs.files)
project.tasks.findByName("check").dependsOn(kotlinCheckstyle)
// poor man's line length check
def lineCheck = project.tasks.create(name : "lineLengthCheck") {
(project.sourceSets.main.allJava.getSourceDirectories() +
project.sourceSets.test.allJava.getSourceDirectories()).each { sourceDir ->
fileTree(dir : sourceDir, include : "**/*.kt").each{ file ->
file.readLines().eachWithIndex { line, index ->
if (line.size() > 100) {
throw new Exception("line too long: file: $file line:$index line: $line")
}
}
}
}
}
kotlinCheckstyle.dependsOn(lineCheck)
}
def createAndroidCheckstyle(Project project) {
def fs = files()
if (project.hasProperty('android')) {
fs += files(project.android.sourceSets.main.java.getSrcDirs().collect {fileTree(it)})
}
if (project.sourceSets.hasProperty('main')) {
fs += files(project.sourceSets.main.allJava)
}
fs = fs.filter{file -> file.name.endsWith(".java")}
def checkStyle = createCheckstyleTask(project, 'checkstyleAndroid',
"${project.rootProject.ext.checkoutRoot}/prebuilts/checkstyle/android-style.xml",
fs.files)
project.tasks.findByName("check").dependsOn(checkStyle)
}
def createCheckstyleTask(project, taskName, configFile, inputFiles) {
def arguments = ['-c', configFile]
arguments.addAll(inputFiles)
def checkStyle = project.tasks.create(name : taskName, type: JavaExec) {
inputs.files(inputFiles).skipWhenEmpty()
main = "com.puppycrawl.tools.checkstyle.Main"
args = arguments
classpath = files(file("${project.rootProject.ext.checkoutRoot}/prebuilts/checkstyle/checkstyle.jar").path)
}
return checkStyle;
}
def buildDir
if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
} else {
buildDir = file("${ext.prebuiltsRootUri}/../out/host/gradle/frameworks/support/build")
}
ext.localMavenRepo = "file://${new File(buildDir, "flatfoot_repo").absolutePath}"
ext.addRepos = this.&addRepos
ext.createKotlinCheckstyle = this.&createKotlinCheckstyle
ext.createAndroidCheckstyle = this.&createAndroidCheckstyle