From 7818039983166ea1099e14d66fadb012c0e6dd00 Mon Sep 17 00:00:00 2001 From: Sergei Vorobyov Date: Mon, 2 Sep 2024 16:03:41 +0200 Subject: [PATCH] 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 --- .../plugins/gradle/service/project/GradleContentRootIndex.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleContentRootIndex.kt b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleContentRootIndex.kt index 3796cb346825..aa06694f020f 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleContentRootIndex.kt +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleContentRootIndex.kt @@ -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() + 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 {