forked from gdutxiaoxu/AnchorTask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
localconfig.gradle
53 lines (47 loc) · 1.54 KB
/
localconfig.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
task test22{
parseLocalProperties()
}
Properties loadProperties(String fileName) {
File file = rootProject.file(fileName)
println("parseLocalProperties start")
if (file.exists()) {
InputStream inputStream = rootProject.file(fileName).newDataInputStream();
Properties properties = new Properties()
properties.load(inputStream)
return properties
}
return null
}
def parseLocalProperties() {
File file = rootProject.file('local.properties')
println("parseLocalProperties start")
if (file.exists()) {
InputStream inputStream = rootProject.file('local.properties').newDataInputStream();
Properties properties = new Properties()
properties.load(inputStream)
def containsKey = properties.containsKey("packagename")
println("parseLocalProperties containsKey is ${containsKey}")
if (containsKey) {
println 'packageName:' + properties.getProperty("packagename")
ext.packagename = properties.getProperty("packagename")
println 'packageName:' + project["packagename"]
}
}
}
// 设置属性
def static getValue(Properties properties, String name, Object defValue) {
if (properties == null) {
return defValue
}
if (properties.containsKey(name)) {
String value = properties.getProperty(name)
return value
}
return defValue
}
// 方法复用
ext {
parseLocalProperties = this.&parseLocalProperties
loadProperties = this.&loadProperties
getValue = this.&getValue
}