Home | History | Annotate | Download | only in support
      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 
     12 ext.supportVersion = '21.0.3'
     13 ext.extraVersion = 10
     14 ext.supportRepoOut = ''
     15 ext.buildToolsVersion = '19.0.3'
     16 ext.buildNumber = Integer.toString(ext.extraVersion)
     17 
     18 /*
     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  */
     25 if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
     26     buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
     27     project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
     28 
     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()
     31 } else {
     32     buildDir = file('../../out/host/gradle/frameworks/support/build')
     33     project.ext.distDir = file('../../out/dist')
     34 }
     35 
     36 ext.supportRepoOut = new File(buildDir, 'support_repo')
     37 
     38 // Main task called by the build server.
     39 task(createArchive) << {
     40 }
     41 
     42 
     43 // upload anchor for subprojects to upload their artifacts
     44 // to the local repo.
     45 task(mainUpload) << {
     46 }
     47 
     48 // repository creation task
     49 task createRepository(type: Zip, dependsOn: mainUpload) {
     50     from project.ext.supportRepoOut
     51     destinationDir project.ext.distDir
     52     into 'm2repository'
     53     baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber)
     54 }
     55 createArchive.dependsOn createRepository
     56 
     57 // prepare repository with older versions
     58 task unzipRepo(type: Copy) {
     59     from "$rootDir/../../prebuilts/maven_repo/android"
     60     into project.ext.supportRepoOut
     61 }
     62 
     63 unzipRepo.doFirst {
     64     project.ext.supportRepoOut.deleteDir()
     65     project.ext.supportRepoOut.mkdirs()
     66 }
     67 
     68 // anchor for prepare repo. This is post unzip + sourceProp.
     69 task(prepareRepo) << {
     70 }
     71 
     72 import com.google.common.io.Files
     73 import com.google.common.base.Charsets
     74 
     75 task(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\
     92       <sdk:archive>\n\
     93        <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 }
    103 createArchive.dependsOn createXml
    104 
    105 task(createSourceProp) << {
    106     def sourceProp =
    107 "Extra.VendorDisplay=Android\n\
    108 Extra.Path=m2repository\n\
    109 Archive.Arch=ANY\n\
    110 Extra.NameDisplay=Android Support Repository\n\
    111 Archive.Os=ANY\n\
    112 Pkg.Revision=${project.ext.extraVersion}.0.0\n\
    113 Extra.VendorId=android"
    114 
    115     Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
    116 }
    117 createSourceProp.dependsOn unzipRepo
    118 prepareRepo.dependsOn createSourceProp
    119 
    120 
    121 import com.google.common.hash.HashCode
    122 import com.google.common.hash.HashFunction
    123 import com.google.common.hash.Hashing
    124 
    125 def getSha1(File inputFile) {
    126     HashFunction hashFunction = Hashing.sha1()
    127     HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath())
    128     return hashCode.toString()
    129 }
    130 
    131 subprojects {
    132     // Change buildDir first so that all plugins pick up the new value.
    133     project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
    134 
    135     apply plugin: 'maven'
    136 
    137     version = rootProject.ext.supportVersion
    138     group = 'com.android.support'
    139 
    140     task release(type: Upload) {
    141         configuration = configurations.archives
    142         repositories {
    143             mavenDeployer {
    144                 repository(url: uri("$rootProject.ext.supportRepoOut"))
    145             }
    146         }
    147     }
    148 
    149     // before the upload, make sure the repo is ready.
    150     release.dependsOn rootProject.tasks.prepareRepo
    151     // make the mainupload depend on this one.
    152     mainUpload.dependsOn release
    153 
    154     project.plugins.whenPluginAdded { plugin ->
    155         if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
    156             project.android.buildToolsVersion = rootProject.buildToolsVersion
    157         }
    158     }
    159 }
    160 
    161 FileCollection getAndroidPrebuilt(String apiLevel) {
    162     files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar")
    163 }
    164 
    165