IJPL-248066 Workspace Model: change codegen-api version check

Merge-request: IJ-MR-215492
Merged-by: Kirill Bochkarev <kirill.bochkarev@jetbrains.com>

GitOrigin-RevId: 51babd1e1ccd8aaeb35f20af1ba94da933da7270
This commit is contained in:
Kirill Bochkarev
2026-07-27 17:19:22 +00:00
committed by intellij-monorepo-bot
parent 1f397395c5
commit d25a0be532
2 changed files with 39 additions and 5 deletions
@@ -28,6 +28,8 @@ command.name.generate.code.for.workspace.entities.in=Generate Code for Workspace
notification.workspace.incompatible.codegen.api.versions=Incompatible codegen api versions
notification.workspace.incompatible.codegen.api.versions.content.older=Codegen-api version in devkit plugin ({0}) is older than in codegen-impl ({1}). Please, update your IDE
notification.workspace.incompatible.codegen.api.versions.content.newer=Codegen-api version in devkit plugin ({0}) is newer than in codegen-impl ({1}). Please, downgrade your IDE
notification.workspace.compatible.but.different.codegen.api.versions=Different codegen api versions
notification.workspace.compatible.but.different.codegen.api.versions.content=Codegen-api version in devkit plugin ({0}) and in codegen-impl ({1}) differ. Generated code might be missing some latest features. Please, update your IDE
notification.workspace.code.generation.not.available=Workspace code generation not available
notification.workspace.code.generation.not.available.message=Entity code generation is not supported for plugins yet
action.WorkspaceModelGenerateAllModulesAction.text=Generate Workspace Model Implementation for All Modules
@@ -216,16 +216,48 @@ object CodeWriter {
copyHeaderComment(sourceFile, file)
}
private fun codegenApiVersionsAreCompatible(project: Project, codeGeneratorFromDownloadedJar: CodeGenerator): Boolean {
val apiVersionInDevkit = getApiVersionFromJSON(CodeGenerator::class.java)
val apiVersionFromDownloadedJar = getApiVersionFromManifest(codeGeneratorFromDownloadedJar::class.java)
private data class ApiVersion(val major: Int, val minor: Int, val patch: Int) : Comparable<ApiVersion> {
fun compatible(other: ApiVersion): Boolean {
return major == other.major && minor == other.minor
}
if (apiVersionInDevkit == apiVersionFromDownloadedJar) {
override fun toString(): String = "$major.$minor.$patch"
override fun compareTo(other: ApiVersion): Int {
return when {
major != other.major -> major - other.major
minor != other.minor -> minor - other.minor
else -> patch - other.patch
}
}
}
private fun parseCodegenApi(codegenApiVersion: String): ApiVersion {
val (major, minor, patch) = codegenApiVersion.split(".", "-").take(3).map { it.toInt() }
return ApiVersion(major, minor, patch)
}
private fun codegenApiVersionsAreCompatible(project: Project, codeGeneratorFromDownloadedJar: CodeGenerator): Boolean {
val apiVersionInDevkit = getApiVersionFromJSON(CodeGenerator::class.java).let { parseCodegenApi(it) }
val apiVersionFromDownloadedJar = getApiVersionFromManifest(codeGeneratorFromDownloadedJar::class.java).let { parseCodegenApi(it) }
if (apiVersionInDevkit.compatible(apiVersionFromDownloadedJar)) {
if (apiVersionInDevkit.patch == apiVersionFromDownloadedJar.patch)
return true
val groupId = DevKitWorkspaceModelBundle.message("notification.workspace.compatible.but.different.codegen.api.versions")
val message = DevKitWorkspaceModelBundle.message("notification.workspace.compatible.but.different.codegen.api.versions.content",
apiVersionInDevkit,
apiVersionFromDownloadedJar)
NotificationGroupManager.getInstance()
.getNotificationGroup(groupId)
.createNotification(title = groupId, message, NotificationType.WARNING)
.notify(project)
return true
}
val message =
if (apiVersionFromDownloadedJar == CodegenApiVersion.UNKNOWN_VERSION || apiVersionInDevkit > apiVersionFromDownloadedJar) {
if (apiVersionInDevkit > apiVersionFromDownloadedJar) {
DevKitWorkspaceModelBundle.message("notification.workspace.incompatible.codegen.api.versions.content.newer",
apiVersionInDevkit,
apiVersionFromDownloadedJar)