Alan Viverette | 77d397d | 2016-11-23 13:14:16 -0500 | [diff] [blame] | 1 | import android.support.checkapi.CheckApiTask |
| 2 | import android.support.checkapi.UpdateApiTask |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 3 | import android.support.doclava.DoclavaMultilineJavadocOptionFileOption |
Alan Viverette | 77d397d | 2016-11-23 13:14:16 -0500 | [diff] [blame] | 4 | import android.support.doclava.DoclavaTask |
| 5 | |
Yigit Boyar | ea5d9b2 | 2016-03-08 13:25:26 -0800 | [diff] [blame] | 6 | import com.android.build.gradle.internal.coverage.JacocoReportTask |
| 7 | import com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask |
Aurimas Liutikas | f8cf145 | 2016-11-21 20:32:13 +0000 | [diff] [blame] | 8 | import org.gradle.internal.os.OperatingSystem |
Yigit Boyar | ea5d9b2 | 2016-03-08 13:25:26 -0800 | [diff] [blame] | 9 | |
Alan Viverette | 77d397d | 2016-11-23 13:14:16 -0500 | [diff] [blame] | 10 | import com.google.common.base.Charsets |
| 11 | import com.google.common.hash.HashCode |
| 12 | import com.google.common.hash.HashFunction |
| 13 | import com.google.common.hash.Hashing |
| 14 | import com.google.common.io.Files |
| 15 | |
| 16 | import groovy.io.FileType |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 17 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 18 | buildscript { |
| 19 | repositories { |
| 20 | maven { url '../../prebuilts/gradle-plugin' } |
| 21 | maven { url '../../prebuilts/tools/common/m2/repository' } |
| 22 | maven { url '../../prebuilts/tools/common/m2/internal' } |
Yigit Boyar | c9750a1 | 2016-01-06 17:28:55 -0800 | [diff] [blame] | 23 | maven { url "../../prebuilts/maven_repo/android" } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 24 | } |
| 25 | dependencies { |
Aurimas Liutikas | 5c6933b | 2016-09-20 09:55:40 -0700 | [diff] [blame] | 26 | // Keep gradle plugin version in sync with ub_supportlib-master manifest. |
Aurimas Liutikas | aca4aad | 2016-10-12 14:48:41 -0700 | [diff] [blame] | 27 | classpath 'com.android.tools.build:gradle:2.2.1' |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 28 | } |
| 29 | } |
| 30 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 31 | repositories { |
| 32 | maven { url '../../prebuilts/tools/common/m2/repository' } |
| 33 | } |
| 34 | |
| 35 | configurations { |
| 36 | doclava |
| 37 | } |
| 38 | |
| 39 | dependencies { |
| 40 | doclava project(':doclava') |
| 41 | } |
| 42 | |
Aurimas Liutikas | f8cf145 | 2016-11-21 20:32:13 +0000 | [diff] [blame] | 43 | gradle.ext.currentSdk = 25 |
Kathy Kam | ecc8636 | 2016-12-21 10:18:08 -0800 | [diff] [blame] | 44 | ext.supportVersion = '25.1.1-SNAPSHOT' |
Kathy Kam | 0917338 | 2016-12-06 14:42:08 -0800 | [diff] [blame] | 45 | ext.extraVersion = 41 |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 46 | ext.supportRepoOut = '' |
Aurimas Liutikas | 78449c1 | 2016-11-14 15:20:08 -0800 | [diff] [blame] | 47 | ext.buildToolsVersion = '24.0.1' |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 48 | ext.buildNumber = Integer.toString(ext.extraVersion) |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 49 | |
Aurimas Liutikas | dfe7578 | 2016-08-03 14:27:20 -0700 | [diff] [blame] | 50 | ext.testRunnerVersion = '0.6-alpha' |
| 51 | ext.espressoVersion = '2.3-alpha' |
| 52 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 53 | // Enforce the use of prebuilt dependencies in all sub-projects. This is |
| 54 | // required for the doclava dependency. |
| 55 | ext.usePrebuilts = "true" |
| 56 | |
Aurimas Liutikas | f8cf145 | 2016-11-21 20:32:13 +0000 | [diff] [blame] | 57 | // Use the embedded SDK by default, which can be overridden by setting the 'sdk.dir' property |
| 58 | // (e.g. local.properties) or the 'ANDROID_HOME' environment variable. |
| 59 | final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux' |
Aurimas Liutikas | 3edb1fa | 2016-12-06 11:35:30 -0800 | [diff] [blame] | 60 | ext.sdkDirectory = "${rootDir}/../../prebuilts/fullsdk-${platform}"; |
| 61 | System.setProperty('android.home', sdkDirectory) |
Aurimas Liutikas | f8cf145 | 2016-11-21 20:32:13 +0000 | [diff] [blame] | 62 | |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 63 | /* |
| 64 | * With the build server you are given two env variables. |
| 65 | * The OUT_DIR is a temporary directory you can use to put things during the build. |
| 66 | * The DIST_DIR is where you want to save things from the build. |
| 67 | * |
| 68 | * The build server will copy the contents of DIST_DIR to somewhere and make it available. |
| 69 | */ |
| 70 | if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) { |
Xavier Ducrohet | 4e04b7a | 2014-10-17 18:02:33 -0700 | [diff] [blame] | 71 | buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile() |
| 72 | project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile() |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 73 | |
| 74 | // the build server does not pass the build number so we infer it from the last folder of the dist path. |
| 75 | ext.buildNumber = project.ext.distDir.getName() |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 76 | } else { |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 77 | buildDir = file("${project.rootDir}/../../out/host/gradle/frameworks/support/build") |
| 78 | project.ext.distDir = file("${project.rootDir}/../../out/dist") |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 79 | } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 80 | |
Alan Viverette | 9b5fe93 | 2016-07-22 10:28:31 -0400 | [diff] [blame] | 81 | subprojects { |
| 82 | // Change buildDir first so that all plugins pick up the new value. |
| 83 | project.buildDir = project.file("$project.parent.buildDir/../$project.name/build") |
| 84 | } |
| 85 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 86 | ext.docsDir = new File(buildDir, 'javadoc') |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 87 | ext.supportRepoOut = new File(buildDir, 'support_repo') |
Yigit Boyar | f18d975 | 2015-12-01 13:45:28 -0800 | [diff] [blame] | 88 | ext.testApkDistOut = ext.distDir |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 89 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 90 | // Main task called by the build server. |
| 91 | task(createArchive) << { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 94 | // upload anchor for subprojects to upload their artifacts |
| 95 | // to the local repo. |
| 96 | task(mainUpload) << { |
| 97 | } |
| 98 | |
| 99 | // repository creation task |
| 100 | task createRepository(type: Zip, dependsOn: mainUpload) { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 101 | from project.ext.supportRepoOut |
| 102 | destinationDir project.ext.distDir |
Xavier Ducrohet | 9dc4480 | 2014-03-20 14:15:16 -0700 | [diff] [blame] | 103 | into 'm2repository' |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 104 | baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber) |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 105 | } |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 106 | createArchive.dependsOn createRepository |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 107 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 108 | // prepare repository with older versions |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 109 | task unzipRepo(type: Copy) { |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 110 | from "${project.rootDir}/../../prebuilts/maven_repo/android" |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 111 | into project.ext.supportRepoOut |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 112 | } |
| 113 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 114 | unzipRepo.doFirst { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 115 | project.ext.supportRepoOut.deleteDir() |
| 116 | project.ext.supportRepoOut.mkdirs() |
| 117 | } |
| 118 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 119 | // anchor for prepare repo. This is post unzip + sourceProp. |
| 120 | task(prepareRepo) << { |
| 121 | } |
| 122 | |
Alan Viverette | af6b251 | 2016-11-16 17:33:10 -0500 | [diff] [blame] | 123 | // lint every library |
| 124 | task(lint) << { |
| 125 | } |
| 126 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 127 | task(createXml) << { |
| 128 | def repoArchive = createRepository.archivePath |
| 129 | def repoArchiveName = createRepository.archiveName |
| 130 | def size = repoArchive.length() |
| 131 | def sha1 = getSha1(repoArchive) |
| 132 | |
| 133 | def xml = |
| 134 | "<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\ |
| 135 | <sdk:extra>\n\ |
| 136 | <sdk:revision>\n\ |
| 137 | <sdk:major>${project.ext.extraVersion}</sdk:major>\n\ |
| 138 | </sdk:revision>\n\ |
| 139 | <sdk:vendor-display>Android</sdk:vendor-display>\n\ |
| 140 | <sdk:vendor-id>android</sdk:vendor-id>\n\ |
| 141 | <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\ |
| 142 | <sdk:path>m2repository</sdk:path>\n\ |
| 143 | <sdk:archives>\n\ |
Xavier Ducrohet | c16b62d | 2014-12-09 12:37:45 -0800 | [diff] [blame] | 144 | <sdk:archive>\n\ |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 145 | <sdk:size>${size}</sdk:size>\n\ |
| 146 | <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\ |
| 147 | <sdk:url>${repoArchiveName}</sdk:url>\n\ |
| 148 | </sdk:archive>\n\ |
| 149 | </sdk:archives>\n\ |
| 150 | </sdk:extra>\n\ |
| 151 | </sdk:sdk-addon>" |
| 152 | |
| 153 | Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8) |
| 154 | } |
| 155 | createArchive.dependsOn createXml |
| 156 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 157 | task(createSourceProp) << { |
| 158 | def sourceProp = |
| 159 | "Extra.VendorDisplay=Android\n\ |
| 160 | Extra.Path=m2repository\n\ |
| 161 | Archive.Arch=ANY\n\ |
| 162 | Extra.NameDisplay=Android Support Repository\n\ |
| 163 | Archive.Os=ANY\n\ |
Alan Viverette | 5ae24d6 | 2016-04-06 16:17:13 -0400 | [diff] [blame] | 164 | Pkg.Desc=Local Maven repository for Support Libraries\n\ |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 165 | Pkg.Revision=${project.ext.extraVersion}.0.0\n\ |
| 166 | Extra.VendorId=android" |
| 167 | |
| 168 | Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8) |
| 169 | } |
| 170 | createSourceProp.dependsOn unzipRepo |
| 171 | prepareRepo.dependsOn createSourceProp |
| 172 | |
Chris Banes | 96f1e91 | 2015-03-05 20:04:05 +0000 | [diff] [blame] | 173 | import java.nio.charset.Charset |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 174 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 175 | /** |
| 176 | * Generates SHA1 hash for the specified file's absolute path. |
| 177 | * |
| 178 | * @param inputFile file to hash |
| 179 | * @return SHA1 hash |
| 180 | */ |
| 181 | String getSha1(File inputFile) { |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 182 | HashFunction hashFunction = Hashing.sha1() |
Chris Banes | 96f1e91 | 2015-03-05 20:04:05 +0000 | [diff] [blame] | 183 | HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8")) |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 184 | return hashCode.toString() |
| 185 | } |
| 186 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 187 | /** |
| 188 | * Returns the Android prebuilt JAR for the specified API level. |
| 189 | * |
| 190 | * @param apiLevel the API level or "current" |
| 191 | * @return a file collection containing the Android prebuilt JAR |
| 192 | */ |
Yigit Boyar | 9673b85 | 2016-06-14 11:13:32 -0700 | [diff] [blame] | 193 | FileCollection getAndroidPrebuilt(apiLevel) { |
Aurimas Liutikas | 3edb1fa | 2016-12-06 11:35:30 -0800 | [diff] [blame] | 194 | files("${ext.sdkDirectory}/platforms/android-${apiLevel}/android.jar") |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 197 | void registerForDocsTask(Task task, Project subProject, releaseVariant) { |
| 198 | task.dependsOn releaseVariant.javaCompile |
| 199 | task.source { |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 200 | def buildConfig = fileTree(releaseVariant.getGenerateBuildConfig().sourceOutputDir) |
| 201 | return releaseVariant.javaCompile.source.minus(buildConfig) + |
| 202 | fileTree(releaseVariant.aidlCompile.sourceOutputDir) + |
| 203 | fileTree(releaseVariant.outputs[0].processResources.sourceOutputDir) |
| 204 | } |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 205 | task.classpath += files(releaseVariant.javaCompile.classpath) + |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 206 | files(releaseVariant.javaCompile.destinationDir) |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 207 | } |
| 208 | |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 209 | // Generates online docs. |
| 210 | task generateDocs(type: DoclavaTask, dependsOn: configurations.doclava) { |
| 211 | docletpath = configurations.doclava.resolve() |
| 212 | destinationDir = new File(project.docsDir, "online") |
| 213 | |
| 214 | // Base classpath is Android SDK, sub-projects add their own. |
| 215 | classpath = getAndroidPrebuilt(gradle.ext.currentSdk) |
| 216 | |
| 217 | def hdfOption = new DoclavaMultilineJavadocOptionFileOption('hdf') |
| 218 | hdfOption.add( |
| 219 | ['android.whichdoc', 'online'], |
| 220 | ['android.hasSamples', 'true']); |
| 221 | |
Alan Viverette | 989f27a | 2016-11-29 17:28:15 -0500 | [diff] [blame] | 222 | // Default hidden errors + hidden superclass (111) and |
| 223 | // deprecation mismatch (113) to match framework docs. |
| 224 | final def hidden = [105, 107, 111, 112, 113, 115, 116, 121] |
| 225 | |
| 226 | doclavaErrors = (101..122) - hidden |
| 227 | doclavaWarnings = [] |
| 228 | doclavaHidden += hidden |
| 229 | |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 230 | options { |
| 231 | addStringOption "templatedir", |
| 232 | "${project.rootDir}/../../build/tools/droiddoc/templates-sdk" |
| 233 | addStringOption "federate Android", "http://developer.android.com" |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 234 | addStringOption "stubpackages", "android.support.*" |
| 235 | addStringOption "samplesdir", "${project.rootDir}/samples" |
| 236 | addOption hdfOption |
| 237 | } |
| 238 | |
| 239 | exclude '**/BuildConfig.java' |
| 240 | } |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 241 | |
| 242 | // Generates API files. |
| 243 | task generateApi(type: DoclavaTask, dependsOn: configurations.doclava) { |
| 244 | docletpath = configurations.doclava.resolve() |
| 245 | destinationDir = project.docsDir |
| 246 | |
| 247 | // Base classpath is Android SDK, sub-projects add their own. |
| 248 | classpath = getAndroidPrebuilt(gradle.ext.currentSdk) |
| 249 | |
| 250 | apiFile = new File(project.docsDir, 'release/current.txt') |
| 251 | removedApiFile = new File(project.docsDir, 'release/removed.txt') |
| 252 | generateDocs = false |
| 253 | |
| 254 | options { |
| 255 | addStringOption "templatedir", |
| 256 | "${project.rootDir}/../../build/tools/droiddoc/templates-sdk" |
| 257 | addStringOption "federate Android", "http://developer.android.com" |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 258 | addStringOption "stubpackages", "android.support.*" |
| 259 | } |
| 260 | exclude '**/BuildConfig.java' |
| 261 | exclude '**/R.java' |
| 262 | } |
| 263 | |
| 264 | // Copies generated API files to current version. |
| 265 | task updateApi(type: UpdateApiTask, dependsOn: generateApi) { |
| 266 | newApiFile = new File(project.docsDir, 'release/current.txt') |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 267 | oldApiFile = new File(project.rootDir, 'api/current.txt') |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 268 | newRemovedApiFile = new File(project.docsDir, 'release/removed.txt') |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 269 | oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt') |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | // Checks generated API files against current version. |
| 273 | task checkApi(type: CheckApiTask, dependsOn: generateApi) { |
| 274 | doclavaClasspath = generateApi.docletpath |
| 275 | |
| 276 | checkApiTaskPath = name |
| 277 | updateApiTaskPath = updateApi.name |
| 278 | |
Alan Viverette | 77d397d | 2016-11-23 13:14:16 -0500 | [diff] [blame] | 279 | // Check that the API we're building hasn't changed from the development |
| 280 | // version. These typed of changes require an explicit API file update. |
| 281 | checkApiErrors = (2..30)-[22] |
| 282 | checkApiWarnings = [] |
| 283 | checkApiHidden = [22] |
| 284 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 285 | newApiFile = new File(project.docsDir, 'release/current.txt') |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 286 | oldApiFile = new File(project.rootDir, 'api/current.txt') |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 287 | newRemovedApiFile = new File(project.docsDir, 'release/removed.txt') |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 288 | oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt') |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 289 | } |
Alan Viverette | dd377c9 | 2016-06-24 09:51:49 -0400 | [diff] [blame] | 290 | createArchive.dependsOn checkApi |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 291 | |
Alan Viverette | 77d397d | 2016-11-23 13:14:16 -0500 | [diff] [blame] | 292 | // Checks generated API files against current version. |
| 293 | task checkApiStable(type: CheckApiTask, dependsOn: generateApi) { |
| 294 | doclavaClasspath = generateApi.docletpath |
| 295 | |
| 296 | checkApiTaskPath = name |
| 297 | updateApiTaskPath = updateApi.name |
| 298 | |
| 299 | // Check that the API we're building hasn't broken the last-released |
| 300 | // library version. These types of changes are forbidden. |
| 301 | checkApiErrors = (7..18) |
| 302 | checkApiWarnings = [23, 24] |
| 303 | checkApiHidden = (2..6) + (19..22) + (25..30) |
| 304 | |
| 305 | def lastReleasedApiFile = null |
| 306 | def apiDir = new File(project.rootDir, 'api') |
| 307 | apiDir.eachFileMatch FileType.FILES, ~/(\d+\.){3}txt/, { File apiFile -> |
| 308 | if (lastReleasedApiFile == null || apiFile.name > lastReleasedApiFile.name) { |
| 309 | lastReleasedApiFile = apiFile; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | newApiFile = new File(project.docsDir, 'release/current.txt') |
| 314 | oldApiFile = lastReleasedApiFile |
| 315 | newRemovedApiFile = new File(project.docsDir, 'release/removed.txt') |
| 316 | oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt') |
| 317 | } |
| 318 | checkApi.dependsOn checkApiStable |
| 319 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 320 | subprojects { |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 321 | // Only modify Android projects. |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 322 | if (project.name.equals('doclava')) return; |
| 323 | |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 324 | // Current SDK is set in studioCompat.gradle. |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 325 | project.ext.currentSdk = gradle.ext.currentSdk |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 326 | apply plugin: 'maven' |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 327 | |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 328 | version = rootProject.ext.supportVersion |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 329 | group = 'com.android.support' |
| 330 | |
Yigit Boyar | be7a54a | 2015-04-07 13:23:50 -0700 | [diff] [blame] | 331 | repositories { |
| 332 | maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" } |
| 333 | maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" } |
| 334 | maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" } |
| 335 | } |
| 336 | |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 337 | project.plugins.whenPluginAdded { plugin -> |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 338 | def isAndroidLibrary = "com.android.build.gradle.LibraryPlugin".equals(plugin.class.name) |
| 339 | def isAndroidApp = "com.android.build.gradle.AppPlugin".equals(plugin.class.name) |
| 340 | def isJavaLibrary = "org.gradle.api.plugins.JavaPlugin".equals(plugin.class.name) |
| 341 | |
| 342 | if (isAndroidLibrary || isAndroidApp) { |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 343 | project.android.buildToolsVersion = rootProject.buildToolsVersion |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 344 | |
| 345 | // Enable code coverage for debug builds only if we are not running inside the IDE, |
| 346 | // since enabling coverage reports breaks the method parameter resolution in the IDE |
| 347 | // debugger. |
Yigit Boyar | d8d42d5 | 2016-04-12 18:20:18 -0700 | [diff] [blame] | 348 | project.android.buildTypes.debug.testCoverageEnabled = !hasProperty('android.injected.invoked.from.ide') |
Alan Viverette | af6b251 | 2016-11-16 17:33:10 -0500 | [diff] [blame] | 349 | |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 350 | // Enforce NewApi lint check as fatal. |
Alan Viverette | af6b251 | 2016-11-16 17:33:10 -0500 | [diff] [blame] | 351 | project.android.lintOptions.check 'NewApi' |
| 352 | project.android.lintOptions.fatal 'NewApi' |
| 353 | project.parent.lint.dependsOn project.lint |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 354 | } |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 355 | |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 356 | if (isAndroidLibrary || isJavaLibrary) { |
| 357 | // Add library to the aggregate dependency report. |
| 358 | task allDeps(type: DependencyReportTask) {} |
| 359 | |
| 360 | // Create release and separate zip task for library. |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 361 | task release(type: Upload) { |
| 362 | configuration = configurations.archives |
| 363 | repositories { |
| 364 | mavenDeployer { |
| 365 | repository(url: uri("$rootProject.ext.supportRepoOut")) |
| 366 | |
| 367 | // Disable unique names for SNAPSHOTS so they can be updated in place. |
| 368 | setUniqueVersion(false) |
| 369 | doLast { |
| 370 | // Remove any invalid maven-metadata.xml files that may have been |
| 371 | // created for SNAPSHOT versions that are *not* uniquely versioned. |
| 372 | pom*.each { pom -> |
| 373 | if (pom.version.endsWith('-SNAPSHOT')) { |
| 374 | final File artifactDir = new File( |
| 375 | rootProject.ext.supportRepoOut, |
| 376 | pom.groupId.replace('.', '/') |
| 377 | + '/' + pom.artifactId |
| 378 | + '/' + pom.version) |
| 379 | delete fileTree(dir: artifactDir, |
| 380 | include: 'maven-metadata.xml*') |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | def deployer = release.repositories.mavenDeployer |
| 389 | deployer.pom*.whenConfigured { pom -> |
| 390 | pom.dependencies.findAll { dep -> |
| 391 | dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations' |
| 392 | }*.type = 'aar' |
| 393 | } |
| 394 | |
| 395 | ext.versionDir = { |
| 396 | def groupDir = new File(rootProject.ext.supportRepoOut, |
| 397 | project.group.replace('.','/')) |
| 398 | def artifactDir = new File(groupDir, archivesBaseName) |
| 399 | return new File(artifactDir, version) |
| 400 | } |
| 401 | |
| 402 | task generateSourceProps(dependsOn: createRepository) << { |
| 403 | def content = "Maven.GroupId=$deployer.pom.groupId\n" + |
| 404 | "Maven.ArtifactId=$deployer.pom.artifactId\n" + |
| 405 | "Maven.Version=$deployer.pom.version\n" + |
Alan Viverette | 4453f0d | 2016-09-14 12:32:27 -0700 | [diff] [blame] | 406 | "Extra.VendorDisplay=Android\n" + |
| 407 | "Extra.VendorId=android\n" + |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 408 | "Pkg.Desc=$project.name\n" + |
| 409 | "Pkg.Revision=1\n" + |
Alan Viverette | 4453f0d | 2016-09-14 12:32:27 -0700 | [diff] [blame] | 410 | "Maven.Dependencies=" + |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 411 | String.join(",", project.configurations.compile.allDependencies.collect { |
| 412 | def p = parent.findProject(it.name) |
| 413 | return p ? "$p.group:$p.archivesBaseName:$p.version" : null |
| 414 | }.grep()) + |
| 415 | "\n" |
| 416 | Files.write(content, new File(versionDir(), 'source.properties'), Charsets.UTF_8) |
| 417 | } |
| 418 | |
| 419 | task createSeparateZip(type: Zip, dependsOn: generateSourceProps) { |
| 420 | into archivesBaseName |
| 421 | destinationDir project.parent.ext.distDir |
| 422 | baseName = project.group |
| 423 | version = project.parent.ext.buildNumber |
| 424 | } |
| 425 | project.parent.createArchive.dependsOn createSeparateZip |
| 426 | |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 427 | // Before the upload, make sure the repo is ready. |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 428 | release.dependsOn rootProject.tasks.prepareRepo |
Alan Viverette | 5032373 | 2016-12-02 11:18:03 -0500 | [diff] [blame] | 429 | |
| 430 | // Make the mainupload depend on this one. |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 431 | mainUpload.dependsOn release |
| 432 | } |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 433 | } |
Chris Banes | daea069 | 2015-12-29 12:48:24 +0000 | [diff] [blame] | 434 | |
Chris Banes | daea069 | 2015-12-29 12:48:24 +0000 | [diff] [blame] | 435 | project.afterEvaluate { |
Joe Baker-Malone | 5e2c51d | 2016-05-13 15:09:24 -0700 | [diff] [blame] | 436 | // The archivesBaseName isn't available intially, so set it now |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 437 | def createZipTask = project.tasks.findByName("createSeparateZip") |
| 438 | if (createZipTask != null) { |
| 439 | createZipTask.appendix = archivesBaseName |
| 440 | createZipTask.from versionDir() |
| 441 | } |
Joe Baker-Malone | 5e2c51d | 2016-05-13 15:09:24 -0700 | [diff] [blame] | 442 | |
| 443 | // Copy instrumentation test APK into the dist dir |
Chris Banes | daea069 | 2015-12-29 12:48:24 +0000 | [diff] [blame] | 444 | def assembleTestTask = project.tasks.findByPath('assembleAndroidTest') |
| 445 | if (assembleTestTask != null) { |
| 446 | assembleTestTask.doLast { |
| 447 | // If the project actually has some instrumentation tests, copy its APK |
| 448 | if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) { |
| 449 | def pkgTask = project.tasks.findByPath('packageDebugAndroidTest') |
| 450 | copy { |
| 451 | from(pkgTask.outputFile) |
| 452 | into(rootProject.ext.testApkDistOut) |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | } |
Yigit Boyar | ea5d9b2 | 2016-03-08 13:25:26 -0800 | [diff] [blame] | 458 | |
| 459 | project.afterEvaluate { p -> |
| 460 | // remove dependency on the test so that we still get coverage even if some tests fail |
| 461 | p.tasks.findAll { it instanceof JacocoReportTask}.each { task -> |
| 462 | def toBeRemoved = new ArrayList() |
| 463 | def dependencyList = task.taskDependencies.values |
| 464 | dependencyList.each { dep -> |
| 465 | if (dep instanceof String) { |
| 466 | def t = tasks.findByName(dep) |
| 467 | if (t instanceof DeviceProviderInstrumentTestTask) { |
| 468 | toBeRemoved.add(dep) |
| 469 | task.mustRunAfter(t) |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | toBeRemoved.each { dep -> |
| 474 | dependencyList.remove(dep) |
| 475 | } |
| 476 | } |
| 477 | } |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 478 | |
| 479 | project.afterEvaluate { p -> |
| 480 | if (p.hasProperty('android') |
| 481 | && p.android.hasProperty('libraryVariants') |
| 482 | && !(p.android.hasProperty('noDocs') && p.android.noDocs)) { |
| 483 | p.android.libraryVariants.all { v -> |
| 484 | if (v.name == 'release') { |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 485 | registerForDocsTask(rootProject.generateDocs, p, v) |
| 486 | registerForDocsTask(rootProject.generateApi, p, v) |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | } |
| 490 | } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 491 | } |
| 492 | |
Chris Banes | 9ae4ee8 | 2015-09-11 10:32:15 +1000 | [diff] [blame] | 493 | project.gradle.buildFinished { buildResult -> |
| 494 | if (buildResult.getFailure() != null) { |
| 495 | println() |
| 496 | println 'Build failed. Possible causes include:' |
| 497 | println ' 1) Bad codes' |
| 498 | println ' 2) Out of date prebuilts in prebuilts/sdk' |
Chris Banes | 9e2e803 | 2015-09-16 10:15:37 +0100 | [diff] [blame] | 499 | 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] | 500 | println() |
| 501 | } |
| 502 | } |