apply from: rootDir.toString() + '/build_module.gradle'

System.err.println("MainProjectList: " + zixieMainProject)
System.err.println("DevProjectList: " + zixieDevelopModule)

if (zixieIsPublish) {
    if (zixieMainProject.contains(",") || zixieDevelopModule.contains(",") || !zixieMainProject.equals(zixieDevelopModule)) {
        throw new Exception("\n\n================== AAF 构建异常 ======================\n\n" +
                "当前为组件发布模式，此时会启动编译加速。\n" +
                "如需关闭发布模式，请将 dependencies.gradle 中 ext.isPublish 设为  false：\n" +
                "发布模式时：dependencies.gradle 中 ：\n" +
                "\t1. ext.mainProject 与 ext.developModule 必须一致  \n" +
                "\t2. ext.includeALLDependOnDevelopModule 必须为 false \n\n" +
                "================== AAF 构建异常 ======================\n\n"
        )
    }
}

zixieMainProject.split(",").each { projectName ->
    addInclude(projectName)
}

zixieDevelopModule.replaceAll("\\s*", "").split(",").each { projectName ->
    addInclude(projectName)
}


if (zixieIncludeALL) {
    zixieDepenciesList.each { projectName, subModuleList ->
        autoAddInclude(projectName)
    }
} else {
    zixieMainProject.split(",").each { projectName ->
        zixieDepenciesList[projectName].each { dependenciesModule ->
            autoAddInclude(dependenciesModule)
        }
    }
}

System.err.println("\n\n========================================\n\n")
System.err.println("当前工程导入组件如下：\n\n\t" + zixieIncludeList)
System.err.println("\n\n========================================\n\n")

def addInclude(projectName) {
    if (null == projectName || projectName.trim().length() == 0) {
        if (zixieIsDebug) System.out.println("Add Include: " + projectName + " is bad !")
    } else if (zixieIncludeList.contains(projectName)) {
        if (zixieIsDebug) System.out.println("Add Include: " + projectName + " has bad !")
    } else {
        String finalProjectName = ':' + projectName
        System.out.println("include " + finalProjectName)
        zixieIncludeList.add(projectName)
        include finalProjectName
    }
}

def autoAddInclude(dependenciesModule) {
    if (zixieIsDebug) println("autoAddInclude Depenciese of dependenciesModule " + dependenciesModule + " " + zixieCheckModuleIsDev(dependenciesModule))
    if (zixieCheckModuleIsDev(dependenciesModule)) {
        addInclude(dependenciesModule)
    }
}


