From c2d61023e682ef272dece88a4c587ba6fb2ce031 Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Mon, 29 Sep 2025 22:45:32 +0200 Subject: [PATCH] [kotlin] project-model-updater: normalize root path ^KTIJ-35777 GitOrigin-RevId: 745494e8986ebaa126aa38d29230eca95e38eb85 --- .../model/updater/KotlinTestsDependenciesUtil.kt | 15 +++++++++++---- .../tools/model/updater/compilerPublication.kt | 2 -- .../tools/model/updater/projectModelUpdater.kt | 15 ++------------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/plugins/kotlin/util/project-model-updater/src/org/jetbrains/tools/model/updater/KotlinTestsDependenciesUtil.kt b/plugins/kotlin/util/project-model-updater/src/org/jetbrains/tools/model/updater/KotlinTestsDependenciesUtil.kt index 111433435f45..50532b3ce766 100644 --- a/plugins/kotlin/util/project-model-updater/src/org/jetbrains/tools/model/updater/KotlinTestsDependenciesUtil.kt +++ b/plugins/kotlin/util/project-model-updater/src/org/jetbrains/tools/model/updater/KotlinTestsDependenciesUtil.kt @@ -23,19 +23,25 @@ object KotlinTestsDependenciesUtil { // We cannot reference PathManager or build scripts here because we call this code from Gradle in TeamCity val communityRoot: Path by lazy { + findCommunityRoot().toAbsolutePath().normalize() + } + + private fun findCommunityRoot(): Path { val possibleHomePaths = mutableListOf() System.getProperty(PROPERTY_HOME_PATH)?.let { possibleHomePaths.add(Path(it)) } System.getenv(IDEA_HOME)?.let { possibleHomePaths.add(Path(it)) } possibleHomePaths.add(Path(".")) for (explicit in possibleHomePaths) { if (explicit.resolve(COMMUNITY_MARKER).isRegularFile()) { - return@lazy explicit + return explicit } + val communityPath = explicit.resolve("community") if (communityPath.resolve(COMMUNITY_MARKER).isRegularFile()) { - return@lazy communityPath.toAbsolutePath() + return communityPath.toAbsolutePath() } } + val aClass: Class<*> = KotlinTestsDependenciesUtil::class.java val aClassFilename = "${aClass.getName().replace('.', '/')}.class" val aClassLocation = aClass.classLoader.getResource(aClassFilename)?.toString()?.substringAfter("file:") @@ -54,15 +60,16 @@ object KotlinTestsDependenciesUtil { while (rootPath != null) { if (rootPath.resolve(COMMUNITY_MARKER).isRegularFile()) { - return@lazy rootPath.toAbsolutePath() + return rootPath.toAbsolutePath() } else if (rootPath.resolve(ULTIMATE_MARKER).isRegularFile()) { val communityPath = rootPath.resolve("community") if (communityPath.isDirectory()) { - return@lazy communityPath.toAbsolutePath() + return communityPath.toAbsolutePath() } } rootPath = rootPath.parent } + error("cannot detect community root path for class $aClassLocation") } diff --git a/plugins/kotlin/util/project-model-updater/src/org/jetbrains/tools/model/updater/compilerPublication.kt b/plugins/kotlin/util/project-model-updater/src/org/jetbrains/tools/model/updater/compilerPublication.kt index 8fff0f49f67a..c538a4194967 100644 --- a/plugins/kotlin/util/project-model-updater/src/org/jetbrains/tools/model/updater/compilerPublication.kt +++ b/plugins/kotlin/util/project-model-updater/src/org/jetbrains/tools/model/updater/compilerPublication.kt @@ -21,8 +21,6 @@ internal fun publishCompiler(preferences: GeneratorPreferences) { val kotlinSnapshotPath = KotlinTestsDependenciesUtil.communityRoot .resolve("lib") .resolve("kotlin-snapshot") - .absolute() - .normalize() println("Artifacts path: $kotlinSnapshotPath") diff --git a/plugins/kotlin/util/project-model-updater/src/org/jetbrains/tools/model/updater/projectModelUpdater.kt b/plugins/kotlin/util/project-model-updater/src/org/jetbrains/tools/model/updater/projectModelUpdater.kt index 16e2e34510ca..f33b3dbcfe61 100644 --- a/plugins/kotlin/util/project-model-updater/src/org/jetbrains/tools/model/updater/projectModelUpdater.kt +++ b/plugins/kotlin/util/project-model-updater/src/org/jetbrains/tools/model/updater/projectModelUpdater.kt @@ -5,9 +5,7 @@ import org.jetbrains.tools.model.updater.impl.JpsLibrary import org.jetbrains.tools.model.updater.impl.JpsResolverSettings import org.jetbrains.tools.model.updater.impl.readJpsResolverSettings import java.nio.file.Path -import kotlin.io.path.Path import kotlin.io.path.deleteExisting -import kotlin.io.path.isDirectory import kotlin.io.path.listDirectoryEntries import kotlin.io.path.readText import kotlin.io.path.writeText @@ -15,17 +13,8 @@ import kotlin.io.path.writeText internal fun updateProjectModel(preferences: GeneratorPreferences) { copyBootstrapArtifactsToMavenRepositoryIfExists() - val communityRoot = generateSequence(Path(".").toRealPath()) { it.parent }.first { - it.resolve(".idea").isDirectory() && - !it.resolve("community").isDirectory() && - // This file name check is needed since the project model updater might be opened as a standalone project - it.fileName.toString() != "project-model-updater" - } - - val monorepoRoot = communityRoot.parent.takeIf { - // The community name check is required since the community might be placed directly inside another repo (e.g., kotlin) - it.resolve(".idea").isDirectory() && it.resolve("community").isDirectory() - } + val communityRoot = KotlinTestsDependenciesUtil.communityRoot + val monorepoRoot = KotlinTestsDependenciesUtil.monorepoRoot val resolverSettings = readJpsResolverSettings(communityRoot, monorepoRoot)