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 26f4dc18..96c616b2 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,7 +2,7 @@ package com.jetbrains.packagesearch.plugin.core.data -import com.jetbrains.packagesearch.plugin.core.utils.DirectoryPath +import com.jetbrains.packagesearch.plugin.core.utils.SerializablePath import java.nio.file.Path import kotlinx.serialization.Serializable import org.jetbrains.packagesearch.api.v3.search.PackagesType @@ -46,6 +46,6 @@ sealed interface PackageSearchModule : IconProvider, PackageSearchModuleEditor { data class Identity( val group: String, val path: String, - val projectDir: DirectoryPath, + val projectDir: SerializablePath, ) } 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 deleted file mode 100644 index e7af4af5..00000000 --- a/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/utils/DirectoryPath.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.jetbrains.packagesearch.plugin.core.utils - -import java.nio.file.Path -import kotlin.io.path.absolutePathString -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" } - } - - override fun toString() = absolutePathString() - override fun equals(other: Any?) = absolutePathString() == (other as? DirectoryPath)?.absolutePathString() - override fun hashCode() = absolutePathString().hashCode() - - 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 3137141a..58b02459 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 @@ -1,10 +1,10 @@ package com.jetbrains.packagesearch.plugin.core.utils import java.nio.file.Path -import java.nio.file.Paths import kotlin.io.path.Path import kotlin.io.path.absolutePathString import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable import kotlinx.serialization.builtins.serializer import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder @@ -20,3 +20,5 @@ object NioPathSerializer : KSerializer { } } + +typealias SerializablePath = @Serializable(with = NioPathSerializer::class) Path 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 68cb541e..c469e65d 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,7 +6,6 @@ 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.toGradle import kotlinx.coroutines.flow.FlowCollector @@ -14,7 +13,6 @@ import org.jetbrains.packagesearch.api.v3.ApiMavenRepository import org.jetbrains.packagesearch.api.v3.search.androidPackages import org.jetbrains.packagesearch.api.v3.search.buildPackageTypes import org.jetbrains.packagesearch.api.v3.search.jvmGradlePackages -import org.jetbrains.packagesearch.packageversionutils.normalization.NormalizedVersion class GradleModuleProvider : AbstractGradleModuleProvider() { @@ -42,7 +40,7 @@ class GradleModuleProvider : AbstractGradleModuleProvider() { identity = PackageSearchModule.Identity( group = "gradle", path = model.projectIdentityPath.fixBuildSrc(model), - projectDir = model.projectDir.toDirectory(), + projectDir = model.projectDir, ), buildFilePath = model.buildFilePath, declaredRepositories = model.declaredRepositories.toGradle(), 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 949d74ca..94ed1327 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 @@ -7,7 +7,6 @@ import com.intellij.packageSearch.mppDependencyUpdater.resolved.MppCompilationIn 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.toGradle import kotlinx.coroutines.flow.FlowCollector @@ -33,7 +32,7 @@ class KotlinMultiplatformModuleProvider : AbstractGradleModuleProvider() { identity = PackageSearchModule.Identity( group = "gradle", path = model.projectIdentityPath, - projectDir = model.projectDir.toDirectory(), + projectDir = model.projectDir, ), buildFilePath = model.buildFilePath, declaredRepositories = model.declaredRepositories.toGradle(), diff --git a/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/PackageSearchGradleModel.kt b/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/PackageSearchGradleModel.kt index 36fe6583..1b06dea8 100644 --- a/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/PackageSearchGradleModel.kt +++ b/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/PackageSearchGradleModel.kt @@ -1,13 +1,12 @@ package com.jetbrains.packagesearch.plugin.gradle import com.intellij.openapi.externalSystem.model.Key -import com.jetbrains.packagesearch.plugin.core.utils.NioPathSerializer -import java.nio.file.Path +import com.jetbrains.packagesearch.plugin.core.utils.SerializablePath import kotlinx.serialization.Serializable @Serializable data class PackageSearchGradleModel( - @Serializable(with = NioPathSerializer::class) val projectDir: Path, + val projectDir: SerializablePath, val configurations: List, val declaredRepositories: List, val isJavaApplied: Boolean, @@ -17,8 +16,8 @@ data class PackageSearchGradleModel( val projectIdentityPath: String, val projectName: String, val rootProjectName: String, - @Serializable(with = NioPathSerializer::class) val buildFilePath: Path?, - @Serializable(with = NioPathSerializer::class) val rootProjectPath: Path, + val buildFilePath: SerializablePath?, + val rootProjectPath: SerializablePath, val gradleVersion: String, ) { 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 b2401ab8..940b4eb8 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 @@ -24,7 +24,6 @@ import com.jetbrains.packagesearch.plugin.core.utils.icon import com.jetbrains.packagesearch.plugin.core.utils.isSameFileAsSafe import com.jetbrains.packagesearch.plugin.core.utils.mapUnit import com.jetbrains.packagesearch.plugin.core.utils.smartModeFlow -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 @@ -114,7 +113,7 @@ suspend fun Module.toPackageSearch( identity = PackageSearchModule.Identity( group = "maven", path = ":", - projectDir = pomPath.parent.toDirectory(), + projectDir = pomPath.parent, ), buildFilePath = pomPath, declaredRepositories = getDeclaredRepositories(),