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