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