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