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 | */ |
Aurimas Liutikas | 76542da | 2017-06-29 17:00:29 -0700 | [diff] [blame] | 16 | // upload anchor for subprojects to upload their artifacts to the local repo. |
Yigit Boyar | 88c16ce | 2017-02-08 16:06:14 -0800 | [diff] [blame] | 17 | task(mainUpload) |
| 18 | |
Aurimas Liutikas | 76542da | 2017-06-29 17:00:29 -0700 | [diff] [blame] | 19 | task createArchive(type : Zip) { |
Yigit Boyar | 78e026c | 2017-03-06 16:19:15 -0800 | [diff] [blame] | 20 | description "Creates a maven repository that includes just the libraries compiled in this" + |
| 21 | " project, without any history from prebuilts." |
Aurimas Liutikas | 279780d | 2017-08-09 14:03:59 -0700 | [diff] [blame] | 22 | from rootProject.ext.supportRepoOut |
Yigit Boyar | 78e026c | 2017-03-06 16:19:15 -0800 | [diff] [blame] | 23 | destinationDir rootProject.ext.distDir |
| 24 | into 'm2repository' |
| 25 | baseName = String.format("top-of-tree-m2repository-%s", project.ext.buildNumber) |
| 26 | dependsOn mainUpload |
| 27 | } |
| 28 | |
Yigit Boyar | a9ac19d | 2017-09-20 16:11:49 -0700 | [diff] [blame] | 29 | task createDiffArchive(type : Zip) { |
| 30 | description "Creates a maven repository that includes just the libraries compiled in this" + |
| 31 | " project without any libraries that are already on maven.google.com. If you need " + |
| 32 | " a full repo, use createArchive task." |
| 33 | dependsOn mainUpload |
| 34 | /** |
| 35 | * building filters in a doFirst block so that we can query the output of other tasks and also |
| 36 | * not query maven.google unless task runs. |
| 37 | */ |
| 38 | doFirst { |
| 39 | def includeFilters = subprojects.collect { it.tasks.withType(Upload) }.findResults { |
| 40 | def group = it.project.group[0] |
| 41 | def archiveName = it.project.name[0] |
| 42 | def version = it.project.version[0] |
| 43 | if (group == null || archiveName == null || version == null) { |
| 44 | logger.info "null artifact info for ${it.project.path}" |
| 45 | return null |
| 46 | } |
| 47 | def subFolder = group.replace('.', '/') + "/" + archiveName + "/" + version |
| 48 | def localFolder = new File(rootProject.ext.supportRepoOut, subFolder) |
| 49 | if (!localFolder.exists()) { |
| 50 | // no reason to check, not even built |
| 51 | logger.info "skipping $subFolder because it does not exist" |
| 52 | return null |
| 53 | } |
| 54 | // query maven.google to check if it is released. |
| 55 | if (rootProject.ext.versionChecker.isReleased(group, archiveName, version)) { |
| 56 | logger.info "looks like $subFolder is released, skipping" |
| 57 | return null |
| 58 | } else { |
| 59 | logger.info "adding $subFolder to partial maven zip because it cannot be found on" + |
| 60 | " maven.google.com" |
| 61 | } |
| 62 | return subFolder + "/**" |
| 63 | } |
| 64 | logger.info "include filters for diff maven zip ${includeFilters}" |
| 65 | includeFilters.forEach { |
| 66 | include it |
| 67 | } |
Yigit Boyar | f250564 | 2017-10-27 13:56:02 -0700 | [diff] [blame] | 68 | if (includeFilters.isEmpty()) { |
| 69 | // not providing any include would mean include everything so we provide a dummy |
| 70 | // include constraint. |
| 71 | include "do-not-include-anything" |
| 72 | } |
Yigit Boyar | a9ac19d | 2017-09-20 16:11:49 -0700 | [diff] [blame] | 73 | } |
| 74 | from rootProject.ext.supportRepoOut |
| 75 | destinationDir rootProject.ext.distDir |
| 76 | into 'm2repository' |
| 77 | baseName = String.format("gmaven-diff-top-of-tree-m2repository-%s", project.ext.buildNumber) |
| 78 | dependsOn mainUpload |
| 79 | } |
| 80 | |
Aurimas Liutikas | 76542da | 2017-06-29 17:00:29 -0700 | [diff] [blame] | 81 | // anchor for prepare repo. This is post unzip. |
| 82 | task prepareRepo() { |
Yigit Boyar | 78e026c | 2017-03-06 16:19:15 -0800 | [diff] [blame] | 83 | description "This task clears the repo folder to ensure that we run a fresh build every" + |
| 84 | " time we create arhives. Otherwise, snapshots will accumulate in the builds folder." |
| 85 | doFirst { |
| 86 | rootProject.ext.supportRepoOut.deleteDir() |
| 87 | rootProject.ext.supportRepoOut.mkdirs() |
| 88 | } |
| 89 | } |