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 15 ext.extraVersion = 22 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() 38 ext.supportRepoOut = new File(buildDir, 'support_repo') 39 40 // Main task called by the build server. 41 task(createArchive) << { 42 } 43 createArchive.doLast { 44 println "support repo out ${project.ext.supportRepoOut}" 45 println "dist dir ${project.ext.distDir}" 46 47 } 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 62 // prepare repository with older versions 63 task unzipRepo(type: Copy) { 64 from "${dataBindingConfig.externalPrebuiltsBase}/maven_repo/android" 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" 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 } 131 createRepository.dependsOn prepareRepo 132 createRepository.dependsOn unzipRepo 133 createRepository.dependsOn bundleSupportLib 134