diff --git a/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/data/PackageSearchModule.kt b/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/data/PackageSearchModule.kt index e3d6d539..2b722cd3 100644 --- a/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/data/PackageSearchModule.kt +++ b/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/data/PackageSearchModule.kt @@ -2,6 +2,7 @@ package com.jetbrains.packagesearch.plugin.core.data +import com.jetbrains.packagesearch.plugin.core.utils.DirectoryPath import java.nio.file.Path import kotlinx.serialization.Serializable import org.jetbrains.packagesearch.api.v3.ApiRepository @@ -42,5 +43,9 @@ sealed interface PackageSearchModule : IconProvider, PackageSearchModuleEditor { } @Serializable - data class Identity(val group: String, val path: String) -} \ No newline at end of file + data class Identity( + val group: String, + val path: String, + val projectDir: DirectoryPath, + ) +} diff --git a/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/utils/DirectoryPath.kt b/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/utils/DirectoryPath.kt new file mode 100644 index 00000000..e15e6352 --- /dev/null +++ b/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/utils/DirectoryPath.kt @@ -0,0 +1,30 @@ +package com.jetbrains.packagesearch.plugin.core.utils + +import java.nio.file.Path +import kotlin.io.path.isDirectory +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +fun Path.toDirectory() = DirectoryPath(this) + +@Serializable(with = DirectoryPath.Companion::class) +class DirectoryPath(path: Path) : Path by path { + init { + require(path.isDirectory()) { "Path $path is not a directory" } + } + + companion object : KSerializer { + override val descriptor: SerialDescriptor + get() = NioPathSerializer.descriptor + + override fun deserialize(decoder: Decoder): DirectoryPath = + NioPathSerializer.deserialize(decoder).toDirectory() + + override fun serialize(encoder: Encoder, value: DirectoryPath) { + NioPathSerializer.serialize(encoder, value) + } + } +} \ No newline at end of file diff --git a/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/utils/NioPathSerializer.kt b/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/utils/NioPathSerializer.kt index 2f974a7a..43a9ea72 100644 --- a/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/utils/NioPathSerializer.kt +++ b/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/utils/NioPathSerializer.kt @@ -18,4 +18,4 @@ object NioPathSerializer : KSerializer { String.serializer().serialize(encoder, value.absolutePathString()) } -} \ No newline at end of file +} diff --git a/plugin/gradle/base/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/GradleModuleProvider.kt b/plugin/gradle/base/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/GradleModuleProvider.kt index 81f2c227..1a6804b4 100644 --- a/plugin/gradle/base/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/GradleModuleProvider.kt +++ b/plugin/gradle/base/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/GradleModuleProvider.kt @@ -6,6 +6,7 @@ import com.intellij.openapi.module.Module import com.jetbrains.packagesearch.plugin.core.PackageSearch import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModule import com.jetbrains.packagesearch.plugin.core.extensions.PackageSearchModuleBuilderContext +import com.jetbrains.packagesearch.plugin.core.utils.toDirectory import com.jetbrains.packagesearch.plugin.gradle.utils.getDeclaredDependencies import com.jetbrains.packagesearch.plugin.gradle.utils.getDeclaredKnownRepositories import kotlinx.coroutines.flow.FlowCollector @@ -37,7 +38,8 @@ class GradleModuleProvider : AbstractGradleModuleProvider() { name = model.projectName, identity = PackageSearchModule.Identity( group = "gradle", - path = model.projectIdentityPath + path = model.projectIdentityPath, + projectDir = model.projectDir.toDirectory(), ), buildFilePath = model.buildFilePath, declaredKnownRepositories = module.getDeclaredKnownRepositories(), diff --git a/plugin/gradle/kmp/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/KotlinMultiplatformModuleProvider.kt b/plugin/gradle/kmp/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/KotlinMultiplatformModuleProvider.kt index ee24395c..12d60f11 100644 --- a/plugin/gradle/kmp/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/KotlinMultiplatformModuleProvider.kt +++ b/plugin/gradle/kmp/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/KotlinMultiplatformModuleProvider.kt @@ -17,6 +17,7 @@ import com.jetbrains.packagesearch.plugin.core.data.IconProvider.Icons import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModule import com.jetbrains.packagesearch.plugin.core.extensions.PackageSearchModuleBuilderContext import com.jetbrains.packagesearch.plugin.core.utils.icon +import com.jetbrains.packagesearch.plugin.core.utils.toDirectory import com.jetbrains.packagesearch.plugin.gradle.utils.getDeclaredDependencies import com.jetbrains.packagesearch.plugin.gradle.utils.toGradleDependencyModel import kotlinx.coroutines.async @@ -48,7 +49,8 @@ class KotlinMultiplatformModuleProvider : AbstractGradleModuleProvider() { name = model.projectName, identity = PackageSearchModule.Identity( group = "gradle", - path = model.projectIdentityPath + path = model.projectIdentityPath, + projectDir = model.projectDir.toDirectory(), ), buildFilePath = model.buildFilePath, declaredKnownRepositories = knownRepositories - DependencyModifierService @@ -137,11 +139,12 @@ class KotlinMultiplatformModuleProvider : AbstractGradleModuleProvider() { gradlePackages { kotlinMultiplatform { compilationTargets.forEach { compilationTarget -> - when { + when { compilationTarget is Js -> when (compilationTarget.compiler) { Js.Compiler.IR -> jsIr() Js.Compiler.LEGACY -> jsLegacy() } + compilationTarget is Native -> native(compilationTarget.target) compilationTarget == MppCompilationInfoModel.Wasm -> wasm() } diff --git a/plugin/maven/src/main/kotlin/com/jetbrains/packagesearch/plugin/maven/MavenUtils.kt b/plugin/maven/src/main/kotlin/com/jetbrains/packagesearch/plugin/maven/MavenUtils.kt index f3914c46..acc31af2 100644 --- a/plugin/maven/src/main/kotlin/com/jetbrains/packagesearch/plugin/maven/MavenUtils.kt +++ b/plugin/maven/src/main/kotlin/com/jetbrains/packagesearch/plugin/maven/MavenUtils.kt @@ -21,10 +21,12 @@ import com.jetbrains.packagesearch.plugin.core.utils.flow import com.jetbrains.packagesearch.plugin.core.utils.icon import com.jetbrains.packagesearch.plugin.core.utils.mapUnit import com.jetbrains.packagesearch.plugin.core.utils.registryFlow +import com.jetbrains.packagesearch.plugin.core.utils.toDirectory import com.jetbrains.packagesearch.plugin.core.utils.watchExternalFileChanges import java.io.File import java.nio.file.Path import java.nio.file.Paths +import kotlin.io.path.Path import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow import kotlinx.coroutines.flow.filter @@ -104,13 +106,15 @@ suspend fun Module.toPackageSearch( mavenProject: MavenProject, ): PackageSearchMavenModule { val declaredDependencies = getDeclaredDependencies() + val pomPath = Path(mavenProject.file.path) return PackageSearchMavenModule( name = mavenProject.name ?: name, identity = PackageSearchModule.Identity( group = "maven", - path = buildMavenParentHierarchy(mavenProject.file.asRegularFile()) + path = buildMavenParentHierarchy(mavenProject.file.asRegularFile()), + projectDir = pomPath.parent.toDirectory(), ), - buildFilePath = Paths.get(mavenProject.file.path), + buildFilePath = pomPath, declaredKnownRepositories = getDeclaredKnownRepositories(), declaredDependencies = declaredDependencies, availableScopes = commonScopes.plus(declaredDependencies.mapNotNull { it.declaredScope }).distinct(), @@ -159,7 +163,7 @@ suspend fun Module.getDeclaredDependencies(): List PackageSearchDeclaredBaseMavenPackage( id = packageId, - declaredVersion = declaredDependency.version?.let { NormalizedVersion.fromStringOrNull(it ) }, + declaredVersion = declaredDependency.version?.let { NormalizedVersion.fromStringOrNull(it) }, remoteInfo = remoteInfo[packageId]?.asMavenApiPackage(), groupId = declaredDependency.groupId, artifactId = declaredDependency.artifactId,