Yigit Boyar | d6ddc64 | 2015-09-11 12:59:40 -0700 | [diff] [blame] | 1 | buildscript { |
| 2 | ext.addRepos(repositories) |
| 3 | dependencies { |
| 4 | classpath 'com.google.guava:guava:18.0' |
| 5 | } |
| 6 | } |
| 7 | import com.google.common.io.Files |
| 8 | import com.google.common.base.Charsets |
| 9 | import com.google.common.hash.HashCode |
| 10 | import com.google.common.hash.HashFunction |
| 11 | import com.google.common.hash.Hashing |
| 12 | import java.nio.charset.Charset |
| 13 | |
| 14 | |
Yigit Boyar | eae7e68 | 2015-10-05 15:47:35 -0700 | [diff] [blame] | 15 | ext.extraVersion = 22 |
Yigit Boyar | d6ddc64 | 2015-09-11 12:59:40 -0700 | [diff] [blame] | 16 | ext.supportRepoOut = '' |
| 17 | ext.buildToolsVersion = '22.1.0' |
| 18 | ext.buildNumber = Integer.toString(ext.extraVersion) |
| 19 | |
| 20 | /* |
| 21 | * With the build server you are given two env variables. |
| 22 | * The OUT_DIR is a temporary directory you can use to put things during the build. |
| 23 | * The DIST_DIR is where you want to save things from the build. |
| 24 | * |
| 25 | * The build server will copy the contents of DIST_DIR to somewhere and make it available. |
| 26 | */ |
| 27 | if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) { |
| 28 | buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile() |
| 29 | project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile() |
| 30 | |
| 31 | // the build server does not pass the build number so we infer it from the last folder of the dist path. |
| 32 | ext.buildNumber = project.ext.distDir.getName() |
| 33 | } else { |
| 34 | buildDir = file('../../out/host/gradle/frameworks/support/build') |
| 35 | project.ext.distDir = file('../../out/dist') |
| 36 | } |
| 37 | project.ext.distDir.mkdirs() |
Yigit Boyar | d6ddc64 | 2015-09-11 12:59:40 -0700 | [diff] [blame] | 38 | ext.supportRepoOut = new File(buildDir, 'support_repo') |
| 39 | |
| 40 | // Main task called by the build server. |
| 41 | task(createArchive) << { |
| 42 | } |
Yigit Boyar | d437f7e | 2015-10-30 16:28:34 -0700 | [diff] [blame] | 43 | createArchive.doLast { |
| 44 | println "support repo out ${project.ext.supportRepoOut}" |
| 45 | println "dist dir ${project.ext.distDir}" |
Yigit Boyar | d6ddc64 | 2015-09-11 12:59:40 -0700 | [diff] [blame] | 46 | |
Yigit Boyar | d437f7e | 2015-10-30 16:28:34 -0700 | [diff] [blame] | 47 | } |
Yigit Boyar | d6ddc64 | 2015-09-11 12:59:40 -0700 | [diff] [blame] | 48 | |
| 49 | // upload anchor for subprojects to upload their artifacts |
| 50 | // to the local repo. |
| 51 | task(mainUpload) << { |
| 52 | } |
| 53 | |
| 54 | // repository creation task |
| 55 | task createRepository(type: Zip, dependsOn: mainUpload) { |
| 56 | from project.ext.supportRepoOut |
| 57 | destinationDir project.ext.distDir |
| 58 | into 'm2repository' |
| 59 | baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber) |
| 60 | } |
| 61 | createArchive.dependsOn createRepository |
Yigit Boyar | d6ddc64 | 2015-09-11 12:59:40 -0700 | [diff] [blame] | 62 | // prepare repository with older versions |
| 63 | task unzipRepo(type: Copy) { |
Yigit Boyar | d437f7e | 2015-10-30 16:28:34 -0700 | [diff] [blame] | 64 | from "${dataBindingConfig.externalPrebuiltsBase}/maven_repo/android" |
Yigit Boyar | d6ddc64 | 2015-09-11 12:59:40 -0700 | [diff] [blame] | 65 | into project.ext.supportRepoOut |
| 66 | } |
| 67 | |
| 68 | unzipRepo.doFirst { |
| 69 | project.ext.supportRepoOut.deleteDir() |
| 70 | project.ext.supportRepoOut.mkdirs() |
| 71 | } |
| 72 | |
| 73 | // anchor for prepare repo. This is post unzip + sourceProp. |
| 74 | task(prepareRepo) << { |
| 75 | } |
| 76 | |
| 77 | task(createXml) << { |
| 78 | def repoArchive = createRepository.archivePath |
| 79 | def repoArchiveName = createRepository.archiveName |
| 80 | def size = repoArchive.length() |
| 81 | def sha1 = getSha1(repoArchive) |
| 82 | |
| 83 | def xml = |
| 84 | "<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\ |
| 85 | <sdk:extra>\n\ |
| 86 | <sdk:revision>\n\ |
| 87 | <sdk:major>${project.ext.extraVersion}</sdk:major>\n\ |
| 88 | </sdk:revision>\n\ |
| 89 | <sdk:vendor-display>Android</sdk:vendor-display>\n\ |
| 90 | <sdk:vendor-id>android</sdk:vendor-id>\n\ |
| 91 | <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\ |
| 92 | <sdk:path>m2repository</sdk:path>\n\ |
| 93 | <sdk:archives>\n\ |
| 94 | <sdk:archive>\n\ |
| 95 | <sdk:size>${size}</sdk:size>\n\ |
| 96 | <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\ |
| 97 | <sdk:url>${repoArchiveName}</sdk:url>\n\ |
| 98 | </sdk:archive>\n\ |
| 99 | </sdk:archives>\n\ |
| 100 | </sdk:extra>\n\ |
| 101 | </sdk:sdk-addon>" |
| 102 | |
| 103 | Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8) |
| 104 | } |
| 105 | createArchive.dependsOn createXml |
| 106 | |
| 107 | task(createSourceProp) << { |
| 108 | def sourceProp = |
| 109 | "Extra.VendorDisplay=Android\n\ |
| 110 | Extra.Path=m2repository\n\ |
| 111 | Archive.Arch=ANY\n\ |
| 112 | Extra.NameDisplay=Android Support Repository\n\ |
| 113 | Archive.Os=ANY\n\ |
| 114 | Pkg.Revision=${project.ext.extraVersion}.0.0\n\ |
| 115 | Extra.VendorId=android" |
Yigit Boyar | d6ddc64 | 2015-09-11 12:59:40 -0700 | [diff] [blame] | 116 | Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8) |
| 117 | } |
| 118 | createSourceProp.dependsOn unzipRepo |
| 119 | prepareRepo.dependsOn createSourceProp |
| 120 | |
| 121 | |
| 122 | def getSha1(File inputFile) { |
| 123 | HashFunction hashFunction = Hashing.sha1() |
| 124 | HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8")) |
| 125 | return hashCode.toString() |
| 126 | } |
| 127 | |
| 128 | task(bundleSupportLib) << { |
| 129 | |
| 130 | } |
Yigit Boyar | a3a7732 | 2015-10-05 17:05:08 -0700 | [diff] [blame] | 131 | createRepository.dependsOn prepareRepo |
Yigit Boyar | d6ddc64 | 2015-09-11 12:59:40 -0700 | [diff] [blame] | 132 | createRepository.dependsOn unzipRepo |
Yigit Boyar | d437f7e | 2015-10-30 16:28:34 -0700 | [diff] [blame] | 133 | createRepository.dependsOn bundleSupportLib |