Yigit Boyar | ea5d9b2 | 2016-03-08 13:25:26 -0800 | [diff] [blame] | 1 | import com.android.build.gradle.internal.coverage.JacocoReportTask |
| 2 | import com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask |
| 3 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 4 | buildscript { |
| 5 | repositories { |
| 6 | maven { url '../../prebuilts/gradle-plugin' } |
| 7 | maven { url '../../prebuilts/tools/common/m2/repository' } |
| 8 | maven { url '../../prebuilts/tools/common/m2/internal' } |
Yigit Boyar | c9750a1 | 2016-01-06 17:28:55 -0800 | [diff] [blame] | 9 | maven { url "../../prebuilts/maven_repo/android" } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 10 | } |
| 11 | dependencies { |
Xavier Ducrohet | 0df81c7 | 2016-05-11 16:35:45 -0700 | [diff] [blame] | 12 | classpath 'com.android.tools.build:gradle:2.2.0-alpha1' |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 13 | } |
| 14 | } |
| 15 | |
Chris Flatt | a48e18c | 2016-05-20 18:12:26 -0700 | [diff] [blame] | 16 | ext.supportVersion = '24.0.0' |
| 17 | ext.extraVersion = 33 |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 18 | ext.supportRepoOut = '' |
Yigit Boyar | c9750a1 | 2016-01-06 17:28:55 -0800 | [diff] [blame] | 19 | ext.buildToolsVersion = '23.0.2' |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 20 | ext.buildNumber = Integer.toString(ext.extraVersion) |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 21 | |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 22 | /* |
| 23 | * With the build server you are given two env variables. |
| 24 | * The OUT_DIR is a temporary directory you can use to put things during the build. |
| 25 | * The DIST_DIR is where you want to save things from the build. |
| 26 | * |
| 27 | * The build server will copy the contents of DIST_DIR to somewhere and make it available. |
| 28 | */ |
| 29 | if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) { |
Xavier Ducrohet | 4e04b7a | 2014-10-17 18:02:33 -0700 | [diff] [blame] | 30 | buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile() |
| 31 | project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile() |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 32 | |
| 33 | // the build server does not pass the build number so we infer it from the last folder of the dist path. |
| 34 | ext.buildNumber = project.ext.distDir.getName() |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 35 | } else { |
| 36 | buildDir = file('../../out/host/gradle/frameworks/support/build') |
| 37 | project.ext.distDir = file('../../out/dist') |
| 38 | } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 39 | |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 40 | ext.supportRepoOut = new File(buildDir, 'support_repo') |
Yigit Boyar | f18d975 | 2015-12-01 13:45:28 -0800 | [diff] [blame] | 41 | ext.testApkDistOut = ext.distDir |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 42 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 43 | // Main task called by the build server. |
| 44 | task(createArchive) << { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 47 | |
| 48 | // upload anchor for subprojects to upload their artifacts |
| 49 | // to the local repo. |
| 50 | task(mainUpload) << { |
| 51 | } |
| 52 | |
| 53 | // repository creation task |
| 54 | task createRepository(type: Zip, dependsOn: mainUpload) { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 55 | from project.ext.supportRepoOut |
| 56 | destinationDir project.ext.distDir |
Xavier Ducrohet | 9dc4480 | 2014-03-20 14:15:16 -0700 | [diff] [blame] | 57 | into 'm2repository' |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 58 | baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber) |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 59 | } |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 60 | createArchive.dependsOn createRepository |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 61 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 62 | // prepare repository with older versions |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 63 | task unzipRepo(type: Copy) { |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 64 | from "$rootDir/../../prebuilts/maven_repo/android" |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 65 | into project.ext.supportRepoOut |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 68 | unzipRepo.doFirst { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 69 | project.ext.supportRepoOut.deleteDir() |
| 70 | project.ext.supportRepoOut.mkdirs() |
| 71 | } |
| 72 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 73 | // anchor for prepare repo. This is post unzip + sourceProp. |
| 74 | task(prepareRepo) << { |
| 75 | } |
| 76 | |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 77 | |
| 78 | import android.support.build.ApiModule |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 79 | import com.google.common.io.Files |
| 80 | import com.google.common.base.Charsets |
| 81 | |
| 82 | task(createXml) << { |
| 83 | def repoArchive = createRepository.archivePath |
| 84 | def repoArchiveName = createRepository.archiveName |
| 85 | def size = repoArchive.length() |
| 86 | def sha1 = getSha1(repoArchive) |
| 87 | |
| 88 | def xml = |
| 89 | "<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\ |
| 90 | <sdk:extra>\n\ |
| 91 | <sdk:revision>\n\ |
| 92 | <sdk:major>${project.ext.extraVersion}</sdk:major>\n\ |
| 93 | </sdk:revision>\n\ |
| 94 | <sdk:vendor-display>Android</sdk:vendor-display>\n\ |
| 95 | <sdk:vendor-id>android</sdk:vendor-id>\n\ |
| 96 | <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\ |
| 97 | <sdk:path>m2repository</sdk:path>\n\ |
| 98 | <sdk:archives>\n\ |
Xavier Ducrohet | c16b62d | 2014-12-09 12:37:45 -0800 | [diff] [blame] | 99 | <sdk:archive>\n\ |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 100 | <sdk:size>${size}</sdk:size>\n\ |
| 101 | <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\ |
| 102 | <sdk:url>${repoArchiveName}</sdk:url>\n\ |
| 103 | </sdk:archive>\n\ |
| 104 | </sdk:archives>\n\ |
| 105 | </sdk:extra>\n\ |
| 106 | </sdk:sdk-addon>" |
| 107 | |
| 108 | Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8) |
| 109 | } |
| 110 | createArchive.dependsOn createXml |
| 111 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 112 | task(createSourceProp) << { |
| 113 | def sourceProp = |
| 114 | "Extra.VendorDisplay=Android\n\ |
| 115 | Extra.Path=m2repository\n\ |
| 116 | Archive.Arch=ANY\n\ |
| 117 | Extra.NameDisplay=Android Support Repository\n\ |
| 118 | Archive.Os=ANY\n\ |
Alan Viverette | 5ae24d6 | 2016-04-06 16:17:13 -0400 | [diff] [blame] | 119 | Pkg.Desc=Local Maven repository for Support Libraries\n\ |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 120 | Pkg.Revision=${project.ext.extraVersion}.0.0\n\ |
| 121 | Extra.VendorId=android" |
| 122 | |
| 123 | Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8) |
| 124 | } |
| 125 | createSourceProp.dependsOn unzipRepo |
| 126 | prepareRepo.dependsOn createSourceProp |
| 127 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 128 | import com.google.common.hash.HashCode |
| 129 | import com.google.common.hash.HashFunction |
| 130 | import com.google.common.hash.Hashing |
Chris Banes | 96f1e91 | 2015-03-05 20:04:05 +0000 | [diff] [blame] | 131 | import java.nio.charset.Charset |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 132 | |
| 133 | def getSha1(File inputFile) { |
| 134 | HashFunction hashFunction = Hashing.sha1() |
Chris Banes | 96f1e91 | 2015-03-05 20:04:05 +0000 | [diff] [blame] | 135 | HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8")) |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 136 | return hashCode.toString() |
| 137 | } |
| 138 | |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 139 | def createApiSourceSets(Project subProject, List<ApiModule> apiModules) { |
| 140 | subProject.ext._apiModules = apiModules |
| 141 | subProject.ext.allSS = [] |
| 142 | if (gradle.ext.studioCompat.enableApiModules) { |
| 143 | // nothing to do, they are all modules |
| 144 | return |
| 145 | } |
| 146 | // create a jar task for the api specific internal implementations |
| 147 | def internalJar = subProject.tasks.create(name: "internalJar", type: Jar) { |
| 148 | baseName "internal_impl" |
| 149 | } |
| 150 | apiModules.each { ApiModule apiModule -> |
| 151 | apiModule.sourceSet = createApiSourceset(subProject, apiModule.folderName, apiModule.folderName, |
| 152 | apiModule.apiForSourceSet.toString(), apiModule.prev == null ? null : apiModule.prev.sourceSet) |
| 153 | subProject.ext.allSS.add(apiModule.sourceSet) |
| 154 | } |
| 155 | subProject.android.libraryVariants.all { variant -> |
| 156 | variant.javaCompile.dependsOn internalJar |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | def createApiSourceset(Project subProject, String name, String folder, String apiLevel, |
| 161 | SourceSet previousSource) { |
| 162 | def sourceSet = subProject.sourceSets.create(name) |
| 163 | sourceSet.java.srcDirs = [folder] |
| 164 | |
| 165 | def configName = sourceSet.getCompileConfigurationName() |
| 166 | |
| 167 | subProject.getDependencies().add(configName, getAndroidPrebuilt(apiLevel)) |
| 168 | if (previousSource != null) { |
| 169 | setupDependencies(subProject, configName, previousSource) |
| 170 | } |
| 171 | subProject.ext.allSS.add(sourceSet) |
| 172 | subProject.tasks.internalJar.from sourceSet.output |
| 173 | return sourceSet |
| 174 | } |
| 175 | |
| 176 | def setApiModuleDependencies(Project subProject, DependencyHandler handler, List extraDeps) { |
| 177 | if (gradle.ext.studioCompat.enableApiModules) { |
| 178 | subProject.android.enforceUniquePackageName=false |
| 179 | // add dependency on the latest module |
| 180 | handler.compile(project(subProject.ext._apiModules.last().moduleName)) |
| 181 | } else { |
| 182 | handler.compile(files(subProject.tasks.internalJar.archivePath)) |
| 183 | def firstModule = subProject.ext._apiModules[0] |
| 184 | extraDeps.each { dep -> |
| 185 | handler."${firstModule.folderName}Compile"(project(dep)) |
| 186 | handler.compile(project(dep)) |
| 187 | } |
| 188 | |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | def setupDependencies(Project subProject, String configName, SourceSet previousSourceSet) { |
| 193 | subProject.getDependencies().add(configName, previousSourceSet.output) |
| 194 | subProject.getDependencies().add(configName, previousSourceSet.compileClasspath) |
| 195 | } |
| 196 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 197 | subprojects { |
| 198 | // Change buildDir first so that all plugins pick up the new value. |
Xavier Ducrohet | 616b95d | 2014-02-12 09:09:43 -0800 | [diff] [blame] | 199 | project.buildDir = project.file("$project.parent.buildDir/../$project.name/build") |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 200 | // current SDK is set in studioCompat.gradle |
| 201 | project.ext.currentSdk = gradle.ext.currentSdk |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 202 | apply plugin: 'maven' |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 203 | project.ext.createApiSourceSets = this.&createApiSourceset |
| 204 | project.ext.setApiModuleDependencies = this.&setApiModuleDependencies |
| 205 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 206 | |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 207 | version = rootProject.ext.supportVersion |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 208 | group = 'com.android.support' |
| 209 | |
Yigit Boyar | be7a54a | 2015-04-07 13:23:50 -0700 | [diff] [blame] | 210 | repositories { |
| 211 | maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" } |
| 212 | maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" } |
| 213 | maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" } |
| 214 | } |
| 215 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 216 | task release(type: Upload) { |
| 217 | configuration = configurations.archives |
| 218 | repositories { |
| 219 | mavenDeployer { |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 220 | repository(url: uri("$rootProject.ext.supportRepoOut")) |
Justin Klaassen | 533239e | 2016-01-09 09:16:23 -0800 | [diff] [blame] | 221 | |
| 222 | // Disable unique names for SNAPSHOTS so they can be updated in place. |
| 223 | setUniqueVersion(false) |
Justin Klaassen | d99d774 | 2016-01-21 15:33:57 -0800 | [diff] [blame] | 224 | doLast { |
| 225 | // Remove any invalid maven-metadata.xml files that may have been created |
| 226 | // for SNAPSHOT versions that are *not* uniquely versioned. |
| 227 | pom*.each { pom -> |
| 228 | if (pom.version.endsWith('-SNAPSHOT')) { |
| 229 | final File artifactDir = new File(rootProject.ext.supportRepoOut, |
| 230 | pom.groupId.replace('.', '/') |
| 231 | + '/' + pom.artifactId |
| 232 | + '/' + pom.version) |
| 233 | delete fileTree(dir: artifactDir, include: 'maven-metadata.xml*') |
| 234 | } |
| 235 | } |
| 236 | } |
Justin Klaassen | 533239e | 2016-01-09 09:16:23 -0800 | [diff] [blame] | 237 | } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 238 | } |
| 239 | } |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 240 | |
Xavier Ducrohet | e4cf5a9 | 2015-03-06 17:17:30 -0800 | [diff] [blame] | 241 | def deployer = release.repositories.mavenDeployer |
| 242 | deployer.pom*.whenConfigured { pom -> |
| 243 | pom.dependencies.findAll {dep -> dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations' }*.type = 'aar' |
| 244 | } |
| 245 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 246 | // before the upload, make sure the repo is ready. |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 247 | release.dependsOn rootProject.tasks.prepareRepo |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 248 | // make the mainupload depend on this one. |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 249 | mainUpload.dependsOn release |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 250 | |
| 251 | project.plugins.whenPluginAdded { plugin -> |
| 252 | if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) { |
| 253 | project.android.buildToolsVersion = rootProject.buildToolsVersion |
Yigit Boyar | d8d42d5 | 2016-04-12 18:20:18 -0700 | [diff] [blame] | 254 | // enable code coverage for debug builds only if we are not running inside the IDE |
| 255 | // enabling coverage reports breaks the method parameter resolution in the IDE debugger |
| 256 | project.android.buildTypes.debug.testCoverageEnabled = !hasProperty('android.injected.invoked.from.ide') |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
Chris Banes | daea069 | 2015-12-29 12:48:24 +0000 | [diff] [blame] | 259 | |
| 260 | // Copy instrumentation test APK into the dist dir |
| 261 | project.afterEvaluate { |
| 262 | def assembleTestTask = project.tasks.findByPath('assembleAndroidTest') |
| 263 | if (assembleTestTask != null) { |
| 264 | assembleTestTask.doLast { |
| 265 | // If the project actually has some instrumentation tests, copy its APK |
| 266 | if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) { |
| 267 | def pkgTask = project.tasks.findByPath('packageDebugAndroidTest') |
| 268 | copy { |
| 269 | from(pkgTask.outputFile) |
| 270 | into(rootProject.ext.testApkDistOut) |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | } |
Yigit Boyar | ea5d9b2 | 2016-03-08 13:25:26 -0800 | [diff] [blame] | 276 | |
| 277 | project.afterEvaluate { p -> |
| 278 | // remove dependency on the test so that we still get coverage even if some tests fail |
| 279 | p.tasks.findAll { it instanceof JacocoReportTask}.each { task -> |
| 280 | def toBeRemoved = new ArrayList() |
| 281 | def dependencyList = task.taskDependencies.values |
| 282 | dependencyList.each { dep -> |
| 283 | if (dep instanceof String) { |
| 284 | def t = tasks.findByName(dep) |
| 285 | if (t instanceof DeviceProviderInstrumentTestTask) { |
| 286 | toBeRemoved.add(dep) |
| 287 | task.mustRunAfter(t) |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | toBeRemoved.each { dep -> |
| 292 | dependencyList.remove(dep) |
| 293 | } |
| 294 | } |
| 295 | } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Chris Banes | 9ae4ee8 | 2015-09-11 10:32:15 +1000 | [diff] [blame] | 298 | project.gradle.buildFinished { buildResult -> |
| 299 | if (buildResult.getFailure() != null) { |
| 300 | println() |
| 301 | println 'Build failed. Possible causes include:' |
| 302 | println ' 1) Bad codes' |
| 303 | println ' 2) Out of date prebuilts in prebuilts/sdk' |
Chris Banes | 9e2e803 | 2015-09-16 10:15:37 +0100 | [diff] [blame] | 304 | 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] | 305 | println() |
| 306 | } |
| 307 | } |
| 308 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 309 | FileCollection getAndroidPrebuilt(String apiLevel) { |
| 310 | files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar") |
Tor Norbye | 47c59fb | 2015-04-08 14:42:16 -0700 | [diff] [blame] | 311 | } |