diff --git a/build.gradle.kts b/build.gradle.kts index 53687ae..033414e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,12 +2,12 @@ import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType plugins { id("java") - id("org.jetbrains.kotlin.jvm") version "1.9.25" - id("org.jetbrains.intellij.platform") version "2.2.1" + id("org.jetbrains.kotlin.jvm") version "2.1.10" + id("org.jetbrains.intellij.platform") version "2.3.0" } group = "com.maxxton" -version = "1.0.2" +version = "1.0.3" repositories { mavenCentral() @@ -18,8 +18,6 @@ repositories { } dependencies { - implementation("org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:6.8.0.202311291450-r") - intellijPlatform { val version = providers.gradleProperty("platformVersion") create(IntelliJPlatformType.IntellijIdeaCommunity, version) @@ -35,8 +33,11 @@ tasks { sourceCompatibility = "21" targetCompatibility = "21" } + withType { - kotlinOptions.jvmTarget = "21" + compilerOptions { + jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21) + } } patchPluginXml { diff --git a/src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt b/src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt index 1c04d32..a166814 100644 --- a/src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt +++ b/src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt @@ -15,11 +15,19 @@ import java.nio.file.Files import java.nio.file.Path import java.util.stream.Collectors import kotlin.io.path.* +import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds + +private const val upToDateNotificationDuration = 1500 class CodeStyleSyncActivity : ProjectActivity { + override suspend fun execute(project: Project) { + println("Syncing code style...") + try { syncCodeStyle() + println("Code style sync complete") } catch (e: Exception) { printlnError("Failed to sync code style: $e") } @@ -30,7 +38,7 @@ class CodeStyleSyncActivity : ProjectActivity { if (config.state.repoUrl.isBlank()) { showNotification( - "Repository URL is not configured. Please set it in Settings | Tools | Mold.", + "Repository URL is not configured. Please set it in Settings -> Tools -> Mold.", NotificationType.ERROR ) return @@ -39,7 +47,6 @@ class CodeStyleSyncActivity : ProjectActivity { val tempDir = Files.createTempDirectory("maxxton-codestyle") try { - // Use config.state.repoUrl instead of hardcoded value val process = ProcessBuilder() .command("git", "clone", "--depth", "1", config.state.repoUrl.trim(), tempDir.toString()) .start() @@ -53,48 +60,60 @@ class CodeStyleSyncActivity : ProjectActivity { throw IllegalStateException("Git clone failed") } - // Get IntelliJ config directory - val configDir = getConfigDir() ?: throw IllegalStateException("Could not find IntelliJ config directory") + updateConfigFiles(tempDir) + } finally { + tempDir.toFile().deleteRecursively() + } + } - // Setup directories - val codestyleDir = configDir.resolve("codestyles").apply { createDirectories() } - val inspectionsDir = configDir.resolve("inspection").apply { createDirectories() } - val optionsDir = configDir.resolve("options").apply { createDirectories() } + private fun updateConfigFiles(tempDir: Path) { + // Get IntelliJ config directory + val configDir = getConfigDir() ?: throw IllegalStateException("Could not find IntelliJ config directory") - // Copy files - var hasChanged = copyIfDifferent( - tempDir.resolve("intellij/MaxxtonCodeStyle.xml"), - codestyleDir.resolve("MaxxtonCodeStyle.xml") - ) + // Setup directories + val codestyleDir = configDir.resolve("codestyles").apply { createDirectories() } + val inspectionsDir = configDir.resolve("inspection").apply { createDirectories() } + val optionsDir = configDir.resolve("options").apply { createDirectories() } - hasChanged = hasChanged || copyIfDifferent( - tempDir.resolve("intellij/MaxxtonInspections.xml"), - inspectionsDir.resolve("MaxxtonInspections.xml") - ) + // Copy files + val changes = mutableListOf() - if (hasChanged) { - showNotification("Updating IDE settings...") - updateCodeStyleSchemes(optionsDir) - updateInspections(optionsDir) - showRestartNotification() - } else { - showNotification("IDE settings are up to date!") - } - } finally { - tempDir.toFile().deleteRecursively() + if (copyIfDifferent(tempDir.resolve("intellij/MaxxtonCodeStyle.xml"), codestyleDir.resolve("MaxxtonCodeStyle.xml"))) { + changes.add("MaxxtonCodeStyle.xml") + } + + if (copyIfDifferent(tempDir.resolve("intellij/MaxxtonInspections.xml"), inspectionsDir.resolve("MaxxtonInspections.xml"))) { + changes.add("MaxxtonInspections.xml") + } + + if (changes.isNotEmpty()) { + updateCodeStyleSchemes(optionsDir) + updateInspections(optionsDir) + showRestartNotification(changes) + } else { + showNotification("IDE Config is up-to-date!", NotificationType.INFORMATION, upToDateNotificationDuration.milliseconds) } } - private fun showNotification(content: String, type: NotificationType = NotificationType.INFORMATION) { + private fun showNotification(content: String, type: NotificationType = NotificationType.INFORMATION, duration: Duration = Duration.ZERO) { ApplicationManager.getApplication().invokeLater { val notification = NotificationGroupManager.getInstance() .getNotificationGroup("Mold") .createNotification(content, type) + notification.notify(null) + + // auto-expire the notification when a duration is specified + if (duration.inWholeMilliseconds > 0) { + ApplicationManager.getApplication().executeOnPooledThread { + Thread.sleep(duration.inWholeMilliseconds) + notification.expire() + } + } } } - private fun showRestartNotification() { + private fun showRestartNotification(changes: List) { ApplicationManager.getApplication().invokeLater { val notification = NotificationGroupManager.getInstance() .getNotificationGroup("Mold") @@ -111,6 +130,15 @@ class CodeStyleSyncActivity : ProjectActivity { } }) + if (changes.isNotEmpty()) { + notification.addAction(object : NotificationAction("View changes") { + override fun actionPerformed(e: AnActionEvent, notification: Notification) { + notification.expire() + showNotification("Updated files: ${changes.joinToString(", ")}") + } + }) + } + notification.notify(null) } } @@ -181,4 +209,4 @@ class CodeStyleSyncActivity : ProjectActivity { """.trimIndent() editorFile.writeText(content) } -} \ No newline at end of file +}