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