Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
YunanChen opened this issue Jul 29, 2020 · 0 comments
Open

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

YunanChen opened this issue Jul 29, 2020 · 0 comments

Comments

@YunanChen
Copy link

YunanChen commented Jul 29, 2020

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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant