-
Notifications
You must be signed in to change notification settings - Fork 4
/
setting_parser.gradle
43 lines (36 loc) · 1.11 KB
/
setting_parser.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
/**
* author: qibin
*
* a simple lexer for parse settings.gradle
*/
ext {
settingsResult = new ArrayList<String>()
isProjectOpen = { projectPath ->
if (settingsResult.isEmpty()) { readSettings()}
def path = projectPath.replaceAll($//|\\/$, ":")
for (String item : settingsResult) {
if (path.endsWith(item)) { return true}
}
return false
}
readSettings = {
def settings = file("./settings.gradle")
def lines = settings.readLines()
def size = lines.size()
for (def i = 0; i < size; i++) {
def line = lines[i].replaceAll("(//.*)|(/\\*.*\\*/)", "")
if (!isEmptyLine(line)) {
line.split(",").each { item ->
item = item.replaceAll($/"|'/$, "")
.replaceAll($/\s*/$, "")
.replaceAll($/include/$, "")
settingsResult.add(item)
}
}
}
}
isEmptyLine = { line ->
if (line == null || line.length() == 0) { return true}
return false
}
}