Archinamon / android-gradle-aspectj

gradle plug-in adding supports of AspectJ into Android project
Apache License 2.0
365 stars 58 forks source link

VariantUtils.kt # findSourcesForVariant() need to improve #125

Open YunanChen opened 4 years ago

YunanChen commented 4 years ago

I have a variant named "LOCAL_Debug". The val types = variantName.split("(?=\\p{Upper})".toRegex()) will split my varaintName into ["L", "O", "C", "A", "L", "Debug"]. Then the for each will match many unexcepted files. For example, I use the MacBook. There is a .ds_store file under app/srcdirs. In this case, the file.list() casue exception.

Since the varaintName can be various, this is a unstable logic. Looking forward to improvement it.

A problem occurred configuring project ':app'.
> file.list() must not be null
fun findSourcesForVariant(project: Project, variantName: String, language: String): MutableSet<File> {
    val possibleDirs: MutableSet<File> = mutableSetOf()
    if (project.file("src/main/$language").exists()) {
        possibleDirs.add(project.file("src/main/$language"))
    }

    val types = variantName.split("(?=\\p{Upper})".toRegex())
    val root = project.file("src").listFiles()

    root.forEach { file ->
        types.forEach { type ->
            if (file.name.contains(type.toLowerCase()) &&
                    file.list().any { it.contains(language) }) {
                possibleDirs.add(File(file, language))
            }
        }
    }

    return LinkedHashSet(possibleDirs)
}