mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Better handling of Java/Kotlin mixed projects.
This commit is contained in:
parent
3fb4959129
commit
8efdfc2a04
1 changed files with 24 additions and 13 deletions
|
@ -126,21 +126,32 @@ class CompilerUtils @Inject constructor(val files: KFiles,
|
||||||
// Note: this should actually be queried on the compiler object so that this method, which
|
// Note: this should actually be queried on the compiler object so that this method, which
|
||||||
// is compiler agnostic, doesn't hardcode Kotlin specific stuff
|
// is compiler agnostic, doesn't hardcode Kotlin specific stuff
|
||||||
val extraSourceFiles = arrayListOf<String>()
|
val extraSourceFiles = arrayListOf<String>()
|
||||||
|
|
||||||
|
fun containsJavaFiles(dir: File) : Boolean {
|
||||||
|
if (dir.isDirectory) {
|
||||||
|
var hasJava = false
|
||||||
|
val directories = arrayListOf<File>()
|
||||||
|
dir.listFiles().forEach {
|
||||||
|
hasJava = it.isFile && it.name.endsWith("java")
|
||||||
|
if (it.isDirectory) directories.add(it)
|
||||||
|
}
|
||||||
|
if (hasJava) return true
|
||||||
|
else return directories.any { containsJavaFiles(it) }
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if (sourceSuffixes.any { it.contains("kt")}) {
|
if (sourceSuffixes.any { it.contains("kt")}) {
|
||||||
project.sourceDirectories.forEach {
|
project.sourceDirectories.forEach {
|
||||||
val javaDir = KFiles.joinDir(project.directory, it)
|
val javaDir = File(KFiles.joinDir(project.directory, it))
|
||||||
if (File(javaDir).exists()) {
|
if (javaDir.exists() && containsJavaFiles(javaDir)) {
|
||||||
if (it.contains("java")) {
|
extraSourceFiles.add(javaDir.path)
|
||||||
extraSourceFiles.add(javaDir)
|
// Add all the source directories contributed as potential Java directories too
|
||||||
// Add all the source directories contributed as potential Java directories too
|
// (except our own)
|
||||||
// (except our own)
|
context.pluginInfo.sourceDirContributors
|
||||||
context.pluginInfo.sourceDirContributors
|
.forEach {
|
||||||
// .filter { it != this }
|
extraSourceFiles.addAll(it.sourceDirectoriesFor(project, context).map { it.path })
|
||||||
.forEach {
|
}
|
||||||
extraSourceFiles.addAll(it.sourceDirectoriesFor(project, context).map { it.path })
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue