blob: d36487963768e4ba83de3d9fa3249cd066b4c649 [file] [log] [blame]
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -08001buildscript {
2 repositories {
3 maven { url '../../prebuilts/gradle-plugin' }
4 maven { url '../../prebuilts/tools/common/m2/repository' }
5 maven { url '../../prebuilts/tools/common/m2/internal' }
6 }
7 dependencies {
Chris Banes4efd0382015-03-05 20:04:05 +00008 classpath 'com.android.tools.build:gradle:1.1.0'
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -08009 }
10}
11
Xavier Ducrohet5a0d6872015-03-06 14:07:26 -080012ext.supportVersion = '22.0.0'
13ext.extraVersion = 12
Xavier Ducrohet020e4322014-03-18 16:41:30 -070014ext.supportRepoOut = ''
Chris Banes4efd0382015-03-05 20:04:05 +000015ext.buildToolsVersion = '21.0.0'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080016ext.buildNumber = Integer.toString(ext.extraVersion)
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080017
Xavier Ducrohet020e4322014-03-18 16:41:30 -070018/*
19 * With the build server you are given two env variables.
20 * The OUT_DIR is a temporary directory you can use to put things during the build.
21 * The DIST_DIR is where you want to save things from the build.
22 *
23 * The build server will copy the contents of DIST_DIR to somewhere and make it available.
24 */
25if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
Xavier Ducrohet4e04b7a2014-10-17 18:02:33 -070026 buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
27 project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
Xavier Ducrohetfa385272014-11-14 13:12:09 -080028
29 // the build server does not pass the build number so we infer it from the last folder of the dist path.
30 ext.buildNumber = project.ext.distDir.getName()
Xavier Ducrohet020e4322014-03-18 16:41:30 -070031} else {
32 buildDir = file('../../out/host/gradle/frameworks/support/build')
33 project.ext.distDir = file('../../out/dist')
34}
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080035
Xavier Ducrohet020e4322014-03-18 16:41:30 -070036ext.supportRepoOut = new File(buildDir, 'support_repo')
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080037
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070038// Main task called by the build server.
39task(createArchive) << {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070040}
41
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070042
43// upload anchor for subprojects to upload their artifacts
44// to the local repo.
45task(mainUpload) << {
46}
47
48// repository creation task
49task createRepository(type: Zip, dependsOn: mainUpload) {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070050 from project.ext.supportRepoOut
51 destinationDir project.ext.distDir
Xavier Ducrohet9dc44802014-03-20 14:15:16 -070052 into 'm2repository'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080053 baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber)
Xavier Ducrohet020e4322014-03-18 16:41:30 -070054}
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070055createArchive.dependsOn createRepository
Xavier Ducrohet020e4322014-03-18 16:41:30 -070056
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070057// prepare repository with older versions
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070058task unzipRepo(type: Copy) {
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080059 from "$rootDir/../../prebuilts/maven_repo/android"
Xavier Ducrohet855a9222014-01-02 19:00:43 -080060 into project.ext.supportRepoOut
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080061}
62
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070063unzipRepo.doFirst {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070064 project.ext.supportRepoOut.deleteDir()
65 project.ext.supportRepoOut.mkdirs()
66}
67
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070068// anchor for prepare repo. This is post unzip + sourceProp.
69task(prepareRepo) << {
70}
71
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070072import com.google.common.io.Files
73import com.google.common.base.Charsets
74
75task(createXml) << {
76 def repoArchive = createRepository.archivePath
77 def repoArchiveName = createRepository.archiveName
78 def size = repoArchive.length()
79 def sha1 = getSha1(repoArchive)
80
81 def xml =
82"<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\
83 <sdk:extra>\n\
84 <sdk:revision>\n\
85 <sdk:major>${project.ext.extraVersion}</sdk:major>\n\
86 </sdk:revision>\n\
87 <sdk:vendor-display>Android</sdk:vendor-display>\n\
88 <sdk:vendor-id>android</sdk:vendor-id>\n\
89 <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\
90 <sdk:path>m2repository</sdk:path>\n\
91 <sdk:archives>\n\
Xavier Ducrohetc16b62d2014-12-09 12:37:45 -080092 <sdk:archive>\n\
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070093 <sdk:size>${size}</sdk:size>\n\
94 <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\
95 <sdk:url>${repoArchiveName}</sdk:url>\n\
96 </sdk:archive>\n\
97 </sdk:archives>\n\
98 </sdk:extra>\n\
99</sdk:sdk-addon>"
100
101 Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8)
102}
103createArchive.dependsOn createXml
104
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700105task(createSourceProp) << {
106 def sourceProp =
107"Extra.VendorDisplay=Android\n\
108Extra.Path=m2repository\n\
109Archive.Arch=ANY\n\
110Extra.NameDisplay=Android Support Repository\n\
111Archive.Os=ANY\n\
112Pkg.Revision=${project.ext.extraVersion}.0.0\n\
113Extra.VendorId=android"
114
115 Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
116}
117createSourceProp.dependsOn unzipRepo
118prepareRepo.dependsOn createSourceProp
119
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700120
121import com.google.common.hash.HashCode
122import com.google.common.hash.HashFunction
123import com.google.common.hash.Hashing
Chris Banes4efd0382015-03-05 20:04:05 +0000124import java.nio.charset.Charset
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700125
126def getSha1(File inputFile) {
127 HashFunction hashFunction = Hashing.sha1()
Chris Banes4efd0382015-03-05 20:04:05 +0000128 HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8"))
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700129 return hashCode.toString()
130}
131
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800132subprojects {
133 // Change buildDir first so that all plugins pick up the new value.
Xavier Ducrohet616b95d2014-02-12 09:09:43 -0800134 project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800135
136 apply plugin: 'maven'
137
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800138 version = rootProject.ext.supportVersion
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800139 group = 'com.android.support'
140
141 task release(type: Upload) {
142 configuration = configurations.archives
143 repositories {
144 mavenDeployer {
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800145 repository(url: uri("$rootProject.ext.supportRepoOut"))
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800146 }
147 }
148 }
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700149
Xavier Ducrohete4cf5a92015-03-06 17:17:30 -0800150 def deployer = release.repositories.mavenDeployer
151 deployer.pom*.whenConfigured { pom ->
152 pom.dependencies.findAll {dep -> dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations' }*.type = 'aar'
153 }
154
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700155 // before the upload, make sure the repo is ready.
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700156 release.dependsOn rootProject.tasks.prepareRepo
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700157 // make the mainupload depend on this one.
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700158 mainUpload.dependsOn release
Jeff Davidson84faec52014-06-18 09:10:36 -0700159
160 project.plugins.whenPluginAdded { plugin ->
161 if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
162 project.android.buildToolsVersion = rootProject.buildToolsVersion
163 }
164 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800165}
166
167FileCollection getAndroidPrebuilt(String apiLevel) {
168 files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar")
169}
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800170