1
+ /*
2
+ * Copyright Careem, an Uber Technologies Inc. company
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
+ // Copies main project Gradle properties to sample project. Can't use buildSrc because settings.gradle
18
+ // must access these properties.
19
+
20
+ List<String > propertiesFiles = [
21
+ " ../gradle.properties" ,
22
+ " ../local.properties" ,
23
+ ]
24
+
25
+ propertiesFiles. each { fileName ->
26
+ File file = file(fileName)
27
+ if (file. exists()) {
28
+ Properties properties = new Properties ()
29
+ file. withInputStream { properties. load(it) }
30
+
31
+ int moduleNameStartIndex = fileName. indexOf(' /' ) + 1
32
+ int moduleNameEndIndex = fileName. lastIndexOf(' /' )
33
+ String namespace
34
+ if (moduleNameStartIndex < moduleNameEndIndex) {
35
+ namespace = fileName. substring(moduleNameStartIndex, moduleNameEndIndex)
36
+ .replace(' /' , ' .' )
37
+ } else {
38
+ namespace = null
39
+ }
40
+
41
+ properties. each { key , value ->
42
+ String namespacedKey
43
+ if (namespace == null ) {
44
+ namespacedKey = key
45
+ } else {
46
+ namespacedKey = " $namespace . $key "
47
+ }
48
+ try {
49
+ properties. set(namespacedKey, value)
50
+ } catch (MissingMethodException ignored) {
51
+ // We are in a pluginManagement block that can't set properties, so set an extra instead:
52
+ ext. set(namespacedKey, value)
53
+ }
54
+ }
55
+ }
56
+
57
+ }
0 commit comments