• 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 */
16// upload anchor for subprojects to upload their artifacts to the local repo.
17task(mainUpload)
18
19task createArchive(type : Zip) {
20    description "Creates a maven repository that includes just the libraries compiled in this" +
21            " project, without any history from prebuilts."
22    from rootProject.ext.supportRepoOut
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
29task 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        }
68    }
69    from rootProject.ext.supportRepoOut
70    destinationDir rootProject.ext.distDir
71    into 'm2repository'
72    baseName = String.format("gmaven-diff-top-of-tree-m2repository-%s", project.ext.buildNumber)
73    dependsOn mainUpload
74}
75
76// anchor for prepare repo. This is post unzip.
77task prepareRepo() {
78    description "This task clears the repo folder to ensure that we run a fresh build every" +
79            " time we create arhives. Otherwise, snapshots will accumulate in the builds folder."
80    doFirst {
81        rootProject.ext.supportRepoOut.deleteDir()
82        rootProject.ext.supportRepoOut.mkdirs()
83    }
84}
85