• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import com.google.common.base.Charsets
17import com.google.common.io.Files
18import com.google.common.hash.HashCode
19import com.google.common.hash.HashFunction
20import com.google.common.hash.Hashing
21import java.nio.charset.Charset
22
23// Main task called by the build server.
24task(createArchive)
25
26// upload anchor for subprojects to upload their artifacts
27// to the local repo.
28task(mainUpload)
29
30rootProject.ext.repoWithHistoryOut = new File(buildDir, 'support_repo_with_history')
31
32// repository creation task
33task createRepository(type: Zip, dependsOn: mainUpload) {
34    from rootProject.ext.supportRepoOut
35    from "${repos.prebuiltsRoot}/maven_repo/android"
36    // if there are duplicates, pick the first one.
37    duplicatesStrategy "EXCLUDE"
38    destinationDir project.ext.distDir
39    into 'm2repository'
40    baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber)
41}
42
43task createTopOfTreeRepository(type : Zip) {
44    description "Creates a maven repository that includes just the libraries compiled in this" +
45            " project, without any history from prebuilts."
46    from rootProject.ext.supportRepoOut
47    destinationDir rootProject.ext.distDir
48    into 'm2repository'
49    baseName = String.format("top-of-tree-m2repository-%s", project.ext.buildNumber)
50    dependsOn mainUpload
51}
52
53createArchive.dependsOn createRepository
54createRepository.dependsOn createTopOfTreeRepository
55
56// anchor for prepare repo. This is post unzip + sourceProp.
57task nukeRepoOut() {
58    description "This task clears the repo folder to ensure that we run a fresh build every" +
59            " time we create arhives. Otherwise, snapshots will accumulate in the builds folder."
60    doFirst {
61        rootProject.ext.supportRepoOut.deleteDir()
62        rootProject.ext.supportRepoOut.mkdirs()
63    }
64}
65
66task(prepareRepo)
67
68task(createXml).doLast({
69    def repoArchive = createRepository.archivePath
70    def repoArchiveName = createRepository.archiveName
71    def size = repoArchive.length()
72    def sha1 = getSha1(repoArchive)
73
74    def xml =
75            "<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\
76  <sdk:extra>\n\
77    <sdk:revision>\n\
78      <sdk:major>${project.ext.extraVersion}</sdk:major>\n\
79    </sdk:revision>\n\
80    <sdk:vendor-display>Android</sdk:vendor-display>\n\
81    <sdk:vendor-id>android</sdk:vendor-id>\n\
82    <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\
83    <sdk:path>m2repository</sdk:path>\n\
84    <sdk:archives>\n\
85      <sdk:archive>\n\
86       <sdk:size>${size}</sdk:size>\n\
87       <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\
88       <sdk:url>${repoArchiveName}</sdk:url>\n\
89      </sdk:archive>\n\
90    </sdk:archives>\n\
91  </sdk:extra>\n\
92</sdk:sdk-addon>"
93
94    Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8)
95})
96createArchive.dependsOn createXml
97createXml.dependsOn createRepository
98
99task(createSourceProp).doLast({
100    def sourceProp =
101            "Extra.VendorDisplay=Android\n\
102Extra.Path=m2repository\n\
103Archive.Arch=ANY\n\
104Extra.NameDisplay=Android Support Repository\n\
105Archive.Os=ANY\n\
106Pkg.Desc=Local Maven repository for Support Libraries\n\
107Pkg.Revision=${project.ext.extraVersion}.0.0\n\
108Extra.VendorId=android"
109
110    Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
111})
112createSourceProp.dependsOn nukeRepoOut
113prepareRepo.dependsOn createSourceProp
114
115/**
116 * Generates SHA1 hash for the specified file's absolute path.
117 *
118 * @param inputFile file to hash
119 * @return SHA1 hash
120 */
121String getSha1(File inputFile) {
122    HashFunction hashFunction = Hashing.sha1()
123    HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8"))
124    return hashCode.toString()
125}
126