generated from JetBrains/intellij-platform-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
212 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
modules/core/src/main/kotlin/com/github/l34130/mise/commands/MiseCmd.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.github.l34130.mise.commands | ||
|
||
import com.github.l34130.mise.extensions.fromJson | ||
import com.github.l34130.mise.notifications.Notification | ||
import com.google.gson.FieldNamingPolicy | ||
import com.google.gson.Gson | ||
import com.google.gson.GsonBuilder | ||
import com.intellij.execution.configurations.GeneralCommandLine | ||
import com.intellij.notification.NotificationType | ||
|
||
object MiseCmd { | ||
fun loadEnv(workDir: String?): Map<String, String> { | ||
try { | ||
val process = | ||
GeneralCommandLine("mise", "env") | ||
.withWorkDirectory(workDir) | ||
.createProcess() | ||
|
||
val exitCode = process.waitFor() | ||
if (exitCode != 0) { | ||
val stderr = process.errorReader().use { it.readText() } | ||
Notification.notify("Failed to import Mise environment: $stderr", NotificationType.WARNING) | ||
return emptyMap() | ||
} | ||
|
||
val output = process.inputReader().use { it.readText() } | ||
return output | ||
.split("\n") | ||
.map { it.removePrefix("export ") } | ||
.filter { it.isNotBlank() } | ||
.map { it.split("=", limit = 2) } | ||
.associate { it[0] to it[1] } | ||
} catch (e: Exception) { | ||
Notification.notify("Failed to import Mise environment: ${e.message}", NotificationType.ERROR) | ||
return emptyMap() | ||
} | ||
} | ||
|
||
fun loadTools(workDir: String?): Map<String, List<MiseTool>> { | ||
try { | ||
val process = | ||
GeneralCommandLine("mise", "ls", "--current", "--json") | ||
.withWorkDirectory(workDir) | ||
.createProcess() | ||
|
||
val exitCode = process.waitFor() | ||
if (exitCode != 0) { | ||
val stderr = process.errorReader().use { it.readText() } | ||
Notification.notify("Failed to import Mise tools: $stderr", NotificationType.WARNING) | ||
return emptyMap() | ||
} | ||
|
||
return GsonBuilder() | ||
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) | ||
.create() | ||
.fromJson<Map<String, List<MiseTool>>>(process.inputReader()) | ||
} catch (e: Exception) { | ||
Notification.notify("Failed to import Mise tools: ${e.message}", NotificationType.ERROR) | ||
return emptyMap() | ||
} | ||
} | ||
} |
50 changes: 0 additions & 50 deletions
50
modules/core/src/main/kotlin/com/github/l34130/mise/commands/MiseEnvCmd.kt
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
modules/core/src/main/kotlin/com/github/l34130/mise/commands/MiseSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.github.l34130.mise.commands | ||
|
||
data class MiseSource( | ||
val type: String, // .mise.toml, .mise.config, etc. | ||
val path: String, // absolute path to the source file | ||
) |
10 changes: 10 additions & 0 deletions
10
modules/core/src/main/kotlin/com/github/l34130/mise/commands/MiseTool.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.github.l34130.mise.commands | ||
|
||
data class MiseTool( | ||
val version: String, | ||
val requestedVersion: String, | ||
val installPath: String, | ||
val source: MiseSource, | ||
val installed: Boolean, | ||
val active: Boolean, | ||
) |
20 changes: 20 additions & 0 deletions
20
modules/core/src/main/kotlin/com/github/l34130/mise/extensions/GsonExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.github.l34130.mise.extensions | ||
|
||
import com.google.gson.Gson | ||
import com.google.gson.JsonElement | ||
import com.google.gson.reflect.TypeToken | ||
import com.google.gson.stream.JsonReader | ||
import java.io.Reader | ||
|
||
|
||
inline fun <reified T> Gson.fromJson(json: String) = | ||
fromJson<T>(json, object : TypeToken<T>() {}.type) | ||
|
||
inline fun <reified T> Gson.fromJson(json: Reader) = | ||
fromJson<T>(json, object : TypeToken<T>() {}.type) | ||
|
||
inline fun <reified T> Gson.fromJson(reader: JsonReader) = | ||
fromJson<T>(reader, object : TypeToken<T>() {}.type) | ||
|
||
inline fun <reified T> Gson.fromJson(json: JsonElement) = | ||
fromJson<T>(json, object : TypeToken<T>() {}.type) |
8 changes: 8 additions & 0 deletions
8
modules/core/src/main/kotlin/com/github/l34130/mise/icons/PluginIcons.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.l34130.mise.icons | ||
|
||
import com.intellij.openapi.util.IconLoader | ||
|
||
object PluginIcons { | ||
@JvmField | ||
val Default = IconLoader.getIcon("/icons/default.svg", javaClass) | ||
} |
19 changes: 19 additions & 0 deletions
19
modules/core/src/main/kotlin/com/github/l34130/mise/notifications/Notification.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.l34130.mise.notifications | ||
|
||
import com.github.l34130.mise.icons.PluginIcons | ||
import com.intellij.notification.NotificationGroupManager | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.openapi.project.Project | ||
|
||
object Notification { | ||
fun notify(content :String, type: NotificationType, project: Project? = null) { | ||
val notification = NotificationGroupManager.getInstance() | ||
.getNotificationGroup(NOTIFICATION_GROUP_ID) | ||
.createNotification(content, type) | ||
|
||
notification.icon = PluginIcons.Default | ||
notification.notify(project) | ||
} | ||
|
||
private const val NOTIFICATION_GROUP_ID = "Mise" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
modules/products/idea/src/main/kotlin/com/github/l34130/mise/jdk/IdeaProjectJdkSetup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.github.l34130.mise.jdk | ||
|
||
import com.github.l34130.mise.commands.MiseCmd | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.application.WriteAction | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.projectRoots.JavaSdk | ||
import com.intellij.openapi.projectRoots.ProjectJdkTable | ||
import com.intellij.openapi.roots.ProjectRootManager | ||
import com.intellij.openapi.startup.StartupActivity | ||
|
||
class IdeaProjectJdkSetup : AnAction(), StartupActivity { | ||
override fun actionPerformed(e: AnActionEvent) { | ||
e.project?.let { runActivity(it) } | ||
} | ||
|
||
override fun runActivity(project: Project) { | ||
val javaTools = MiseCmd.loadTools(project.basePath)["java"] ?: return | ||
|
||
WriteAction.runAndWait<Throwable> { | ||
for (tool in javaTools) { | ||
val jdkName = createJdkName(project.name) | ||
val newJdk = | ||
JavaSdk.getInstance().createJdk( | ||
jdkName, | ||
tool.installPath, | ||
false, | ||
) | ||
|
||
val oldJdk = ProjectJdkTable.getInstance().findJdk(jdkName) | ||
if (oldJdk != null) { | ||
ProjectJdkTable.getInstance().updateJdk(oldJdk, newJdk) | ||
} else { | ||
ProjectJdkTable.getInstance().addJdk(newJdk) | ||
} | ||
|
||
if (javaTools.size == 1) { | ||
ProjectRootManager.getInstance(project).projectSdk = newJdk | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun createJdkName(name: String): String = "JDK of project $name (mise)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,23 @@ | ||
<idea-plugin> | ||
<extensions defaultExtensionNs="com.intellij"> | ||
<postStartupActivity implementation="com.github.l34130.mise.jdk.IdeaProjectJdkSetup"/> | ||
|
||
<runConfigurationExtension implementation="com.github.l34130.mise.runconfigs.IdeaRunConfigurationExtension" | ||
id="miseIdea"/> | ||
</extensions> | ||
|
||
<actions> | ||
<group id="ch.mise.actions" | ||
text="Mise" | ||
popup="true" | ||
icon="com.github.l34130.mise.icons.PluginIcons.Default"> | ||
<add-to-group group-id="ToolsMenu"/> | ||
</group> | ||
<action id="com.github.l34130.mise.jdk.IdeaProjectJdkSetup" | ||
class="com.github.l34130.mise.jdk.IdeaProjectJdkSetup" | ||
text="Reload JDK" | ||
> | ||
<add-to-group group-id="ch.mise.actions"/> | ||
</action> | ||
</actions> | ||
</idea-plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.