Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -35,8 +33,11 @@ tasks {
sourceCompatibility = "21"
targetCompatibility = "21"
}

withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "21"
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21)
}
}

patchPluginXml {
Expand Down
88 changes: 58 additions & 30 deletions src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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<String>()

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<String>) {
ApplicationManager.getApplication().invokeLater {
val notification = NotificationGroupManager.getInstance()
.getNotificationGroup("Mold")
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -181,4 +209,4 @@ class CodeStyleSyncActivity : ProjectActivity {
""".trimIndent()
editorFile.writeText(content)
}
}
}