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 { |
Alan Viverette | 3780b50 | 2016-04-11 12:39:10 -0400 | [diff] [blame] | 12 | classpath 'com.android.tools.build:gradle:2.1.0-alpha4' |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 13 | } |
| 14 | } |
| 15 | |
Ian Pedowitz | c0f4ca6 | 2016-02-29 16:21:03 +0000 | [diff] [blame] | 16 | ext.supportVersion = '24.0.0-SNAPSHOT' |
| 17 | ext.extraVersion = 25 |
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 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 77 | import com.google.common.io.Files |
| 78 | import com.google.common.base.Charsets |
| 79 | |
| 80 | task(createXml) << { |
| 81 | def repoArchive = createRepository.archivePath |
| 82 | def repoArchiveName = createRepository.archiveName |
| 83 | def size = repoArchive.length() |
| 84 | def sha1 = getSha1(repoArchive) |
| 85 | |
| 86 | def xml = |
| 87 | "<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\ |
| 88 | <sdk:extra>\n\ |
| 89 | <sdk:revision>\n\ |
| 90 | <sdk:major>${project.ext.extraVersion}</sdk:major>\n\ |
| 91 | </sdk:revision>\n\ |
| 92 | <sdk:vendor-display>Android</sdk:vendor-display>\n\ |
| 93 | <sdk:vendor-id>android</sdk:vendor-id>\n\ |
| 94 | <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\ |
| 95 | <sdk:path>m2repository</sdk:path>\n\ |
| 96 | <sdk:archives>\n\ |
Xavier Ducrohet | c16b62d | 2014-12-09 12:37:45 -0800 | [diff] [blame] | 97 | <sdk:archive>\n\ |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 98 | <sdk:size>${size}</sdk:size>\n\ |
| 99 | <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\ |
| 100 | <sdk:url>${repoArchiveName}</sdk:url>\n\ |
| 101 | </sdk:archive>\n\ |
| 102 | </sdk:archives>\n\ |
| 103 | </sdk:extra>\n\ |
| 104 | </sdk:sdk-addon>" |
| 105 | |
| 106 | Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8) |
| 107 | } |
| 108 | createArchive.dependsOn createXml |
| 109 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 110 | task(createSourceProp) << { |
| 111 | def sourceProp = |
| 112 | "Extra.VendorDisplay=Android\n\ |
| 113 | Extra.Path=m2repository\n\ |
| 114 | Archive.Arch=ANY\n\ |
| 115 | Extra.NameDisplay=Android Support Repository\n\ |
| 116 | Archive.Os=ANY\n\ |
Alan Viverette | 5ae24d6 | 2016-04-06 16:17:13 -0400 | [diff] [blame] | 117 | Pkg.Desc=Local Maven repository for Support Libraries\n\ |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 118 | Pkg.Revision=${project.ext.extraVersion}.0.0\n\ |
| 119 | Extra.VendorId=android" |
| 120 | |
| 121 | Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8) |
| 122 | } |
| 123 | createSourceProp.dependsOn unzipRepo |
| 124 | prepareRepo.dependsOn createSourceProp |
| 125 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 126 | import com.google.common.hash.HashCode |
| 127 | import com.google.common.hash.HashFunction |
| 128 | import com.google.common.hash.Hashing |
Chris Banes | 96f1e91 | 2015-03-05 20:04:05 +0000 | [diff] [blame] | 129 | import java.nio.charset.Charset |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 130 | |
| 131 | def getSha1(File inputFile) { |
| 132 | HashFunction hashFunction = Hashing.sha1() |
Chris Banes | 96f1e91 | 2015-03-05 20:04:05 +0000 | [diff] [blame] | 133 | HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8")) |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 134 | return hashCode.toString() |
| 135 | } |
| 136 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 137 | subprojects { |
| 138 | // Change buildDir first so that all plugins pick up the new value. |
Xavier Ducrohet | 616b95d | 2014-02-12 09:09:43 -0800 | [diff] [blame] | 139 | project.buildDir = project.file("$project.parent.buildDir/../$project.name/build") |
Yigit Boyar | 02a9e8c | 2016-01-26 20:41:00 -0800 | [diff] [blame] | 140 | project.ext.currentSdk = 'current' |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 141 | apply plugin: 'maven' |
| 142 | |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 143 | version = rootProject.ext.supportVersion |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 144 | group = 'com.android.support' |
| 145 | |
Yigit Boyar | be7a54a | 2015-04-07 13:23:50 -0700 | [diff] [blame] | 146 | repositories { |
| 147 | maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" } |
| 148 | maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" } |
| 149 | maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" } |
| 150 | } |
| 151 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 152 | task release(type: Upload) { |
| 153 | configuration = configurations.archives |
| 154 | repositories { |
| 155 | mavenDeployer { |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 156 | repository(url: uri("$rootProject.ext.supportRepoOut")) |
Justin Klaassen | 533239e | 2016-01-09 09:16:23 -0800 | [diff] [blame] | 157 | |
| 158 | // Disable unique names for SNAPSHOTS so they can be updated in place. |
| 159 | setUniqueVersion(false) |
Justin Klaassen | d99d774 | 2016-01-21 15:33:57 -0800 | [diff] [blame] | 160 | doLast { |
| 161 | // Remove any invalid maven-metadata.xml files that may have been created |
| 162 | // for SNAPSHOT versions that are *not* uniquely versioned. |
| 163 | pom*.each { pom -> |
| 164 | if (pom.version.endsWith('-SNAPSHOT')) { |
| 165 | final File artifactDir = new File(rootProject.ext.supportRepoOut, |
| 166 | pom.groupId.replace('.', '/') |
| 167 | + '/' + pom.artifactId |
| 168 | + '/' + pom.version) |
| 169 | delete fileTree(dir: artifactDir, include: 'maven-metadata.xml*') |
| 170 | } |
| 171 | } |
| 172 | } |
Justin Klaassen | 533239e | 2016-01-09 09:16:23 -0800 | [diff] [blame] | 173 | } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 174 | } |
| 175 | } |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 176 | |
Xavier Ducrohet | e4cf5a9 | 2015-03-06 17:17:30 -0800 | [diff] [blame] | 177 | def deployer = release.repositories.mavenDeployer |
| 178 | deployer.pom*.whenConfigured { pom -> |
| 179 | pom.dependencies.findAll {dep -> dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations' }*.type = 'aar' |
| 180 | } |
| 181 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 182 | // before the upload, make sure the repo is ready. |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 183 | release.dependsOn rootProject.tasks.prepareRepo |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 184 | // make the mainupload depend on this one. |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 185 | mainUpload.dependsOn release |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 186 | |
| 187 | project.plugins.whenPluginAdded { plugin -> |
| 188 | if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) { |
| 189 | project.android.buildToolsVersion = rootProject.buildToolsVersion |
Yigit Boyar | ea5d9b2 | 2016-03-08 13:25:26 -0800 | [diff] [blame] | 190 | // enable code coverage for debug builds |
| 191 | // run createDebugCoverageReport to get the coverage |
| 192 | project.android.buildTypes.debug.testCoverageEnabled = true |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 193 | } |
| 194 | } |
Chris Banes | daea069 | 2015-12-29 12:48:24 +0000 | [diff] [blame] | 195 | |
| 196 | // Copy instrumentation test APK into the dist dir |
| 197 | project.afterEvaluate { |
| 198 | def assembleTestTask = project.tasks.findByPath('assembleAndroidTest') |
| 199 | if (assembleTestTask != null) { |
| 200 | assembleTestTask.doLast { |
| 201 | // If the project actually has some instrumentation tests, copy its APK |
| 202 | if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) { |
| 203 | def pkgTask = project.tasks.findByPath('packageDebugAndroidTest') |
| 204 | copy { |
| 205 | from(pkgTask.outputFile) |
| 206 | into(rootProject.ext.testApkDistOut) |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | } |
Yigit Boyar | ea5d9b2 | 2016-03-08 13:25:26 -0800 | [diff] [blame] | 212 | |
| 213 | project.afterEvaluate { p -> |
| 214 | // remove dependency on the test so that we still get coverage even if some tests fail |
| 215 | p.tasks.findAll { it instanceof JacocoReportTask}.each { task -> |
| 216 | def toBeRemoved = new ArrayList() |
| 217 | def dependencyList = task.taskDependencies.values |
| 218 | dependencyList.each { dep -> |
| 219 | if (dep instanceof String) { |
| 220 | def t = tasks.findByName(dep) |
| 221 | if (t instanceof DeviceProviderInstrumentTestTask) { |
| 222 | toBeRemoved.add(dep) |
| 223 | task.mustRunAfter(t) |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | toBeRemoved.each { dep -> |
| 228 | dependencyList.remove(dep) |
| 229 | } |
| 230 | } |
| 231 | } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 232 | } |
| 233 | |
Chris Banes | 9ae4ee8 | 2015-09-11 10:32:15 +1000 | [diff] [blame] | 234 | project.gradle.buildFinished { buildResult -> |
| 235 | if (buildResult.getFailure() != null) { |
| 236 | println() |
| 237 | println 'Build failed. Possible causes include:' |
| 238 | println ' 1) Bad codes' |
| 239 | println ' 2) Out of date prebuilts in prebuilts/sdk' |
Chris Banes | 9e2e803 | 2015-09-16 10:15:37 +0100 | [diff] [blame] | 240 | 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] | 241 | println() |
| 242 | } |
| 243 | } |
| 244 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 245 | FileCollection getAndroidPrebuilt(String apiLevel) { |
| 246 | files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar") |
Tor Norbye | 47c59fb | 2015-04-08 14:42:16 -0700 | [diff] [blame] | 247 | } |