IDEA-163185 [Gradle|Sync] fix: resolve source set collections with nested source directories

In case of the nested source directory collision, resolve the most common content roots for the source set.
For example, resolve project/src content root for the project/src and project/src/main/java source directories.

GitOrigin-RevId: 8185b7127fd8644c9a0bd44420485bbe215fd3b1
This commit is contained in:
Sergei Vorobyov
2024-09-02 18:09:20 +00:00
committed by intellij-monorepo-bot
parent 400f7f95b6
commit 7818039983
@@ -7,6 +7,7 @@ import com.intellij.openapi.externalSystem.model.project.ContentRootData
import com.intellij.openapi.externalSystem.model.project.IExternalSystemSourceType
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.NioPathPrefixTreeFactory
import com.intellij.openapi.util.io.toCanonicalPath
import org.jetbrains.plugins.gradle.model.ExternalProject
import org.jetbrains.plugins.gradle.model.ExternalSourceSet
@@ -59,14 +60,14 @@ class GradleContentRootIndex {
val projectRootPath = externalProject.projectDir.toPath()
val contentRootPaths = HashSet<Path>()
val contentRootPaths = NioPathPrefixTreeFactory.createSet()
for (sourceDirectorySet in sources.values) {
for (sourceRootPath in sourceDirectorySet) {
val contentRootPath = resolveContentRoot(projectRootPath, sourceRootPath)
contentRootPaths.add(contentRootPath)
}
}
return contentRootPaths
return contentRootPaths.getRoots()
}
private fun resolveContentRoot(projectRootPath: Path, sourceRootPath: Path): Path {