Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 1 | import android.support.checkapi.ApiXmlConversionTask |
Alan Viverette | 62ff5d9 | 2016-12-07 09:51:16 -0500 | [diff] [blame] | 2 | import android.support.checkapi.CheckApiTask |
| 3 | import android.support.checkapi.UpdateApiTask |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 4 | import android.support.doclava.DoclavaMultilineJavadocOptionFileOption |
Alan Viverette | 62ff5d9 | 2016-12-07 09:51:16 -0500 | [diff] [blame] | 5 | import android.support.doclava.DoclavaTask |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 6 | import android.support.jdiff.JDiffTask |
Alan Viverette | 62ff5d9 | 2016-12-07 09:51:16 -0500 | [diff] [blame] | 7 | |
| 8 | import com.android.build.gradle.internal.coverage.JacocoPlugin |
Yigit Boyar | ea5d9b2 | 2016-03-08 13:25:26 -0800 | [diff] [blame] | 9 | import com.android.build.gradle.internal.coverage.JacocoReportTask |
| 10 | import com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask |
Aurimas Liutikas | d4d9cde | 2016-11-23 12:12:50 -0800 | [diff] [blame] | 11 | import org.gradle.internal.os.OperatingSystem |
Yigit Boyar | ea5d9b2 | 2016-03-08 13:25:26 -0800 | [diff] [blame] | 12 | |
Alan Viverette | 62ff5d9 | 2016-12-07 09:51:16 -0500 | [diff] [blame] | 13 | import com.google.common.base.Charsets |
| 14 | import com.google.common.hash.HashCode |
| 15 | import com.google.common.hash.HashFunction |
| 16 | import com.google.common.hash.Hashing |
| 17 | import com.google.common.io.Files |
| 18 | |
| 19 | import groovy.io.FileType |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 20 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 21 | buildscript { |
| 22 | repositories { |
| 23 | maven { url '../../prebuilts/gradle-plugin' } |
| 24 | maven { url '../../prebuilts/tools/common/m2/repository' } |
| 25 | maven { url '../../prebuilts/tools/common/m2/internal' } |
Yigit Boyar | c9750a1 | 2016-01-06 17:28:55 -0800 | [diff] [blame] | 26 | maven { url "../../prebuilts/maven_repo/android" } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 27 | } |
| 28 | dependencies { |
Aurimas Liutikas | 5c6933b | 2016-09-20 09:55:40 -0700 | [diff] [blame] | 29 | // Keep gradle plugin version in sync with ub_supportlib-master manifest. |
Aurimas Liutikas | 9135bd9 | 2016-12-16 10:53:43 -0800 | [diff] [blame] | 30 | classpath 'com.android.tools.build:gradle:2.2.4' |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 34 | repositories { |
| 35 | maven { url '../../prebuilts/tools/common/m2/repository' } |
| 36 | } |
| 37 | |
| 38 | configurations { |
| 39 | doclava |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 40 | jdiff |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | dependencies { |
| 44 | doclava project(':doclava') |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 45 | jdiff project(':jdiff') |
| 46 | jdiff 'xerces:xmlParserAPIs:2.6.2' |
| 47 | jdiff 'xerces:xercesImpl:2.6.2' |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 48 | } |
| 49 | |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 50 | // Version code components. |
| 51 | ext.supportVersion = "26.0.0-SNAPSHOT" |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 52 | |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 53 | // This number gets incremented for each public release. |
| 54 | ext.extraVersion = 41 |
| 55 | |
| 56 | // Dependency versions. |
Aurimas Liutikas | dfe7578 | 2016-08-03 14:27:20 -0700 | [diff] [blame] | 57 | ext.testRunnerVersion = '0.6-alpha' |
| 58 | ext.espressoVersion = '2.3-alpha' |
| 59 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 60 | // Enforce the use of prebuilt dependencies in all sub-projects. This is |
| 61 | // required for the doclava dependency. |
| 62 | ext.usePrebuilts = "true" |
| 63 | |
Aurimas Liutikas | d4d9cde | 2016-11-23 12:12:50 -0800 | [diff] [blame] | 64 | final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux' |
| 65 | System.setProperty('android.dir', "${rootDir}/../../") |
| 66 | final String fullSdkPath = "${rootDir}/../../prebuilts/fullsdk-${platform}" |
| 67 | if (file(fullSdkPath).exists()) { |
| 68 | gradle.ext.currentSdk = 26 |
| 69 | ext.buildToolsVersion = '26.0.0' |
| 70 | project.ext.androidJar = files("${fullSdkPath}/platforms/android-${gradle.ext.currentSdk}/android.jar") |
| 71 | System.setProperty('android.home', "${rootDir}/../../prebuilts/fullsdk-${platform}") |
| 72 | File props = file("local.properties") |
| 73 | props.write "sdk.dir=${fullSdkPath}" |
| 74 | } else { |
| 75 | gradle.ext.currentSdk = 'current' |
| 76 | ext.buildToolsVersion = '24.0.1' |
| 77 | project.ext.androidJar = files("${project.rootDir}/../../prebuilts/sdk/current/android.jar") |
| 78 | File props = file("local.properties") |
| 79 | props.write "android.dir=../../" |
| 80 | } |
| 81 | |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 82 | ext.supportRepoOut = '' |
| 83 | ext.buildNumber = Integer.toString(ext.extraVersion) |
| 84 | |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 85 | /* |
| 86 | * With the build server you are given two env variables. |
| 87 | * The OUT_DIR is a temporary directory you can use to put things during the build. |
| 88 | * The DIST_DIR is where you want to save things from the build. |
| 89 | * |
| 90 | * The build server will copy the contents of DIST_DIR to somewhere and make it available. |
| 91 | */ |
| 92 | if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) { |
Xavier Ducrohet | 4e04b7a | 2014-10-17 18:02:33 -0700 | [diff] [blame] | 93 | buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile() |
| 94 | project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile() |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 95 | |
| 96 | // the build server does not pass the build number so we infer it from the last folder of the dist path. |
| 97 | ext.buildNumber = project.ext.distDir.getName() |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 98 | } else { |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 99 | buildDir = file("${project.rootDir}/../../out/host/gradle/frameworks/support/build") |
| 100 | project.ext.distDir = file("${project.rootDir}/../../out/dist") |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 101 | } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 102 | |
Alan Viverette | 9b5fe93 | 2016-07-22 10:28:31 -0400 | [diff] [blame] | 103 | subprojects { |
| 104 | // Change buildDir first so that all plugins pick up the new value. |
| 105 | project.buildDir = project.file("$project.parent.buildDir/../$project.name/build") |
| 106 | } |
| 107 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 108 | ext.docsDir = new File(buildDir, 'javadoc') |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 109 | ext.supportRepoOut = new File(buildDir, 'support_repo') |
Yigit Boyar | f18d9757 | 2015-12-01 13:45:28 -0800 | [diff] [blame] | 110 | ext.testApkDistOut = ext.distDir |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 111 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 112 | // Main task called by the build server. |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 113 | task(createArchive) |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 114 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 115 | // upload anchor for subprojects to upload their artifacts |
| 116 | // to the local repo. |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 117 | task(mainUpload) |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 118 | |
| 119 | // repository creation task |
| 120 | task createRepository(type: Zip, dependsOn: mainUpload) { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 121 | from project.ext.supportRepoOut |
| 122 | destinationDir project.ext.distDir |
Xavier Ducrohet | 9dc4480 | 2014-03-20 14:15:16 -0700 | [diff] [blame] | 123 | into 'm2repository' |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 124 | baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber) |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 125 | } |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 126 | createArchive.dependsOn createRepository |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 127 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 128 | // prepare repository with older versions |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 129 | task unzipRepo(type: Copy) { |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 130 | from "${project.rootDir}/../../prebuilts/maven_repo/android" |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 131 | into project.ext.supportRepoOut |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 134 | unzipRepo.doFirst { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 135 | project.ext.supportRepoOut.deleteDir() |
| 136 | project.ext.supportRepoOut.mkdirs() |
| 137 | } |
| 138 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 139 | // anchor for prepare repo. This is post unzip + sourceProp. |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 140 | task(prepareRepo) |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 141 | |
Alan Viverette | af6b251 | 2016-11-16 17:33:10 -0500 | [diff] [blame] | 142 | // lint every library |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 143 | task(lint) |
Alan Viverette | af6b251 | 2016-11-16 17:33:10 -0500 | [diff] [blame] | 144 | |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 145 | task(createXml).doLast({ |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 146 | def repoArchive = createRepository.archivePath |
| 147 | def repoArchiveName = createRepository.archiveName |
| 148 | def size = repoArchive.length() |
| 149 | def sha1 = getSha1(repoArchive) |
| 150 | |
| 151 | def xml = |
| 152 | "<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\ |
| 153 | <sdk:extra>\n\ |
| 154 | <sdk:revision>\n\ |
| 155 | <sdk:major>${project.ext.extraVersion}</sdk:major>\n\ |
| 156 | </sdk:revision>\n\ |
| 157 | <sdk:vendor-display>Android</sdk:vendor-display>\n\ |
| 158 | <sdk:vendor-id>android</sdk:vendor-id>\n\ |
| 159 | <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\ |
| 160 | <sdk:path>m2repository</sdk:path>\n\ |
| 161 | <sdk:archives>\n\ |
Xavier Ducrohet | c16b62d | 2014-12-09 12:37:45 -0800 | [diff] [blame] | 162 | <sdk:archive>\n\ |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 163 | <sdk:size>${size}</sdk:size>\n\ |
| 164 | <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\ |
| 165 | <sdk:url>${repoArchiveName}</sdk:url>\n\ |
| 166 | </sdk:archive>\n\ |
| 167 | </sdk:archives>\n\ |
| 168 | </sdk:extra>\n\ |
| 169 | </sdk:sdk-addon>" |
| 170 | |
| 171 | Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8) |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 172 | }) |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 173 | createArchive.dependsOn createXml |
| 174 | |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 175 | task(createSourceProp).doLast({ |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 176 | def sourceProp = |
| 177 | "Extra.VendorDisplay=Android\n\ |
| 178 | Extra.Path=m2repository\n\ |
| 179 | Archive.Arch=ANY\n\ |
| 180 | Extra.NameDisplay=Android Support Repository\n\ |
| 181 | Archive.Os=ANY\n\ |
Alan Viverette | 5ae24d6 | 2016-04-06 16:17:13 -0400 | [diff] [blame] | 182 | Pkg.Desc=Local Maven repository for Support Libraries\n\ |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 183 | Pkg.Revision=${project.ext.extraVersion}.0.0\n\ |
| 184 | Extra.VendorId=android" |
| 185 | |
| 186 | Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8) |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 187 | }) |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 188 | createSourceProp.dependsOn unzipRepo |
| 189 | prepareRepo.dependsOn createSourceProp |
| 190 | |
Chris Banes | 96f1e91 | 2015-03-05 20:04:05 +0000 | [diff] [blame] | 191 | import java.nio.charset.Charset |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 192 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 193 | /** |
| 194 | * Generates SHA1 hash for the specified file's absolute path. |
| 195 | * |
| 196 | * @param inputFile file to hash |
| 197 | * @return SHA1 hash |
| 198 | */ |
| 199 | String getSha1(File inputFile) { |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 200 | HashFunction hashFunction = Hashing.sha1() |
Chris Banes | 96f1e91 | 2015-03-05 20:04:05 +0000 | [diff] [blame] | 201 | HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8")) |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 202 | return hashCode.toString() |
| 203 | } |
| 204 | |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 205 | void registerForDocsTask(Task task, Project subProject, releaseVariant) { |
| 206 | task.dependsOn releaseVariant.javaCompile |
| 207 | task.source { |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 208 | def buildConfig = fileTree(releaseVariant.getGenerateBuildConfig().sourceOutputDir) |
| 209 | return releaseVariant.javaCompile.source.minus(buildConfig) + |
| 210 | fileTree(releaseVariant.aidlCompile.sourceOutputDir) + |
| 211 | fileTree(releaseVariant.outputs[0].processResources.sourceOutputDir) |
| 212 | } |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 213 | task.classpath += files(releaseVariant.javaCompile.classpath) + |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 214 | files(releaseVariant.javaCompile.destinationDir) |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 215 | } |
| 216 | |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 217 | // Generates online docs. |
| 218 | task generateDocs(type: DoclavaTask, dependsOn: configurations.doclava) { |
| 219 | docletpath = configurations.doclava.resolve() |
| 220 | destinationDir = new File(project.docsDir, "online") |
| 221 | |
| 222 | // Base classpath is Android SDK, sub-projects add their own. |
Aurimas Liutikas | d4d9cde | 2016-11-23 12:12:50 -0800 | [diff] [blame] | 223 | classpath = project.ext.androidJar |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 224 | |
| 225 | def hdfOption = new DoclavaMultilineJavadocOptionFileOption('hdf') |
| 226 | hdfOption.add( |
| 227 | ['android.whichdoc', 'online'], |
| 228 | ['android.hasSamples', 'true']); |
| 229 | |
Alan Viverette | 989f27a | 2016-11-29 17:28:15 -0500 | [diff] [blame] | 230 | // Default hidden errors + hidden superclass (111) and |
| 231 | // deprecation mismatch (113) to match framework docs. |
| 232 | final def hidden = [105, 107, 111, 112, 113, 115, 116, 121] |
| 233 | |
| 234 | doclavaErrors = (101..122) - hidden |
| 235 | doclavaWarnings = [] |
| 236 | doclavaHidden += hidden |
| 237 | |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 238 | options { |
| 239 | addStringOption "templatedir", |
| 240 | "${project.rootDir}/../../build/tools/droiddoc/templates-sdk" |
| 241 | addStringOption "federate Android", "http://developer.android.com" |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 242 | addStringOption "stubpackages", "android.support.*" |
| 243 | addStringOption "samplesdir", "${project.rootDir}/samples" |
| 244 | addOption hdfOption |
| 245 | } |
| 246 | |
| 247 | exclude '**/BuildConfig.java' |
| 248 | } |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 249 | |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 250 | JDiffTask createApiDiffsTask(String taskName, File oldApiXml, File newApiXml, File outDir, |
| 251 | Configuration jdiff, Task... dependencies) { |
| 252 | return tasks.create(name: taskName, type: JDiffTask.class) { |
| 253 | dependsOn jdiff |
| 254 | dependsOn dependencies |
| 255 | |
| 256 | docletpath = jdiff.resolve() |
| 257 | |
| 258 | oldApiXmlFile oldApiXml |
| 259 | newApiXmlFile newApiXml |
| 260 | destinationDir = outDir |
| 261 | |
| 262 | // This prefix is based on the assumption that the output diffs will |
| 263 | // ultimately land in frameworks/base/docs/html/sdk/support_api_diff/. |
| 264 | newJavadocPrefix = "../reference/" |
| 265 | } |
| 266 | } |
| 267 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 268 | // Generates API files. |
| 269 | task generateApi(type: DoclavaTask, dependsOn: configurations.doclava) { |
| 270 | docletpath = configurations.doclava.resolve() |
| 271 | destinationDir = project.docsDir |
| 272 | |
| 273 | // Base classpath is Android SDK, sub-projects add their own. |
Aurimas Liutikas | d4d9cde | 2016-11-23 12:12:50 -0800 | [diff] [blame] | 274 | classpath = project.ext.androidJar |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 275 | |
| 276 | apiFile = new File(project.docsDir, 'release/current.txt') |
| 277 | removedApiFile = new File(project.docsDir, 'release/removed.txt') |
| 278 | generateDocs = false |
| 279 | |
| 280 | options { |
| 281 | addStringOption "templatedir", |
| 282 | "${project.rootDir}/../../build/tools/droiddoc/templates-sdk" |
| 283 | addStringOption "federate Android", "http://developer.android.com" |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 284 | addStringOption "stubpackages", "android.support.*" |
| 285 | } |
| 286 | exclude '**/BuildConfig.java' |
| 287 | exclude '**/R.java' |
| 288 | } |
| 289 | |
| 290 | // Copies generated API files to current version. |
| 291 | task updateApi(type: UpdateApiTask, dependsOn: generateApi) { |
| 292 | newApiFile = new File(project.docsDir, 'release/current.txt') |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 293 | oldApiFile = new File(project.rootDir, 'api/current.txt') |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 294 | newRemovedApiFile = new File(project.docsDir, 'release/removed.txt') |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 295 | oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt') |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | // Checks generated API files against current version. |
| 299 | task checkApi(type: CheckApiTask, dependsOn: generateApi) { |
| 300 | doclavaClasspath = generateApi.docletpath |
| 301 | |
| 302 | checkApiTaskPath = name |
| 303 | updateApiTaskPath = updateApi.name |
| 304 | |
Alan Viverette | 62ff5d9 | 2016-12-07 09:51:16 -0500 | [diff] [blame] | 305 | // Check that the API we're building hasn't changed from the development |
| 306 | // version. These typed of changes require an explicit API file update. |
| 307 | checkApiErrors = (2..30)-[22] |
| 308 | checkApiWarnings = [] |
| 309 | checkApiHidden = [22] |
| 310 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 311 | newApiFile = new File(project.docsDir, 'release/current.txt') |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 312 | oldApiFile = new File(project.rootDir, 'api/current.txt') |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 313 | newRemovedApiFile = new File(project.docsDir, 'release/removed.txt') |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 314 | oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt') |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 315 | } |
Alan Viverette | dd377c9 | 2016-06-24 09:51:49 -0400 | [diff] [blame] | 316 | createArchive.dependsOn checkApi |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 317 | |
Alan Viverette | 62ff5d9 | 2016-12-07 09:51:16 -0500 | [diff] [blame] | 318 | // Checks generated API files against current version. |
| 319 | task checkApiStable(type: CheckApiTask, dependsOn: generateApi) { |
| 320 | doclavaClasspath = generateApi.docletpath |
| 321 | |
| 322 | checkApiTaskPath = name |
| 323 | updateApiTaskPath = updateApi.name |
| 324 | |
| 325 | // Check that the API we're building hasn't broken the last-released |
| 326 | // library version. These types of changes are forbidden. |
| 327 | checkApiErrors = (7..18) |
| 328 | checkApiWarnings = [23, 24] |
| 329 | checkApiHidden = (2..6) + (19..22) + (25..30) |
| 330 | |
Alan Viverette | 62ff5d9 | 2016-12-07 09:51:16 -0500 | [diff] [blame] | 331 | newApiFile = new File(project.docsDir, 'release/current.txt') |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 332 | oldApiFile = getReleasedApiFile() |
Alan Viverette | 62ff5d9 | 2016-12-07 09:51:16 -0500 | [diff] [blame] | 333 | newRemovedApiFile = new File(project.docsDir, 'release/removed.txt') |
| 334 | oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt') |
| 335 | } |
| 336 | checkApi.dependsOn checkApiStable |
| 337 | |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 338 | /** |
| 339 | * Converts the <code>toApi</code>.txt file (or current.txt if not explicitly |
| 340 | * defined using -DtoAPi=<file>) to XML format for use by JDiff. |
| 341 | */ |
| 342 | task newApiXml(type: ApiXmlConversionTask, dependsOn: configurations.doclava) { |
| 343 | classpath configurations.doclava.resolve() |
| 344 | |
| 345 | if (project.hasProperty("toApi")) { |
| 346 | // Use an explicit API file. |
| 347 | inputApiFile = new File(project.rootDir, "api/${toApi}.txt") |
| 348 | } else { |
| 349 | // Use the current API file (e.g. current.txt). |
| 350 | inputApiFile = generateApi.apiFile |
| 351 | dependsOn generateApi |
| 352 | } |
| 353 | |
| 354 | int lastDot = inputApiFile.name.lastIndexOf('.') |
| 355 | outputApiXmlFile = new File(project.docsDir, |
| 356 | "release/" + inputApiFile.name.substring(0, lastDot) + ".xml") |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Converts the <code>fromApi</code>.txt file (or the most recently released |
| 361 | * X.Y.Z.txt if not explicitly defined using -DfromAPi=<file>) to XML format |
| 362 | * for use by JDiff. |
| 363 | */ |
| 364 | task oldApiXml(type: ApiXmlConversionTask, dependsOn: configurations.doclava) { |
| 365 | classpath configurations.doclava.resolve() |
| 366 | |
| 367 | if (project.hasProperty("fromApi")) { |
| 368 | // Use an explicit API file. |
| 369 | inputApiFile = new File(project.rootDir, "api/${fromApi}.txt") |
| 370 | } else if (project.hasProperty("toApi") && toApi.matches(~/(\d+\.){2}\d+/)) { |
| 371 | // If toApi matches released API (X.Y.Z) format, use the most recently |
| 372 | // released API file prior to toApi. |
| 373 | inputApiFile = getReleasedApiFile(toApi) |
| 374 | } else { |
| 375 | // Use the most recently released API file. |
| 376 | inputApiFile = getReleasedApiFile(); |
| 377 | } |
| 378 | |
| 379 | int lastDot = inputApiFile.name.lastIndexOf('.') |
| 380 | outputApiXmlFile = new File(project.docsDir, |
| 381 | "release/" + inputApiFile.name.substring(0, lastDot) + ".xml") |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * Generates API diffs. |
| 386 | * <p> |
| 387 | * By default, diffs are generated for the delta between current.txt and the |
| 388 | * next most recent X.Y.Z.txt API file. Behavior may be changed by specifying |
| 389 | * one or both of -DtoApi and -DfromApi. |
| 390 | * <p> |
| 391 | * If both fromApi and toApi are specified, diffs will be generated for |
| 392 | * fromApi -> toApi. For example, 25.0.0 -> 26.0.0 diffs could be generated by |
| 393 | * using: |
| 394 | * <br><code> |
| 395 | * ./gradlew generateDiffs -DfromApi=25.0.0 -DtoApi=26.0.0 |
| 396 | * </code> |
| 397 | * <p> |
| 398 | * If only toApi is specified, it MUST be specified as X.Y.Z and diffs will be |
| 399 | * generated for (release before toApi) -> toApi. For example, 24.2.0 -> 25.0.0 |
| 400 | * diffs could be generated by using: |
| 401 | * <br><code> |
| 402 | * ./gradlew generateDiffs -DtoApi=25.0.0 |
| 403 | * </code> |
| 404 | * <p> |
| 405 | * If only fromApi is specified, diffs will be generated for fromApi -> current. |
| 406 | * For example, lastApiReview -> current diffs could be generated by using: |
| 407 | * <br><code> |
| 408 | * ./gradlew generateDiffs -DfromApi=lastApiReview |
| 409 | * </code> |
| 410 | * <p> |
| 411 | */ |
| 412 | task generateDiffs(type: JDiffTask, dependsOn: [configurations.jdiff, configurations.doclava, |
| 413 | oldApiXml, newApiXml]) { |
| 414 | // Base classpath is Android SDK, sub-projects add their own. |
| 415 | classpath = project.ext.androidJar |
| 416 | |
| 417 | // JDiff properties. |
| 418 | oldApiXmlFile = oldApiXml.outputApiXmlFile |
| 419 | newApiXmlFile = newApiXml.outputApiXmlFile |
| 420 | newJavadocPrefix = "../../../../reference/" |
| 421 | |
| 422 | String newApi = newApiXmlFile.name |
| 423 | int lastDot = newApi.lastIndexOf('.') |
| 424 | newApi = newApi.substring(0, lastDot) |
| 425 | |
| 426 | // Javadoc properties. |
| 427 | docletpath = configurations.jdiff.resolve() |
| 428 | destinationDir = new File(project.docsDir, "support_api_diff/$newApi") |
| 429 | title = "Support Library API Differences Report" |
| 430 | |
| 431 | exclude '**/BuildConfig.java' |
| 432 | exclude '**/R.java' |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * Returns the most recently released API, optionally restricting to APIs |
| 437 | * before <code>beforeApi</code>. |
| 438 | * |
| 439 | * @param beforeApi the API to find an API file before, ex. 25.0.0 |
| 440 | * @return the most recently released API file |
| 441 | */ |
| 442 | File getReleasedApiFile(String beforeApi = null) { |
| 443 | String beforeApiFileName = beforeApi != null ? beforeApi + ".txt" : null |
| 444 | File lastReleasedApiFile = null |
| 445 | File apiDir = new File(project.rootDir, 'api') |
| 446 | |
| 447 | apiDir.eachFileMatch FileType.FILES, ~/(\d+\.){3}txt/, { File apiFile -> |
| 448 | // Is the current API file newer than the last one we saw? |
| 449 | if (lastReleasedApiFile == null || apiFile.name > lastReleasedApiFile.name) { |
| 450 | // Is the current API file older than the "before" API? |
| 451 | if (beforeApiFileName == null || apiFile.name < beforeApiFileName) { |
| 452 | lastReleasedApiFile = apiFile |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | return lastReleasedApiFile |
| 458 | } |
| 459 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 460 | subprojects { |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 461 | // Only modify Android projects. |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 462 | if (project.name.equals('doclava') || project.name.equals('jdiff')) return; |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 463 | |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 464 | // Current SDK is set in studioCompat.gradle. |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 465 | project.ext.currentSdk = gradle.ext.currentSdk |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 466 | apply plugin: 'maven' |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 467 | |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 468 | version = rootProject.ext.supportVersion |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 469 | group = 'com.android.support' |
| 470 | |
Yigit Boyar | be7a54a | 2015-04-07 13:23:50 -0700 | [diff] [blame] | 471 | repositories { |
| 472 | maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" } |
| 473 | maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" } |
| 474 | maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" } |
| 475 | } |
| 476 | |
Jeff Davidson | 84faec58 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 477 | project.plugins.whenPluginAdded { plugin -> |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 478 | def isAndroidLibrary = "com.android.build.gradle.LibraryPlugin".equals(plugin.class.name) |
| 479 | def isAndroidApp = "com.android.build.gradle.AppPlugin".equals(plugin.class.name) |
| 480 | def isJavaLibrary = "org.gradle.api.plugins.JavaPlugin".equals(plugin.class.name) |
| 481 | |
| 482 | if (isAndroidLibrary || isAndroidApp) { |
Jeff Davidson | 84faec58 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 483 | project.android.buildToolsVersion = rootProject.buildToolsVersion |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 484 | |
| 485 | // Enable code coverage for debug builds only if we are not running inside the IDE, |
| 486 | // since enabling coverage reports breaks the method parameter resolution in the IDE |
| 487 | // debugger. |
Yigit Boyar | d8d42d5 | 2016-04-12 18:20:18 -0700 | [diff] [blame] | 488 | project.android.buildTypes.debug.testCoverageEnabled = !hasProperty('android.injected.invoked.from.ide') |
Alan Viverette | af6b251 | 2016-11-16 17:33:10 -0500 | [diff] [blame] | 489 | |
Shankhoneer Chakrovarty | 2e6107d | 2016-10-17 17:39:35 -0700 | [diff] [blame] | 490 | // Copy the class files in a jar to be later used to generate code coverage report |
| 491 | project.android.testVariants.all { v -> |
| 492 | // check if the variant has any source files |
| 493 | // and test coverage is enabled |
| 494 | if (v.buildType.testCoverageEnabled |
| 495 | && v.sourceSets.any { !it.java.sourceFiles.isEmpty() }) { |
| 496 | def jarifyTask = project.tasks.create( |
| 497 | name: "package${v.name.capitalize()}ClassFilesForCoverageReport", |
| 498 | type: Jar) { |
Shankhoneer Chakrovarty | 719c323 | 2016-11-23 15:39:01 -0800 | [diff] [blame] | 499 | from v.testedVariant.javaCompile.destinationDir |
Shankhoneer Chakrovarty | 0056534b | 2017-01-03 17:34:35 -0800 | [diff] [blame] | 500 | exclude "**/R.class" |
| 501 | exclude "**/R\$*.class" |
Shankhoneer Chakrovarty | 6e45f61 | 2016-11-14 16:28:31 -0800 | [diff] [blame] | 502 | destinationDir file(project.distDir) |
| 503 | archiveName "${project.archivesBaseName}-${v.baseName}-allclasses.jar" |
Shankhoneer Chakrovarty | 2e6107d | 2016-10-17 17:39:35 -0700 | [diff] [blame] | 504 | } |
Shankhoneer Chakrovarty | 6e45f61 | 2016-11-14 16:28:31 -0800 | [diff] [blame] | 505 | def jacocoAntConfig = |
| 506 | project.configurations[JacocoPlugin.ANT_CONFIGURATION_NAME] |
| 507 | def jacocoAntArtifacts = jacocoAntConfig.resolvedConfiguration.resolvedArtifacts |
| 508 | def version = jacocoAntArtifacts.find { "org.jacoco.ant".equals(it.name) } |
| 509 | .moduleVersion.id.version |
| 510 | def collectJacocoAntPackages = project.tasks.create( |
| 511 | name: "collectJacocoAntPackages", |
| 512 | type: Jar) { |
| 513 | from (jacocoAntArtifacts.collect { zipTree(it.getFile()) }) { |
| 514 | // exclude all the signatures the jar might have |
| 515 | exclude "META-INF/*.SF" |
| 516 | exclude "META-INF/*.DSA" |
| 517 | exclude "META-INF/*.RSA" |
| 518 | } |
| 519 | destinationDir file(project.distDir) |
| 520 | archiveName "jacocoant-" + version + ".jar" |
Shankhoneer Chakrovarty | 2e6107d | 2016-10-17 17:39:35 -0700 | [diff] [blame] | 521 | } |
Shankhoneer Chakrovarty | 6e45f61 | 2016-11-14 16:28:31 -0800 | [diff] [blame] | 522 | v.assemble.dependsOn jarifyTask, collectJacocoAntPackages |
Shankhoneer Chakrovarty | 2e6107d | 2016-10-17 17:39:35 -0700 | [diff] [blame] | 523 | } |
| 524 | } |
Alan Viverette | e758964 | 2016-11-16 18:18:36 -0500 | [diff] [blame] | 525 | |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 526 | // Enforce NewApi lint check as fatal. |
Alan Viverette | af6b251 | 2016-11-16 17:33:10 -0500 | [diff] [blame] | 527 | project.android.lintOptions.check 'NewApi' |
| 528 | project.android.lintOptions.fatal 'NewApi' |
| 529 | project.parent.lint.dependsOn project.lint |
Jeff Davidson | 84faec58 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 530 | } |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 531 | |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 532 | if (isAndroidLibrary || isJavaLibrary) { |
| 533 | // Add library to the aggregate dependency report. |
| 534 | task allDeps(type: DependencyReportTask) {} |
| 535 | |
| 536 | // Create release and separate zip task for library. |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 537 | task release(type: Upload) { |
| 538 | configuration = configurations.archives |
| 539 | repositories { |
| 540 | mavenDeployer { |
| 541 | repository(url: uri("$rootProject.ext.supportRepoOut")) |
| 542 | |
| 543 | // Disable unique names for SNAPSHOTS so they can be updated in place. |
| 544 | setUniqueVersion(false) |
| 545 | doLast { |
| 546 | // Remove any invalid maven-metadata.xml files that may have been |
| 547 | // created for SNAPSHOT versions that are *not* uniquely versioned. |
| 548 | pom*.each { pom -> |
| 549 | if (pom.version.endsWith('-SNAPSHOT')) { |
| 550 | final File artifactDir = new File( |
| 551 | rootProject.ext.supportRepoOut, |
| 552 | pom.groupId.replace('.', '/') |
| 553 | + '/' + pom.artifactId |
| 554 | + '/' + pom.version) |
| 555 | delete fileTree(dir: artifactDir, |
| 556 | include: 'maven-metadata.xml*') |
| 557 | } |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | def deployer = release.repositories.mavenDeployer |
| 565 | deployer.pom*.whenConfigured { pom -> |
| 566 | pom.dependencies.findAll { dep -> |
| 567 | dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations' |
| 568 | }*.type = 'aar' |
| 569 | } |
| 570 | |
| 571 | ext.versionDir = { |
| 572 | def groupDir = new File(rootProject.ext.supportRepoOut, |
| 573 | project.group.replace('.','/')) |
| 574 | def artifactDir = new File(groupDir, archivesBaseName) |
| 575 | return new File(artifactDir, version) |
| 576 | } |
| 577 | |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 578 | task generateSourceProps(dependsOn: createRepository) |
| 579 | generateSourceProps.doLast({ |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 580 | def content = "Maven.GroupId=$deployer.pom.groupId\n" + |
| 581 | "Maven.ArtifactId=$deployer.pom.artifactId\n" + |
| 582 | "Maven.Version=$deployer.pom.version\n" + |
Alan Viverette | 4453f0d | 2016-09-14 12:32:27 -0700 | [diff] [blame] | 583 | "Extra.VendorDisplay=Android\n" + |
| 584 | "Extra.VendorId=android\n" + |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 585 | "Pkg.Desc=$project.name\n" + |
| 586 | "Pkg.Revision=1\n" + |
Alan Viverette | 4453f0d | 2016-09-14 12:32:27 -0700 | [diff] [blame] | 587 | "Maven.Dependencies=" + |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 588 | String.join(",", project.configurations.compile.allDependencies.collect { |
| 589 | def p = parent.findProject(it.name) |
| 590 | return p ? "$p.group:$p.archivesBaseName:$p.version" : null |
| 591 | }.grep()) + |
| 592 | "\n" |
| 593 | Files.write(content, new File(versionDir(), 'source.properties'), Charsets.UTF_8) |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 594 | }) |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 595 | |
| 596 | task createSeparateZip(type: Zip, dependsOn: generateSourceProps) { |
| 597 | into archivesBaseName |
| 598 | destinationDir project.parent.ext.distDir |
| 599 | baseName = project.group |
| 600 | version = project.parent.ext.buildNumber |
| 601 | } |
| 602 | project.parent.createArchive.dependsOn createSeparateZip |
| 603 | |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 604 | // Before the upload, make sure the repo is ready. |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 605 | release.dependsOn rootProject.tasks.prepareRepo |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 606 | |
| 607 | // Make the mainupload depend on this one. |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 608 | mainUpload.dependsOn release |
| 609 | } |
Jeff Davidson | 84faec58 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 610 | } |
Chris Banes | daea069 | 2015-12-29 12:48:24 +0000 | [diff] [blame] | 611 | |
Chris Banes | daea069 | 2015-12-29 12:48:24 +0000 | [diff] [blame] | 612 | project.afterEvaluate { |
Joe Baker-Malone | 5e2c51d | 2016-05-13 15:09:24 -0700 | [diff] [blame] | 613 | // The archivesBaseName isn't available intially, so set it now |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 614 | def createZipTask = project.tasks.findByName("createSeparateZip") |
| 615 | if (createZipTask != null) { |
| 616 | createZipTask.appendix = archivesBaseName |
| 617 | createZipTask.from versionDir() |
| 618 | } |
Joe Baker-Malone | 5e2c51d | 2016-05-13 15:09:24 -0700 | [diff] [blame] | 619 | |
| 620 | // Copy instrumentation test APK into the dist dir |
Chris Banes | daea069 | 2015-12-29 12:48:24 +0000 | [diff] [blame] | 621 | def assembleTestTask = project.tasks.findByPath('assembleAndroidTest') |
| 622 | if (assembleTestTask != null) { |
| 623 | assembleTestTask.doLast { |
| 624 | // If the project actually has some instrumentation tests, copy its APK |
| 625 | if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) { |
| 626 | def pkgTask = project.tasks.findByPath('packageDebugAndroidTest') |
| 627 | copy { |
| 628 | from(pkgTask.outputFile) |
| 629 | into(rootProject.ext.testApkDistOut) |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 | } |
Yigit Boyar | ea5d9b2 | 2016-03-08 13:25:26 -0800 | [diff] [blame] | 635 | |
| 636 | project.afterEvaluate { p -> |
| 637 | // remove dependency on the test so that we still get coverage even if some tests fail |
| 638 | p.tasks.findAll { it instanceof JacocoReportTask}.each { task -> |
| 639 | def toBeRemoved = new ArrayList() |
| 640 | def dependencyList = task.taskDependencies.values |
| 641 | dependencyList.each { dep -> |
| 642 | if (dep instanceof String) { |
| 643 | def t = tasks.findByName(dep) |
| 644 | if (t instanceof DeviceProviderInstrumentTestTask) { |
| 645 | toBeRemoved.add(dep) |
| 646 | task.mustRunAfter(t) |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | toBeRemoved.each { dep -> |
| 651 | dependencyList.remove(dep) |
| 652 | } |
| 653 | } |
| 654 | } |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 655 | |
| 656 | project.afterEvaluate { p -> |
| 657 | if (p.hasProperty('android') |
| 658 | && p.android.hasProperty('libraryVariants') |
| 659 | && !(p.android.hasProperty('noDocs') && p.android.noDocs)) { |
| 660 | p.android.libraryVariants.all { v -> |
| 661 | if (v.name == 'release') { |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 662 | registerForDocsTask(rootProject.generateDocs, p, v) |
| 663 | registerForDocsTask(rootProject.generateApi, p, v) |
Alan Viverette | 9290dcd | 2016-12-15 17:29:58 -0500 | [diff] [blame] | 664 | registerForDocsTask(rootProject.generateDiffs, p, v) |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 665 | } |
| 666 | } |
| 667 | } |
| 668 | } |
Chris Banes | 310f81d | 2016-11-13 16:13:53 +0000 | [diff] [blame] | 669 | |
| 670 | // Update the version meta-data in each Manifest |
| 671 | project.afterEvaluate { p -> |
| 672 | if (p.hasProperty('android')) { |
| 673 | p.android.defaultConfig.manifestPlaceholders = |
| 674 | ["support-version": rootProject.ext.supportVersion] |
| 675 | } |
| 676 | } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Chris Banes | 9ae4ee8 | 2015-09-11 10:32:15 +1000 | [diff] [blame] | 679 | project.gradle.buildFinished { buildResult -> |
| 680 | if (buildResult.getFailure() != null) { |
| 681 | println() |
| 682 | println 'Build failed. Possible causes include:' |
| 683 | println ' 1) Bad codes' |
| 684 | println ' 2) Out of date prebuilts in prebuilts/sdk' |
Chris Banes | 9e2e803 | 2015-09-16 10:15:37 +0100 | [diff] [blame] | 685 | println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle' |
Chris Banes | 9ae4ee8 | 2015-09-11 10:32:15 +1000 | [diff] [blame] | 686 | println() |
| 687 | } |
| 688 | } |