:fire: Android developers should collect the following utils(updating).
|
|
import groovy.json.JsonSlurper
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 在 module_config.json 中 根据 appConfig 和 pkgConfig 来 include 本地模块
|
||
|
|
* 可以考虑写成插件来更方便 apply
|
||
|
|
*/
|
||
|
|
|
||
|
|
def json = new JsonSlurper().parse(file("./module_config.json"))
|
||
|
|
|
||
|
|
for (def module in json.moduleConfig) {
|
||
|
|
String moduleName = module.name
|
||
|
|
|
||
|
|
if (moduleName == "feature_mock") {
|
||
|
|
if (json.pkgConfig.isEmpty()) {
|
||
|
|
module.isApply = false
|
||
|
|
}
|
||
|
|
} else if (moduleName.endsWith("_app")) {
|
||
|
|
if (!json.appConfig.contains(moduleName)) {
|
||
|
|
module.isApply = false
|
||
|
|
}
|
||
|
|
} else if (moduleName.endsWith("_pkg")) {
|
||
|
|
if (!json.pkgConfig.isEmpty()) {
|
||
|
|
if (!json.pkgConfig.contains(moduleName)) {
|
||
|
|
module.isApply = false
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (module.useLocal && module.isApply) {
|
||
|
|
include moduleName
|
||
|
|
project(":$moduleName").projectDir = file(module.localPath)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
def ls = System.getProperty("line.separator")
|
||
|
|
|
||
|
|
List<String> modules = []
|
||
|
|
for (def module in json.moduleConfig) {
|
||
|
|
String name = module.name
|
||
|
|
boolean isApply = module.isApply
|
||
|
|
boolean useLocal = module.useLocal
|
||
|
|
String localPath = module.localPath
|
||
|
|
String remotePath = module.remotePath
|
||
|
|
if (localPath != null) localPath = "\"$localPath\""
|
||
|
|
if (remotePath != null) remotePath = "\"$remotePath\""
|
||
|
|
modules.add(String.format("%-12s%-27s: new ModuleConfig(isApply: %-5s, useLocal: %-5s, localPath: $localPath%s),",
|
||
|
|
"", name, isApply, useLocal, remotePath == null ? "" : ", remotePath: $remotePath"))
|
||
|
|
}
|
||
|
|
|
||
|
|
def configFile = file('./buildSrc/src/main/groovy/Config.groovy')
|
||
|
|
def lines = configFile.readLines("utf8")
|
||
|
|
def configContent = new StringBuilder()
|
||
|
|
|
||
|
|
boolean enterNeverFlag = false
|
||
|
|
for (def line : lines) {
|
||
|
|
if (enterNeverFlag) {
|
||
|
|
if (line.contains("/*Don't delete this line*/")) {
|
||
|
|
configContent.append(ls).append(line)
|
||
|
|
enterNeverFlag = false
|
||
|
|
}
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
configContent.append(ls).append(line)
|
||
|
|
if (line.contains("/*Don't delete this line*/")) {
|
||
|
|
configContent.append(ls).append(String.format("%-12s/*Generated by \"module_config.json\"*/", ""))
|
||
|
|
enterNeverFlag = true
|
||
|
|
for (String m : modules) {
|
||
|
|
configContent.append(ls).append(m)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
configFile.write(configContent.substring(ls.length()).toString())
|