blob: 5126d472a83354a900da8f6abd4fe04bb8dab15f [file] [log] [blame]
Yigit Boyar88c16ce2017-02-08 16:06:14 -08001/*
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
Yigit Boyar78e026c2017-03-06 16:19:15 -080030rootProject.ext.repoWithHistoryOut = new File(buildDir, 'support_repo_with_history')
31
Yigit Boyar88c16ce2017-02-08 16:06:14 -080032// repository creation task
33task createRepository(type: Zip, dependsOn: mainUpload) {
Yigit Boyar78e026c2017-03-06 16:19:15 -080034 from rootProject.ext.supportRepoOut
Aurimas Liutikas9ab3b4c2017-04-19 09:33:27 -070035 from "${repos.prebuiltsRoot}/maven_repo/android"
Yigit Boyar78e026c2017-03-06 16:19:15 -080036 // if there are duplicates, pick the first one.
37 duplicatesStrategy "EXCLUDE"
Yigit Boyar88c16ce2017-02-08 16:06:14 -080038 destinationDir project.ext.distDir
39 into 'm2repository'
40 baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber)
41}
Yigit Boyar78e026c2017-03-06 16:19:15 -080042
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
Yigit Boyar88c16ce2017-02-08 16:06:14 -080053createArchive.dependsOn createRepository
Yigit Boyar78e026c2017-03-06 16:19:15 -080054createRepository.dependsOn createTopOfTreeRepository
Yigit Boyar88c16ce2017-02-08 16:06:14 -080055
56// anchor for prepare repo. This is post unzip + sourceProp.
Yigit Boyar78e026c2017-03-06 16:19:15 -080057task 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
Yigit Boyar88c16ce2017-02-08 16:06:14 -080066task(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})
Yigit Boyar78e026c2017-03-06 16:19:15 -0800112createSourceProp.dependsOn nukeRepoOut
Yigit Boyar88c16ce2017-02-08 16:06:14 -0800113prepareRepo.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()
Yigit Boyar78e026c2017-03-06 16:19:15 -0800125}