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