• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1buildscript {
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 {
8        classpath 'com.android.tools.build:gradle:0.10.0'
9    }
10}
11
12ext.supportVersion = '21.0.0'
13ext.extraVersion = 7
14ext.supportRepoOut = ''
15ext.buildToolsVersion = '19.0.3'
16
17/*
18 * With the build server you are given two env variables.
19 * The OUT_DIR is a temporary directory you can use to put things during the build.
20 * The DIST_DIR is where you want to save things from the build.
21 *
22 * The build server will copy the contents of DIST_DIR to somewhere and make it available.
23 */
24if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
25    buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
26    project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
27} else {
28    buildDir = file('../../out/host/gradle/frameworks/support/build')
29    project.ext.distDir = file('../../out/dist')
30}
31
32ext.supportRepoOut = new File(buildDir, 'support_repo')
33
34// Main task called by the build server.
35task(createArchive) << {
36}
37
38
39// upload anchor for subprojects to upload their artifacts
40// to the local repo.
41task(mainUpload) << {
42}
43
44// repository creation task
45task createRepository(type: Zip, dependsOn: mainUpload) {
46    from project.ext.supportRepoOut
47    destinationDir project.ext.distDir
48    into 'm2repository'
49    baseName = String.format("android_m2repository_r%02d", project.ext.extraVersion)
50}
51createArchive.dependsOn createRepository
52
53// prepare repository with older versions
54task unzipRepo(type: Copy) {
55    from "$rootDir/../../prebuilts/maven_repo/android"
56    into project.ext.supportRepoOut
57}
58
59unzipRepo.doFirst {
60    project.ext.supportRepoOut.deleteDir()
61    project.ext.supportRepoOut.mkdirs()
62}
63
64// anchor for prepare repo. This is post unzip + sourceProp.
65task(prepareRepo) << {
66}
67
68import com.google.common.io.Files
69import com.google.common.base.Charsets
70
71task(createXml) << {
72    def repoArchive = createRepository.archivePath
73    def repoArchiveName = createRepository.archiveName
74    def size = repoArchive.length()
75    def sha1 = getSha1(repoArchive)
76
77    def xml =
78"<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\
79  <sdk:extra>\n\
80    <sdk:revision>\n\
81      <sdk:major>${project.ext.extraVersion}</sdk:major>\n\
82    </sdk:revision>\n\
83    <sdk:vendor-display>Android</sdk:vendor-display>\n\
84    <sdk:vendor-id>android</sdk:vendor-id>\n\
85    <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\
86    <sdk:path>m2repository</sdk:path>\n\
87    <sdk:archives>\n\
88      <sdk:archive os=\"any\" arch=\"any\">\n\
89       <sdk:size>${size}</sdk:size>\n\
90       <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\
91       <sdk:url>${repoArchiveName}</sdk:url>\n\
92      </sdk:archive>\n\
93    </sdk:archives>\n\
94  </sdk:extra>\n\
95</sdk:sdk-addon>"
96
97    Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8)
98}
99createArchive.dependsOn createXml
100
101task(createSourceProp) << {
102    def sourceProp =
103"Extra.VendorDisplay=Android\n\
104Extra.Path=m2repository\n\
105Archive.Arch=ANY\n\
106Extra.NameDisplay=Android Support Repository\n\
107Archive.Os=ANY\n\
108Pkg.Revision=${project.ext.extraVersion}.0.0\n\
109Extra.VendorId=android"
110
111    Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
112}
113createSourceProp.dependsOn unzipRepo
114prepareRepo.dependsOn createSourceProp
115
116
117import com.google.common.hash.HashCode
118import com.google.common.hash.HashFunction
119import com.google.common.hash.Hashing
120
121def getSha1(File inputFile) {
122    HashFunction hashFunction = Hashing.sha1()
123    HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath())
124    return hashCode.toString()
125}
126
127subprojects {
128    // Change buildDir first so that all plugins pick up the new value.
129    project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
130
131    apply plugin: 'maven'
132
133    version = rootProject.ext.supportVersion
134    group = 'com.android.support'
135
136    task release(type: Upload) {
137        configuration = configurations.archives
138        repositories {
139            mavenDeployer {
140                repository(url: uri("$rootProject.ext.supportRepoOut"))
141            }
142        }
143    }
144
145    // before the upload, make sure the repo is ready.
146    release.dependsOn rootProject.tasks.prepareRepo
147    // make the mainupload depend on this one.
148    mainUpload.dependsOn release
149
150    project.plugins.whenPluginAdded { plugin ->
151        if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
152            project.android.buildToolsVersion = rootProject.buildToolsVersion
153        }
154    }
155}
156
157FileCollection getAndroidPrebuilt(String apiLevel) {
158    files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar")
159}
160
161