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
17def supportRootFolder = ext.supportRootFolder
18if (supportRootFolder == null) {
19    throw new RuntimeException("Canonical root project directory is not set. You must specify " +
20            "ext.supportRootFolder before including this script")
21}
22// Makes strong assumptions about the project structure.
23def checkoutRoot = supportRootFolder.parentFile.parentFile
24
25ext.repos = new Properties()
26ext.repos.checkoutRoot = checkoutRoot.absolutePath
27ext.repos.prebuiltsRoot = new File(checkoutRoot, "prebuilts").absolutePath
28
29/**
30 * Adds maven repositories to the given repository handler.
31 */
32def addMavenRepositories(RepositoryHandler handler) {
33    def metalavaRepoOverride = System.getenv("METALAVA_REPO")
34    if (metalavaRepoOverride != null) {
35        for(extraRepo in metalavaRepoOverride.split(File.pathSeparator)) {
36            handler.maven {
37                url = extraRepo
38            }
39        }
40    }
41    handler.maven {
42        url = "${repos.prebuiltsRoot}/androidx/internal"
43        metadataSources {
44            mavenPom()
45            artifact()
46        }
47        content {
48            includeGroupByRegex "android.*"
49            includeGroupByRegex "com.android.support.*"
50            excludeGroupByRegex "androidx.databinding.*"
51        }
52    }
53    handler.maven {
54        url = "${repos.prebuiltsRoot}/androidx/external"
55        metadataSources {
56            mavenPom()
57            artifact()
58        }
59        if (metalavaRepoOverride != null) {
60            // When using custom metalava repo, do not resolve metalava artifacts from this repo
61            content {
62                excludeGroup "com.android.tools.metalava"
63            }
64        }
65    }
66    if (System.getenv("ALLOW_PUBLIC_REPOS") != null || System.getProperty("ALLOW_PUBLIC_REPOS") != null) {
67        handler.mavenCentral()
68        handler.google {
69            content {
70                includeGroupByRegex("androidx.*")
71                includeGroupByRegex("com\\.android.*")
72                includeGroupByRegex("com\\.google.*")
73            }
74        }
75        handler.gradlePluginPortal()
76        handler.maven {
77               url = "https://maven.pkg.jetbrains.space/public/p/compose/dev"
78        }
79        handler.maven {
80            url = "https://packages.jetbrains.team/maven/p/kt/dev"
81            content {
82                includeGroupByRegex("org\\.jetbrains\\.kotlin.*")
83            }
84        }
85        handler.mavenLocal()
86    }
87    // Ordering appears to be important: b/229733266
88    def androidPluginRepoOverride = System.getenv("GRADLE_PLUGIN_REPO")
89    if (androidPluginRepoOverride != null) {
90        for(extraRepo in androidPluginRepoOverride.split(File.pathSeparator)) {
91            handler.maven {
92                url = extraRepo
93            }
94        }
95    }
96}
97
98ext.repos.addMavenRepositories = this.&addMavenRepositories
99