Yigit Boyar | 19b4110 | 2016-11-20 10:46:32 -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 | def root = ext.lifecyclesRootFolder |
| 17 | ext.prebuiltsRoot = "file://${root}/../../../prebuilts" |
| 18 | ext.repoNames = ["$prebuiltsRoot/maven_repo", |
| 19 | "$prebuiltsRoot/gradle-plugin", |
| 20 | "$prebuiltsRoot/tools/common/m2/repository", |
| 21 | "$prebuiltsRoot/tools/common/m2/internal", |
| 22 | "$prebuiltsRoot/tools/common/offline-m2", |
| 23 | "$prebuiltsRoot/maven_repo/android", |
| 24 | "$prebuiltsRoot/../out/host/gradle/frameworks/support/build/support_repo/"] |
| 25 | |
| 26 | ext.kotlin_version = "1.0.5" |
Yigit Boyar | 2259e4d | 2016-11-25 18:26:10 -0800 | [diff] [blame] | 27 | ext.android_gradle_plugin_version = "2.2.1" |
Yigit Boyar | 19b4110 | 2016-11-20 10:46:32 -0800 | [diff] [blame] | 28 | ext.auto_common_version = "0.6" |
| 29 | ext.javapoet_version = "1.7.0" |
| 30 | ext.compile_testing_version = "0.9" |
| 31 | ext.localize_maven_version = "1.1" |
| 32 | ext.support_lib_version = "25.1.0-SNAPSHOT" |
| 33 | ext.junit_version = "4.12" |
| 34 | ext.mockito_version = "1.9.5" |
| 35 | ext.min_sdk_version = 14 |
| 36 | ext.target_sdk_version = 24 |
| 37 | ext.compile_sdk_version = 24 |
| 38 | ext.build_tools_version = "24.0.0" |
| 39 | ext.intellij_annotation = "12.0" |
Sergey Vasilinets | b085e34 | 2016-12-05 19:02:59 -0800 | [diff] [blame^] | 40 | ext.release_version = "1.0-SNAPSHOT" |
Yigit Boyar | 19b4110 | 2016-11-20 10:46:32 -0800 | [diff] [blame] | 41 | ext.enablePublicRepos = System.getenv("ALLOW_PUBLIC_REPOS") |
| 42 | |
| 43 | def addRepos(RepositoryHandler handler) { |
| 44 | repoNames.each { repo -> |
| 45 | handler.maven { |
| 46 | url repo |
| 47 | } |
| 48 | if (ext.enablePublicRepos) { |
| 49 | handler.mavenCentral() |
| 50 | handler.jcenter() |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | def createKotlinCheckstyle(Project project) { |
| 56 | def kotlinCheckstyle = project.tasks.create(name : 'checkstyleKotlin', type: Checkstyle) { |
Sergey Vasilinets | b085e34 | 2016-12-05 19:02:59 -0800 | [diff] [blame^] | 57 | configFile file("$lifecyclesRootFolder/../flatfoot-common/kotlin-checkstyle.xml") |
Yigit Boyar | 19b4110 | 2016-11-20 10:46:32 -0800 | [diff] [blame] | 58 | source project.sourceSets.main.allJava |
Yigit Boyar | de33ce4 | 2016-11-24 11:52:24 -0800 | [diff] [blame] | 59 | source project.sourceSets.test.allJava |
Yigit Boyar | 19b4110 | 2016-11-20 10:46:32 -0800 | [diff] [blame] | 60 | ignoreFailures false |
| 61 | showViolations true |
| 62 | include '**/*.kt' |
| 63 | classpath = project.files() |
Sergey Vasilinets | b085e34 | 2016-12-05 19:02:59 -0800 | [diff] [blame^] | 64 | checkstyleClasspath = files(file("$lifecyclesRootFolder../../../development/tools/checkstyle/checkstyle.jar").path) |
| 65 | } |
Yigit Boyar | 19b4110 | 2016-11-20 10:46:32 -0800 | [diff] [blame] | 66 | project.tasks.findByName("check").dependsOn(kotlinCheckstyle) |
| 67 | // poor man's line length check |
| 68 | def lineCheck = project.tasks.create(name : "lineLengthCheck") { |
Yigit Boyar | de33ce4 | 2016-11-24 11:52:24 -0800 | [diff] [blame] | 69 | (project.sourceSets.main.allJava.getSourceDirectories() + |
| 70 | project.sourceSets.test.allJava.getSourceDirectories()).each { sourceDir -> |
| 71 | fileTree(dir : sourceDir, include : "**/*.kt").each{ file -> |
| 72 | file.readLines().eachWithIndex { line, index -> |
| 73 | if (line.size() > 100) { |
Yigit Boyar | efaf86a | 2016-12-02 15:16:35 -0800 | [diff] [blame] | 74 | throw new Exception("line too long: file: $file line:$index line: $line") |
Yigit Boyar | de33ce4 | 2016-11-24 11:52:24 -0800 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | } |
Yigit Boyar | 19b4110 | 2016-11-20 10:46:32 -0800 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | kotlinCheckstyle.dependsOn(lineCheck) |
| 81 | } |
| 82 | |
| 83 | def createAndroidCheckstyle(Project project) { |
| 84 | def androidCheckstyle = project.tasks.create(name : 'checkstyleAndroid', type: Checkstyle) { |
Sergey Vasilinets | b085e34 | 2016-12-05 19:02:59 -0800 | [diff] [blame^] | 85 | configFile file("$lifecyclesRootFolder/../../../development/tools/checkstyle/android-style.xml") |
Yigit Boyar | a034a6e | 2016-11-25 08:57:33 -0800 | [diff] [blame] | 86 | if (project.hasProperty('android')) { |
| 87 | source project.android.sourceSets.main.java.getSrcDirs() |
| 88 | } |
| 89 | if (project.sourceSets.hasProperty('main')) { |
| 90 | source project.sourceSets.main.allJava |
| 91 | } |
Yigit Boyar | 19b4110 | 2016-11-20 10:46:32 -0800 | [diff] [blame] | 92 | ignoreFailures false |
| 93 | showViolations true |
| 94 | include '**/*.java' |
| 95 | classpath = project.files() |
Sergey Vasilinets | b085e34 | 2016-12-05 19:02:59 -0800 | [diff] [blame^] | 96 | checkstyleClasspath = files(file("$lifecyclesRootFolder/../../../development/tools/checkstyle/checkstyle.jar").path) |
Yigit Boyar | 19b4110 | 2016-11-20 10:46:32 -0800 | [diff] [blame] | 97 | } |
| 98 | project.tasks.findByName("check").dependsOn(androidCheckstyle) |
| 99 | } |
| 100 | |
| 101 | ext.localMavenRepo = "file://${new File(root, "maven-repo").absolutePath}" |
| 102 | ext.addRepos = this.&addRepos |
| 103 | ext.createKotlinCheckstyle = this.&createKotlinCheckstyle |
| 104 | ext.createAndroidCheckstyle = this.&createAndroidCheckstyle |