-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.gradle.kts
127 lines (108 loc) · 3.74 KB
/
settings.gradle.kts
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
pluginManagement {
repositories {
google {
content {
includeGroupByRegex("com\\.android.*")
includeGroupByRegex("com\\.google.*")
includeGroupByRegex("androidx.*")
}
}
mavenCentral()
gradlePluginPortal()
}
// ---------------------------------------------------------------------------------------------
// iToys plugin
// ---------------------------------------------------------------------------------------------
includeBuild("iToys-plugin")
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { setUrl("https://maven.aliyun.com/repository/public") }
maven { setUrl("https://jitpack.io") }
}
}
rootProject.name = "iToys-android-mini"
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
includeModules(":app", ":iToys-kit")
// -------------------------------------------------------------------------------------------------
// Tools (Modules)
// -------------------------------------------------------------------------------------------------
fun includeModules(vararg paths: String, with: (Module.() -> Unit)? = null) {
paths.forEach {
includeModule(it, with)
}
}
fun includeModule(path: String, with: (Module.() -> Unit)? = null) {
val moduleSpec = Module()
with?.invoke(moduleSpec)
val moduleDir = File(rootDir, path.replace(':', '/'))
if (moduleDir.exists()) {
include(path)
val module = project(path)
module.projectDir = moduleDir
val settingsFile = File(moduleDir, "settings.gradle")
if (settingsFile.exists()) {
apply {
from(settingsFile)
to(SettingsProxy(settings, module, moduleSpec))
}
}
moduleDir.walk().maxDepth(1).filter { it.isDirectory && it != moduleDir }.forEach {
val settingsFileInternal = File(it, "settings.gradle")
if (settingsFileInternal.exists()) {
val moduleInternal = settings.findProject("$path:${it.name}")
if (moduleInternal != null) {
moduleInternal.projectDir = it
apply {
from(settingsFileInternal)
to(SettingsProxy(settings, moduleInternal, moduleSpec))
}
}
}
}
}
}
class Module {
private val excludes = mutableListOf<String>()
private var filter: ((String) -> Boolean)? = null
fun exclude(vararg paths: String) {
excludes.addAll(paths)
}
fun accept(path: String): Boolean {
if (excludes.contains(path)) {
return false
}
if (filter?.invoke(path) == true) {
return false
}
return true
}
}
class SettingsProxy(
private var mSettings: Settings,
private var mModule: ProjectDescriptor,
private var mModuleSpec: Module,
) {
fun getRootProject(): ProjectDescriptor {
return mModule
}
fun include(vararg paths: String) {
paths.forEach {
if (mModuleSpec.accept(it.replace(":", ""))) {
val descendantPath = generateDescendantPath(it)
mSettings.include(descendantPath)
val descendantProjectDir = File(mModule.projectDir, it.replace(':', '/'))
mSettings.project(descendantPath).projectDir = descendantProjectDir
}
}
}
fun project(path: String): ProjectDescriptor {
return mSettings.project("${mModule.path}$path")
}
private fun generateDescendantPath(path: String): String {
return "${mModule.path}$path"
}
}