Skip to content

Commit 1e049e0

Browse files
committed
mise direnv support
1 parent 69bee5a commit 1e049e0

File tree

33 files changed

+569
-188
lines changed

33 files changed

+569
-188
lines changed

.idea/gradle.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.run/Run Plugin.run.xml

+13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@
1818
</ExternalSystemSettings>
1919
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
2020
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
21+
<EXTENSION ID="com.intellij.execution.ExternalSystemRunConfigurationJavaExtension">
22+
<extension name="net.ashald.envfile">
23+
<option name="IS_ENABLED" value="false" />
24+
<option name="IS_SUBST" value="false" />
25+
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
26+
<option name="IS_IGNORE_MISSING_FILES" value="false" />
27+
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
28+
<ENTRIES>
29+
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" />
30+
</ENTRIES>
31+
</extension>
32+
</EXTENSION>
2133
<DebugAllEnabled>false</DebugAllEnabled>
34+
<RunAsTest>false</RunAsTest>
2235
<method v="2" />
2336
</configuration>
2437
</component>

.run/Run Qodana.run.xml

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717
</ExternalSystemSettings>
1818
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
1919
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
20+
<EXTENSION ID="com.intellij.execution.ExternalSystemRunConfigurationJavaExtension">
21+
<extension name="net.ashald.envfile">
22+
<option name="IS_ENABLED" value="false" />
23+
<option name="IS_SUBST" value="false" />
24+
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
25+
<option name="IS_IGNORE_MISSING_FILES" value="false" />
26+
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
27+
<ENTRIES>
28+
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" />
29+
</ENTRIES>
30+
</extension>
31+
</EXTENSION>
2032
<DebugAllEnabled>false</DebugAllEnabled>
2133
<RunAsTest>false</RunAsTest>
2234
<method v="2" />

build.gradle.kts

+59-22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import org.jetbrains.changelog.Changelog
22
import org.jetbrains.changelog.markdownToHTML
33

44
fun properties(key: String) = providers.gradleProperty(key)
5+
56
fun environment(key: String) = providers.environmentVariable(key)
67

