From 845da1329b6e79722c9f260fb7cf264048d6587d Mon Sep 17 00:00:00 2001 From: "Daniil.Karol" Date: Thu, 2 Jan 2025 17:59:58 +0100 Subject: [PATCH] migrated to K2, intellij platform v2.*.*, fixed bugs with gradle --- build.gradle.kts | 3 +- gradle.properties | 6 +-- gradle/libs.versions.toml | 17 +++--- gradle/wrapper/gradle-wrapper.properties | 2 +- ij-plugin/build.gradle.kts | 54 ++++++++++++++----- .../handler/ide/InspectionHandler.kt | 2 +- .../tasktracker/tracking/TaskFileHandler.kt | 4 +- .../ui/main/panel/MainPluginWindow.kt | 8 +-- .../main/panel/panelStates/DefaultStates.kt | 17 +++--- .../ide/inspection/InspectionConfigTest.kt | 7 ++- .../tracking/TaskFileHandlerTest.kt | 3 +- ij-server/build.gradle.kts | 3 +- .../research/tasktracker/util/FileUtil.kt | 2 +- settings.gradle.kts | 2 +- 14 files changed, 81 insertions(+), 49 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0a8c48c5..c096bc95 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { id(libs.plugins.kotlin.jvm.get().pluginId) version libs.versions.kotlin.get() alias(libs.plugins.buildconfig) apply false alias(libs.plugins.detekt) - alias(libs.plugins.serialization) + alias(libs.plugins.serialization) apply false alias(libs.plugins.changelog) } @@ -32,6 +32,7 @@ allprojects { implementation(rootProject.libs.csv) detektPlugins(rootProject.libs.detekt.formatting) implementation(rootProject.libs.joda) + implementation(rootProject.libs.kotlin.serialization) testImplementation(kotlin("test")) } diff --git a/gradle.properties b/gradle.properties index 314f7dc6..23345eed 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,18 +8,18 @@ pluginVersion = 0.1.0 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild = 223 -pluginUntilBuild = 242 +pluginUntilBuild = 243.* # IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension platformType = IC -platformVersion = 2022.3.3 +platformVersion = 2024.3 # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 platformPlugins = # Gradle Releases -> https://github.com/gradle/gradle/releases -gradleVersion = 8.5 +gradleVersion = 8.10 # Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib # suppress inspection "UnusedProperty" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 752139b0..046a94dd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,12 +1,12 @@ [versions] -kotlin = "1.8.10" -intellij = "1.16.1" -detekt = "1.22.0" +kotlin = "2.1.0" +intellij = "2.1.0" +detekt = "1.23.7" buildconfig = "3.1.0" -jdk17 = "17" +jdk21 = "21" jdk11 = "11" kaml = "0.52.0" -serialization = "1.8.10" +serialization = "1.7.3" snakeyaml = "2.0" csv = "1.10.0" joda = "2.12.4" @@ -20,6 +20,7 @@ postgres = "42.3.1" logback = "1.4.11" exposed = "0.44.0" h2 = "2.2.224" +opentest4j="1.3.0" [libraries] detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } @@ -39,6 +40,8 @@ ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx ktor-server-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor" } ktor-server-netty = { module = "io.ktor:ktor-server-netty-jvm", version.ref = "ktor" } ktor-server-tests = { module = "io.ktor:ktor-server-tests-jvm", version.ref = "ktor" } +opentest4j = { module = "org.opentest4j:opentest4j", version.ref = "opentest4j" } +kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" } slf4j = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" } postgres = { module = "org.postgresql:postgresql", version.ref = "postgres" } @@ -51,10 +54,10 @@ h2 = { module = "com.h2database:h2", version.ref = "h2" } [plugins] -intellij = { id = "org.jetbrains.intellij", version.ref = "intellij" } +intellij = { id = "org.jetbrains.intellij.platform", version.ref = "intellij" } detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } buildconfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildconfig" } -serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "serialization" } +serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" } ktor = { id = "io.ktor.plugin", version.ref = "ktor" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bdc9a83b..9a308b8d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +distributionUrl=https://services.gradle.org/distributions/gradle-8.10-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/ij-plugin/build.gradle.kts b/ij-plugin/build.gradle.kts index 74c0e234..ec37899f 100644 --- a/ij-plugin/build.gradle.kts +++ b/ij-plugin/build.gradle.kts @@ -1,6 +1,7 @@ import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.changelog.markdownToHTML -import org.jetbrains.kotlin.incremental.createDirectory +import org.jetbrains.intellij.platform.gradle.TestFrameworkType +import org.jetbrains.kotlin.gradle.dsl.JvmTarget group = rootProject.group version = rootProject.version @@ -12,9 +13,36 @@ plugins { alias(libs.plugins.intellij) } -val jdkVersion = libs.versions.jdk17.get() +repositories { + intellijPlatform { + defaultRepositories() + } +} + +intellijPlatform { + buildSearchableOptions = false + projectName = project.name + pluginConfiguration { + id = project.name + name = properties("pluginName") + version = properties("pluginVersion") + ideaVersion { + sinceBuild = properties("pluginSinceBuild") + untilBuild = properties("pluginUntilBuild") + } + } +} + +val jdkVersion = libs.versions.jdk21.get() dependencies { + intellijPlatform { + create(properties("platformType"), properties("platformVersion")) + instrumentationTools() + testFramework(TestFrameworkType.Platform) + plugins(properties("platformPlugins").map { it.split(',').map(String::trim).filter(String::isNotEmpty) }) + } + implementation(rootProject.libs.kaml) implementation(rootProject.libs.snakeyaml) implementation(rootProject.libs.kinference) @@ -27,17 +55,20 @@ dependencies { implementation(rootProject.libs.ktor.serialization.kotlinx.json) implementation(rootProject.libs.slf4j) implementation(rootProject.libs.opencv) + // Due to the IJPL-157292 issue + testImplementation(rootProject.libs.opentest4j) } -intellij { - pluginName.set(properties("pluginName")) - version.set(properties("platformVersion")) - type.set(properties("platformType")) - plugins.set(properties("platformPlugins").map { it.split(',').map(String::trim).filter(String::isNotEmpty) }) + +configurations { + all { + exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core") + } } val defaultPropertiesDirectory = project.file("src/main/resources/properties/default") -val actualPropertiesDirectory = project.file("src/main/resources/properties/actual").also { if (!it.exists()) it.createDirectory() } +val actualPropertiesDirectory = + project.file("src/main/resources/properties/actual").also { if (!it.exists()) it.mkdirs() } tasks { val checkPropertiesExist = register("checkPropertiesExist") { @@ -58,9 +89,6 @@ tasks { } } - withType() - .forEach { it.enabled = false } - patchPluginXml { val description = """ TaskTracker-3 - a revolutionary plugin for collecting detailed data during education. @@ -77,10 +105,10 @@ tasks { withType { sourceCompatibility = jdkVersion - targetCompatibility = JavaVersion.VERSION_17.toString() + targetCompatibility = JavaVersion.VERSION_21.toString() } withType { - kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString() + compilerOptions.jvmTarget.set(JvmTarget.JVM_21) } withType().configureEach { diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/ide/InspectionHandler.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/ide/InspectionHandler.kt index 09c001a3..c06bfbc6 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/ide/InspectionHandler.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/ide/InspectionHandler.kt @@ -44,7 +44,7 @@ class InspectionHandler(override val config: InspectionConfig, override val proj } } - private fun initTaskProfile(project: Project): InspectionProfileImpl { + fun initTaskProfile(project: Project): InspectionProfileImpl { val inspectionProfileManager = ProjectInspectionProfileManager.getInstance(project) val inspectionProfile = InspectionProfileImpl( PROFILE_NAME, diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TaskFileHandler.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TaskFileHandler.kt index a259bd42..5708d0a4 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TaskFileHandler.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TaskFileHandler.kt @@ -75,7 +75,7 @@ object TaskFileHandler { } private fun addVirtualFileListener(project: Project, virtualFile: VirtualFile) { - ApplicationManager.getApplication().invokeAndWait { + ApplicationManager.getApplication().runWriteAction { val document = FileDocumentManager.getInstance().getDocument(virtualFile) document?.let { it.addDocumentListener(getListener()) @@ -87,7 +87,7 @@ object TaskFileHandler { private fun removeVirtualFileListener(project: Project, virtualFiles: List) { virtualFiles.forEach { file -> - ApplicationManager.getApplication().invokeAndWait { + ApplicationManager.getApplication().runWriteAction { val document = FileDocumentManager.getInstance().getDocument(file) document?.let { DocumentLogger.removeDocumentLogPrinter(project, document) diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginWindow.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginWindow.kt index b1034a64..e7637613 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginWindow.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginWindow.kt @@ -52,11 +52,11 @@ class MainPluginWindow(service: MainWindowService) { private fun getJsElementByIdCommand(elementId: String) = "document.getElementById('$elementId')" - fun getElementValue(elementId: String): Promise = - windowBrowser.executeJavaScriptAsync("${getJsElementByIdCommand(elementId)}.value") + fun getElementValue(elementId: String): Promise = + windowBrowser.executeJavaScriptAsync("${getJsElementByIdCommand(elementId)}.value") as Promise - fun checkIfRadioButtonChecked(elementId: String): Promise = - windowBrowser.executeJavaScriptAsync("${getJsElementByIdCommand(elementId)}.checked") + fun checkIfRadioButtonChecked(elementId: String): Promise = + windowBrowser.executeJavaScriptAsync("${getJsElementByIdCommand(elementId)}.checked") as Promise fun executeJavaScriptAsync(@Language("JavaScript") code: String) = windowBrowser.executeJavaScriptAsync(code) diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/panelStates/DefaultStates.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/panelStates/DefaultStates.kt index 682b27f4..90c7891f 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/panelStates/DefaultStates.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/panelStates/DefaultStates.kt @@ -1,7 +1,6 @@ package org.jetbrains.research.tasktracker.ui.main.panel.panelStates import com.intellij.openapi.application.ApplicationManager -import com.intellij.util.alsoIfNull import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @@ -32,12 +31,14 @@ fun Panel.agreementAcceptance() { checkAgreementInputs().runOnSuccess { if (!it) { GlobalPluginStorage.agreementChecker?.let { agreement -> - GlobalPluginStorage.userId = IdRequests.getUserId(agreement.name, agreement.email).alsoIfNull { - notifyError( - project, - UIBundle.message("ui.connection.lose") - ) - return@runOnSuccess + GlobalPluginStorage.userId = IdRequests.getUserId(agreement.name, agreement.email).also { + if (it == null) { + notifyError( + project, + UIBundle.message("ui.connection.lose") + ) + return@runOnSuccess + } } } GlobalPluginStorage.currentResearchId = IdRequests.getResearchId() @@ -69,7 +70,7 @@ private fun Panel.selectTask(taskIds: List, allRequired: Boolean = true) loadBasePage(TasksPageTemplate(tasks), isVisiblePauseButton = false) setNextAction { mainWindow.getElementValue("tasks").runOnSuccess { name -> - solveTask(name.toString(), if (allRequired) taskIds.filter { it != name } else emptyList()) + solveTask(name, if (allRequired) taskIds.filter { it != name } else emptyList()) } } } diff --git a/ij-plugin/src/test/kotlin/org/jetbrains/research/tasktracker/config/ide/inspection/InspectionConfigTest.kt b/ij-plugin/src/test/kotlin/org/jetbrains/research/tasktracker/config/ide/inspection/InspectionConfigTest.kt index 38ada9ab..e15cfd71 100644 --- a/ij-plugin/src/test/kotlin/org/jetbrains/research/tasktracker/config/ide/inspection/InspectionConfigTest.kt +++ b/ij-plugin/src/test/kotlin/org/jetbrains/research/tasktracker/config/ide/inspection/InspectionConfigTest.kt @@ -66,7 +66,6 @@ class InspectionConfigTest : LightPlatformTestCase() { fun testAddSelectedInspections() { val profile = getProfile("addSelected") val enabledTools = profile.getAllEnabledToolIds() - println(profile.getAllDisabledToolIds()) assert(enabledTools.size == ADD_SELECTED_ENABLED_INSPECTION_SIZE) { "add selected tools size is $ADD_SELECTED_ENABLED_INSPECTION_SIZE, but ${enabledTools.size} has been found" } @@ -124,9 +123,9 @@ class InspectionConfigTest : LightPlatformTestCase() { } companion object { - const val DEFAULT_ENABLED_INSPECTION_SIZE = 56 - const val DISABLE_SELECTED_ENABLED_INSPECTION_SIZE = 54 - const val ADD_SELECTED_ENABLED_INSPECTION_SIZE = 58 + const val DEFAULT_ENABLED_INSPECTION_SIZE = 48 + const val DISABLE_SELECTED_ENABLED_INSPECTION_SIZE = 46 + const val ADD_SELECTED_ENABLED_INSPECTION_SIZE = 50 val enableSelectedTools = listOf("LongLine", "TodoComment") val disableSelectedTools = listOf("CheckTagEmptyBody", "RegExpRedundantEscape") val addSelectedTools = listOf("EmptyDirectory", "ProblematicWhitespace") diff --git a/ij-plugin/src/test/kotlin/org/jetbrains/research/tasktracker/tracking/TaskFileHandlerTest.kt b/ij-plugin/src/test/kotlin/org/jetbrains/research/tasktracker/tracking/TaskFileHandlerTest.kt index be9edfaa..704d7400 100644 --- a/ij-plugin/src/test/kotlin/org/jetbrains/research/tasktracker/tracking/TaskFileHandlerTest.kt +++ b/ij-plugin/src/test/kotlin/org/jetbrains/research/tasktracker/tracking/TaskFileHandlerTest.kt @@ -8,7 +8,6 @@ import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig.Companion import org.jetbrains.research.tasktracker.config.content.task.base.Task import org.jetbrains.research.tasktracker.config.content.task.base.TaskWithFiles import org.jetbrains.research.tasktracker.tracking.mock.* -import kotlin.test.assertFailsWith class TaskFileHandlerTest : CodeInsightFixtureTestCase>() { @@ -37,7 +36,7 @@ class TaskFileHandlerTest : CodeInsightFixtureTestCase>( fun testInitExistingTask() { TaskFileHandler.initTask(project, task1) - assertFailsWith("Expected Throwable on second initialization of $task1") { + assertNoThrowable { TaskFileHandler.initTask(project, task1) } } diff --git a/ij-server/build.gradle.kts b/ij-server/build.gradle.kts index 916f2cf1..2b64fcd0 100644 --- a/ij-server/build.gradle.kts +++ b/ij-server/build.gradle.kts @@ -1,4 +1,5 @@ import io.gitlab.arturbosch.detekt.Detekt +import org.jetbrains.kotlin.gradle.dsl.JvmTarget group = rootProject.group version = rootProject.version @@ -36,7 +37,7 @@ tasks{ targetCompatibility = JavaVersion.VERSION_11.toString() } withType { - kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString() + compilerOptions.jvmTarget.set(JvmTarget.JVM_11) } withType().configureEach { diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/util/FileUtil.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/util/FileUtil.kt index 412adfec..d9582c8b 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/util/FileUtil.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/util/FileUtil.kt @@ -25,7 +25,7 @@ suspend inline fun PipelineContext.createLogFile( val fileName = part.originalFileName as String val fileBytes = part.streamProvider().readBytes() file = file ?: getAndCreateFile(directoryPath, fileName) - file?.appendBytes(fileBytes) + file.appendBytes(fileBytes) } part.dispose() } diff --git a/settings.gradle.kts b/settings.gradle.kts index 5c9be412..64cc3043 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,6 @@ pluginManagement { repositories { - mavenCentral() + maven("https://oss.sonatype.org/content/repositories/snapshots/") gradlePluginPortal() } }