Home | History | Annotate | Download | only in buildSrc
      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 
     17 import org.gradle.api.artifacts.dsl.RepositoryHandler;
     18 
     19 String getFullSdkPath(String prebuiltsRoot) {
     20     final String osName = System.getProperty("os.name").toLowerCase()
     21     final boolean isMacOsX =
     22             osName.contains("mac os x") || osName.contains("darwin") || osName.contains("osx");
     23     final String platform = isMacOsX ? 'darwin' : 'linux'
     24     return "${prebuiltsRoot}/fullsdk-${platform}"
     25 }
     26 
     27 def supportRoot = ext.supportRootFolder
     28 if (supportRoot == null) {
     29     throw new RuntimeException("variable supportRootFolder is not set. you must set it before" +
     30             " including this script")
     31 }
     32 
     33 def checkoutRoot = "${supportRoot}/../.."
     34 ext.repos = new Properties()
     35 ext.repos.prebuiltsRoot = "${checkoutRoot}/prebuilts"
     36 ext.repos.prebuiltsRootUri = "file://${repos.prebuiltsRoot}"
     37 
     38 ext.repoNames = ["${repos.prebuiltsRoot}/gradle-plugin",
     39                  "${repos.prebuiltsRoot}/tools/common/m2/repository",
     40                  "${repos.prebuiltsRoot}/tools/common/m2/internal",
     41                  "${repos.prebuiltsRoot}/maven_repo/android",
     42                  "${getFullSdkPath(repos.prebuiltsRoot)}/extras/m2repository"]
     43 
     44 /**
     45  * Adds maven repositories to the given repository handler.
     46  */
     47 def addMavenRepositories(RepositoryHandler handler) {
     48     repoNames.each { repo ->
     49         handler.maven {
     50             url repo
     51         }
     52     }
     53     if (System.getenv("ALLOW_PUBLIC_REPOS") != null) {
     54         handler.mavenCentral()
     55         handler.jcenter()
     56         handler.google()
     57     }
     58     def androidPluginRepoOverride = System.getenv("GRADLE_PLUGIN_REPO")
     59     if (androidPluginRepoOverride != null) {
     60         handler.maven {
     61             url androidPluginRepoOverride
     62         }
     63     }
     64 }
     65 
     66 ext.repos.addMavenRepositories = this.&addMavenRepositories