78
plugins {
@@ -17,13 +18,23 @@ group = properties("pluginGroup").get()
1718
version = properties("pluginVersion").get()
1819

1920
// Configure project's dependencies
20-
repositories {
21-
mavenCentral()
21+
allprojects {
22+
group = group
23+
version = version
24+
25+
apply(plugin = "java")
26+
27+
repositories {
28+
mavenCentral()
29+
}
2230
}
2331

2432
// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
2533
dependencies {
26-
// implementation(libs.exampleLibrary)
34+
implementation(project(":mise-products-idea"))
35+
implementation(project(":mise-products-gradle"))
36+
implementation(project(":mise-products-goland"))
37+
implementation(project(":mise-products-nodejs"))
2738
}
2839

2940
// Set the JVM language level used to build the project.
@@ -38,7 +49,7 @@ intellij {
3849
type = properties("platformType")
3950

4051
// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
41-
plugins = properties("platformPlugins").map { it.split(',').map(String::trim).filter(String::isNotEmpty) }
52+
plugins.set("".split(',').map(String::trim).filter(String::isNotEmpty))
4253
}
4354

4455
// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
@@ -58,6 +69,30 @@ kover {
5869
}
5970
}
6071

72+
gradle.taskGraph.whenReady(
73+
closureOf<TaskExecutionGraph> {
74+
val ignoreSubprojectTasks =
75+
listOf(
76+
"buildSearchableOptions",
77+
"listProductsReleases",
78+
"patchPluginXml",
79+
"publishPlugin",
80+
"runIde",
81+
"runPluginVerifier",
82+
"verifyPlugin",
83+
)
84+
85+
// Don't run some tasks for subprojects
86+
for (task in allTasks) {
87+
if (task.project != task.project.rootProject) {
88+
when (task.name) {
89+
in ignoreSubprojectTasks -> task.enabled = false
90+
}
91+
}
92+
}
93+
},
94+
)
95+
6196
tasks {
6297
wrapper {
6398
gradleVersion = properties("gradleVersion").get()
@@ -69,30 +104,32 @@ tasks {
69104
untilBuild = properties("pluginUntilBuild")
70105

71106
// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
72-
pluginDescription = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
73-
val start = "<!-- Plugin description -->"
74-
val end = "<!-- Plugin description end -->"
75-
76-
with(it.lines()) {
77-
if (!containsAll(listOf(start, end))) {
78-
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
107+
pluginDescription =
108+
providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
109+
val start = "<!-- Plugin description -->"
110+
val end = "<!-- Plugin description end -->"
111+
112+
with(it.lines()) {
113+
if (!containsAll(listOf(start, end))) {
114+
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
115+
}
116+
subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML)
79117
}
80-
subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML)
81118
}
82-
}
83119

84120
val changelog = project.changelog // local variable for configuration cache compatibility
85121
// Get the latest available change notes from the changelog file
86-
changeNotes = properties("pluginVersion").map { pluginVersion ->
87-
with(changelog) {
88-
renderItem(
89-
(getOrNull(pluginVersion) ?: getUnreleased())
90-
.withHeader(false)
91-
.withEmptySections(false),
92-
Changelog.OutputType.HTML,
93-
)
122+
changeNotes =
123+
properties("pluginVersion").map { pluginVersion ->
124+
with(changelog) {
125+
renderItem(
126+
(getOrNull(pluginVersion) ?: getUnreleased())
127+
.withHeader(false)
128+
.withEmptySections(false),
129+
Changelog.OutputType.HTML,
130+
)
131+
}
94132
}
95-
}
96133
}
97134

98135
// Configure UI tests plugin

gradle.properties

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
22

3-
pluginGroup = com.github.134130.mise
3+
pluginGroup = com.github.l34130.mise
44
pluginName = mise
55
pluginRepositoryUrl = https://github.com/134130/mise
66
# SemVer format -> https://semver.org
77
pluginVersion = 0.0.1
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
10-
pluginSinceBuild = 232
11-
pluginUntilBuild = 242.*
10+
pluginSinceBuild = 223
11+
pluginUntilBuild = 299.*
1212

1313
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
14-
platformType = IC
15-
platformVersion = 2023.2.7
16-
17-
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
18-
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
19-
platformPlugins =
14+
platformType = IU
15+
platformVersion = 2022.3.3
2016

2117
# Gradle Releases -> https://github.com/gradle/gradle/releases
2218
gradleVersion = 8.8

modules/core/build.gradle.kts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fun properties(key: String) = project.findProperty(key).toString()
2+
3+
plugins {
4+
id("org.jetbrains.intellij")
5+
alias(libs.plugins.kotlin) // Kotlin support
6+
}
7+
8+
dependencies {
9+
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
10+
}
11+
12+
// Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
13+
intellij {
14+
version.set(properties("platformVersion"))
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.github.l34130.mise.commands
2+
3+
import com.intellij.execution.configurations.GeneralCommandLine
4+
import com.intellij.notification.Notification
5+
import com.intellij.notification.NotificationType
6+
import com.intellij.notification.Notifications
7+
8+
class MiseEnvCmd(
9+
private val workDir: String?,
10+
) {
11+
fun load(): Map<String, String> {
12+
try {
13+
val process =
14+
GeneralCommandLine("mise", "env")
15+
.withWorkDirectory(workDir)
16+
.createProcess()
17+
18+
val exitCode = process.waitFor()
19+
if (exitCode != 0) {
20+
val stderr = process.errorReader().use { it.readText() }
21+
Notifications.Bus.notify(
22+
Notification(
23+
GROUP_DISPLAY_ID,
24+
"Mise warning",
25+
"Failed to import Mise environment: $stderr",
26+
NotificationType.WARNING,
27+
),
28+
)
29+
return emptyMap()
30+
}
31+
32+
val output = process.inputReader().use { it.readText() }
33+
return output
34+
.split("\n")
35+
.map { it.removePrefix("export ") }
36+
.filter { it.isNotBlank() }
37+
.map { it.split("=", limit = 2) }
38+
.associate { it[0] to it[1] }
39+
} catch (e: Exception) {
40+
Notifications.Bus.notify(
41+
Notification(GROUP_DISPLAY_ID, "Mise error", "Failed to import Mise environment", NotificationType.ERROR),
42+
)
43+
return emptyMap()
44+
}
45+
}
46+
47+
companion object {
48+
private const val GROUP_DISPLAY_ID = "Mise"
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.l34130.mise.settings
2+
3+
data class MiseSettings(
4+
val miseEnabled: Boolean,
5+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.github.l34130.mise.settings.ui
2+
3+
import com.github.l34130.mise.settings.MiseSettings
4+
import com.intellij.execution.configurations.RunConfigurationBase
5+
import com.intellij.openapi.options.ConfigurationException
6+
import com.intellij.openapi.options.SettingsEditor
7+
import com.intellij.openapi.ui.panel.ComponentPanelBuilder
8+
import com.intellij.openapi.util.Key
9+
import org.jdom.Element
10+
import java.awt.BorderLayout
11+
import javax.swing.BoxLayout
12+
import javax.swing.JCheckBox
13+
import javax.swing.JComponent
14+
import javax.swing.JPanel
15+
16+
class RunConfigurationSettingsEditor<T : RunConfigurationBase<*>>(
17+
configuration: T,
18+
) : SettingsEditor<T>() {
19+
private val editor = RunConfigurationSettingsPanel(configuration)
20+
21+
override fun resetEditorFrom(config: T) {
22+
config.getCopyableUserData(USER_DATA_KEY)?.let {
23+
editor.state = it
24+
}
25+
}
26+
27+
@Throws(ConfigurationException::class)
28+
override fun applyEditorTo(config: T) {
29+
config.putCopyableUserData(USER_DATA_KEY, editor.state)
30+
}
31+
32+
override fun createEditor(): JComponent = editor
33+
34+
companion object {
35+
const val EDITOR_TITLE = "Mise"
36+
const val SERIALIZATION_ID = "com.github.l34130.mise"
37+
val USER_DATA_KEY: Key<MiseSettings> = Key("Mise Settings")
38+
39+
private const val FIELD_MISE_ENABLED = "MISE_ENABLED"
40+
41+
fun readExternal(
42+
runConfiguration: RunConfigurationBase<*>,
43+
element: Element,
44+
) {
45+
val miseEnabled = element.getAttributeValue(FIELD_MISE_ENABLED)?.toBoolean() ?: false
46+
runConfiguration.putCopyableUserData(USER_DATA_KEY, MiseSettings(miseEnabled))
47+
}
48+
49+
fun writeExternal(
50+
runConfiguration: RunConfigurationBase<*>,
51+
element: Element,
52+
) {
53+
runConfiguration.getCopyableUserData(USER_DATA_KEY)?.let { settings ->
54+
element.setAttribute(FIELD_MISE_ENABLED, settings.miseEnabled.toString())
55+
}
56+
}
57+
58+
fun isMiseEnabled(configuration: RunConfigurationBase<*>): Boolean =
59+
configuration.getCopyableUserData(USER_DATA_KEY)?.miseEnabled ?: false
60+
}
61+
62+
private class RunConfigurationSettingsPanel<T : RunConfigurationBase<*>>(
63+
private val configuration: T,
64+
) : JPanel() {
65+
private val useMiseCheckBox = JCheckBox("Enable Mise")
66+
67+
init {
68+
val boxLayoutWrapper = JPanel()
69+
val bl = BoxLayout(boxLayoutWrapper, BoxLayout.PAGE_AXIS)
70+
71+
boxLayoutWrapper.apply {
72+
layout = bl
73+
add(ComponentPanelBuilder(useMiseCheckBox).createPanel())
74+
}
75+
76+
layout = BorderLayout()
77+
add(boxLayoutWrapper, BorderLayout.NORTH)
78+
}
79+
80+
var state: MiseSettings
81+
get() = MiseSettings(useMiseCheckBox.isSelected)
82+
set(value) {
83+
useMiseCheckBox.isSelected = value.miseEnabled
84+
}
85+
}
86+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
fun properties(key: String) = project.findProperty(key).toString()
2+
3+
plugins {
4+
id("org.jetbrains.intellij")
5+
alias(libs.plugins.kotlin) // Kotlin support
6+
}
7+
8+
// Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
9+
intellij {
10+
version.set(properties("platformVersion"))
11+
type.set("GO")
12+
13+
// Plugin Dependencies
14+
plugins.set(listOf("org.jetbrains.plugins.go"))
15+
}
16+
17+
dependencies {
18+
implementation(project(":mise-core"))
19+
}

0 commit comments

Comments
 (0)