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 String getFullSdkPath(String prebuiltsRoot) {
     18     final String osName = System.getProperty("os.name").toLowerCase()
     19     final boolean isMacOsX =
     20             osName.contains("mac os x") || osName.contains("darwin") || osName.contains("osx");
     21     final String platform = isMacOsX ? 'darwin' : 'linux'
     22     return "${prebuiltsRoot}/fullsdk-${platform}"
     23 }
     24 
     25 def supportRoot = ext.supportRootFolder
     26 if (supportRoot == null) {
     27     throw new RuntimeException("variable supportRootFolder is not set. you must set it before" +
     28             " including this script")
     29 }
     30 
     31 apply from: "${supportRoot}/buildSrc/unbundled_check.gradle"
     32 
     33 def checkoutRoot = "${ext.supportRootFolder}/../.."
     34 ext.repos = new Properties()
     35 ext.repos.prebuiltsRoot = "${checkoutRoot}/prebuilts"
     36 ext.repos.prebuiltsRootUri = "file://${repos.prebuiltsRoot}"
     37 
     38 ext.repoNames = [// Android Gradle Plugin prebuilts updated manually
     39                  "${repos.prebuiltsRoot}/gradle-plugin",
     40                  // Miscellaneous prebuilts updated sporadically
     41                  "${repos.prebuiltsRoot}/tools/common/m2/repository",
     42                  // Historical releases updated as part of public release
     43                  "${repos.prebuiltsRoot}/maven_repo/android",
     44                  "${repos.prebuiltsRoot}/maven_repo/google-play-service-client-libraries-3p",
     45                  // Manually constructed, but soon to be updated by update_current.py
     46                  "${repos.prebuiltsRoot}/sdk/current/extras/material-design",
     47                  // Full checkout prebuilts updated by update_current.py
     48                  "${repos.prebuiltsRoot}/sdk/current/support/m2repository",
     49                  // Unbundled checkout prebuilts updated by fullsdk drop
     50                  "${getFullSdkPath(repos.prebuiltsRoot)}/extras/android/m2repository",
     51                  // temporary: com.android.support.constraint:constraint-layout:1.0.2 is there
     52                  "${getFullSdkPath(repos.prebuiltsRoot)}/extras/m2repository/"]
     53 
     54 /**
     55  * Adds maven repositories to the given repository handler.
     56  */
     57 def addMavenRepositories(RepositoryHandler handler) {
     58     repoNames.each { repo ->
     59         handler.maven {
     60             url repo
     61         }
     62     }
     63     if (System.getenv("ALLOW_PUBLIC_REPOS") != null || (isUnbundledBuild(ext.supportRootFolder))) {
     64         handler.mavenCentral()
     65         handler.jcenter()
     66         handler.google()
     67         handler.maven {
     68             url "https://plugins.gradle.org/m2/"
     69         }
     70     }
     71     def androidPluginRepoOverride = System.getenv("GRADLE_PLUGIN_REPO")
     72     if (androidPluginRepoOverride != null) {
     73         handler.maven {
     74             url androidPluginRepoOverride
     75         }
     76     }
     77 }
     78 
     79 ext.repos.addMavenRepositories = this.&addMavenRepositories
     80