Yigit Boyar | 88c16ce | 2017-02-08 16:06:14 -0800 | [diff] [blame] | 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 | */ |
| 16 | import com.google.common.base.Charsets |
| 17 | import com.google.common.io.Files |
| 18 | import com.google.common.hash.HashCode |
| 19 | import com.google.common.hash.HashFunction |
| 20 | import com.google.common.hash.Hashing |
| 21 | import java.nio.charset.Charset |
| 22 | |
| 23 | // Main task called by the build server. |
| 24 | task(createArchive) |
| 25 | |
| 26 | // upload anchor for subprojects to upload their artifacts |
| 27 | // to the local repo. |
| 28 | task(mainUpload) |
| 29 | |
Yigit Boyar | 78e026c | 2017-03-06 16:19:15 -0800 | [diff] [blame] | 30 | rootProject.ext.repoWithHistoryOut = new File(buildDir, 'support_repo_with_history') |
| 31 | |
Yigit Boyar | 88c16ce | 2017-02-08 16:06:14 -0800 | [diff] [blame] | 32 | // repository creation task |
| 33 | task createRepository(type: Zip, dependsOn: mainUpload) { |
Yigit Boyar | 78e026c | 2017-03-06 16:19:15 -0800 | [diff] [blame] | 34 | from rootProject.ext.supportRepoOut |
Aurimas Liutikas | 9ab3b4c | 2017-04-19 09:33:27 -0700 | [diff] [blame] | 35 | from "${repos.prebuiltsRoot}/maven_repo/android" |
Yigit Boyar | 78e026c | 2017-03-06 16:19:15 -0800 | [diff] [blame] | 36 | // if there are duplicates, pick the first one. |
| 37 | duplicatesStrategy "EXCLUDE" |
Yigit Boyar | 88c16ce | 2017-02-08 16:06:14 -0800 | [diff] [blame] | 38 | destinationDir project.ext.distDir |
| 39 | into 'm2repository' |
| 40 | baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber) |
| 41 | } |
Yigit Boyar | 78e026c | 2017-03-06 16:19:15 -0800 | [diff] [blame] | 42 | |
| 43 | task 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 Boyar | 88c16ce | 2017-02-08 16:06:14 -0800 | [diff] [blame] | 53 | createArchive.dependsOn createRepository |
Yigit Boyar | 78e026c | 2017-03-06 16:19:15 -0800 | [diff] [blame] | 54 | createRepository.dependsOn createTopOfTreeRepository |
Yigit Boyar | 88c16ce | 2017-02-08 16:06:14 -0800 | [diff] [blame] | 55 | |
| 56 | // anchor for prepare repo. This is post unzip + sourceProp. |
Yigit Boyar | 78e026c | 2017-03-06 16:19:15 -0800 | [diff] [blame] | 57 | task 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 Boyar | 88c16ce | 2017-02-08 16:06:14 -0800 | [diff] [blame] | 66 | task(prepareRepo) |
| 67 | |
| 68 | task(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 | }) |
| 96 | createArchive.dependsOn createXml |
| 97 | createXml.dependsOn createRepository |
| 98 | |
| 99 | task(createSourceProp).doLast({ |
| 100 | def sourceProp = |
| 101 | "Extra.VendorDisplay=Android\n\ |
| 102 | Extra.Path=m2repository\n\ |
| 103 | Archive.Arch=ANY\n\ |
| 104 | Extra.NameDisplay=Android Support Repository\n\ |
| 105 | Archive.Os=ANY\n\ |
| 106 | Pkg.Desc=Local Maven repository for Support Libraries\n\ |
| 107 | Pkg.Revision=${project.ext.extraVersion}.0.0\n\ |
| 108 | Extra.VendorId=android" |
| 109 | |
| 110 | Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8) |
| 111 | }) |
Yigit Boyar | 78e026c | 2017-03-06 16:19:15 -0800 | [diff] [blame] | 112 | createSourceProp.dependsOn nukeRepoOut |
Yigit Boyar | 88c16ce | 2017-02-08 16:06:14 -0800 | [diff] [blame] | 113 | prepareRepo.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 | */ |
| 121 | String getSha1(File inputFile) { |
| 122 | HashFunction hashFunction = Hashing.sha1() |
| 123 | HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8")) |
| 124 | return hashCode.toString() |
Yigit Boyar | 78e026c | 2017-03-06 16:19:15 -0800 | [diff] [blame] | 125 | } |