Skip to content

Commit

Permalink
Rename profile to configEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
134130 committed Dec 8, 2024
1 parent 144e92b commit 4a2c92c
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private val LOG = Logger.getInstance(MiseCommandLine::class.java)

internal class MiseCommandLine(
private val workDir: String? = null,
private val miseEnv: String? = null,
private val configEnvironment: String? = null,
) {
inline fun <reified T> runCommandLine(vararg params: String): Result<T> =

Check warning on line 17 in modules/core/src/main/kotlin/com/github/l34130/mise/core/command/MiseCommandLine.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "runCommandLine" is never used
runCommandLine(params.toList())
Expand All @@ -22,13 +22,13 @@ internal class MiseCommandLine(

val commandLineArgs = mutableListOf("mise")

if (miseEnv != null) {
if (configEnvironment != null) {
if (miseVersion >= MiseVersion(2024, 12, 2)) {
commandLineArgs.add("--env")
commandLineArgs.add(miseEnv)
commandLineArgs.add(configEnvironment)
} else {
commandLineArgs.add("--profile")
commandLineArgs.add(miseEnv)
commandLineArgs.add(configEnvironment)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package com.github.l34130.mise.core.command

object MiseCommandLineHelper {
// mise env
fun getEnvVars(workDir: String?, profile: String?): Result<Map<String, String>> {
fun getEnvVars(workDir: String?, configEnvironment: String?): Result<Map<String, String>> {
val commandLineArgs = mutableListOf("env", "--json")

val miseCommandLine = MiseCommandLine(workDir, profile)
val miseCommandLine = MiseCommandLine(workDir, configEnvironment)
return miseCommandLine.runCommandLine(commandLineArgs)
}

// mise ls
fun getDevTools(workDir: String?, profile: String?): Result<Map<MiseDevToolName, List<MiseDevTool>>> {
fun getDevTools(workDir: String?, configEnvironment: String?): Result<Map<MiseDevToolName, List<MiseDevTool>>> {
val commandLineArgs = mutableListOf("ls", "--current", "--json")

val miseVersion = MiseCommandLine.getMiseVersion()
Expand All @@ -21,18 +21,18 @@ object MiseCommandLineHelper {
commandLineArgs.add("--offline")
}

val miseCommandLine = MiseCommandLine(workDir, profile)
val miseCommandLine = MiseCommandLine(workDir, configEnvironment)
return miseCommandLine.runCommandLine<Map<String, List<MiseDevTool>>>(commandLineArgs)
.map { devTools ->
devTools.mapKeys { (toolName, _) -> MiseDevToolName(toolName) }
}
}

// mise task ls
fun getTasks(workDir: String?, profile: String?): Result<List<MiseTask>> {
fun getTasks(workDir: String?, configEnvironment: String?): Result<List<MiseTask>> {
val commandLineArgs = mutableListOf("task", "ls", "--json")

val miseCommandLine = MiseCommandLine(workDir, profile)
val miseCommandLine = MiseCommandLine(workDir, configEnvironment)
return miseCommandLine.runCommandLine(commandLineArgs)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.intellij.openapi.project.Project

class MiseRunTaskOnTerminalAction(
private val taskName: String,
private val profile: String? = null,
private val configEnvironment: String? = null,
) : DumbAwareAction(
"Run Mise Task",
"Execute the Mise task on Terminal",
Expand All @@ -22,7 +22,7 @@ class MiseRunTaskOnTerminalAction(
return
}

executeTask(project, taskName, profile)
executeTask(project, taskName, configEnvironment)
}

companion object {
Expand All @@ -31,12 +31,12 @@ class MiseRunTaskOnTerminalAction(
fun executeTask(
project: Project,
taskName: String,
profile: String? = null,
configEnvironment: String? = null,
) {
val command =
buildString {
append("mise run")
profile?.let { append(" --profile '$it'") }
configEnvironment?.let { append(" --profile '$it'") } // TODO: Handle mise config environment
append(" '$taskName'")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MiseRunConfigurationSettingsEditor<T : RunConfigurationBase<*>>(
private val project: Project,
) : SettingsEditor<T>() {
private val myMiseDirEnvCb = JBCheckBox("Use environment variables from mise")
private val myMiseProfileTf = JBTextField()
private val myMiseConfigEnvironmentTf = JBTextField()

override fun createEditor(): JComponent {
val projectState = MiseSettings.getService(project).state
Expand All @@ -42,8 +42,8 @@ class MiseRunConfigurationSettingsEditor<T : RunConfigurationBase<*>>(
cell(myMiseDirEnvCb)
.comment("Load environment variables from mise configuration file(s)")
}.enabled(isOverridden.not())
row("Profile: ") {
cell(myMiseProfileTf)
row("Config Environment:") {
cell(myMiseConfigEnvironmentTf)
.comment(
"""
Specify the mise configuration environment to use (leave empty for default) <br/>
Expand All @@ -68,7 +68,7 @@ class MiseRunConfigurationSettingsEditor<T : RunConfigurationBase<*>>(
USER_DATA_KEY,
MiseRunConfigurationState(
useMiseDirEnv = myMiseDirEnvCb.isSelected,
miseProfile = myMiseProfileTf.text,
miseConfigEnvironment = myMiseConfigEnvironmentTf.text,
),
)
}
Expand All @@ -80,14 +80,14 @@ class MiseRunConfigurationSettingsEditor<T : RunConfigurationBase<*>>(
val state = userData.mergeProjectState(projectState)

myMiseDirEnvCb.isSelected = state.useMiseDirEnv
myMiseProfileTf.text = state.miseProfile
myMiseConfigEnvironmentTf.text = state.miseConfigEnvironment
if (!myMiseDirEnvCb.isSelected) {
myMiseProfileTf.isEnabled = false
myMiseConfigEnvironmentTf.isEnabled = false
}

if (projectState.useMiseDirEnv) {
myMiseDirEnvCb.isEnabled = false
myMiseProfileTf.isEnabled = false
myMiseConfigEnvironmentTf.isEnabled = false
}
}

Expand All @@ -100,11 +100,11 @@ class MiseRunConfigurationSettingsEditor<T : RunConfigurationBase<*>>(
element: Element,
) {
val miseDirEnvCb = element.getAttributeValue("myMiseDirEnvCb")?.toBoolean() ?: false
val miseProfile = element.getAttributeValue("myMiseProfileTf") ?: ""
val miseConfigEnvironment = element.getAttributeValue("myMiseConfigEnvironmentTf") ?: ""
val state =
MiseRunConfigurationState(
useMiseDirEnv = miseDirEnvCb,
miseProfile = miseProfile,
miseConfigEnvironment = miseConfigEnvironment,
)
runConfiguration.putCopyableUserData(USER_DATA_KEY, state)
}
Expand All @@ -116,7 +116,7 @@ class MiseRunConfigurationSettingsEditor<T : RunConfigurationBase<*>>(
val userData = runConfiguration.getCopyableUserData(USER_DATA_KEY) ?: return

element.setAttribute("myMiseDirEnvCb", userData.useMiseDirEnv.toString())
element.setAttribute("myMiseProfileTf", userData.miseProfile)
element.setAttribute("myMiseConfigEnvironmentTf", userData.miseConfigEnvironment)
}

fun getMiseRunConfigurationState(configuration: RunConfigurationBase<*>): MiseRunConfigurationState? =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import com.github.l34130.mise.core.setting.MiseState

data class MiseRunConfigurationState(
var useMiseDirEnv: Boolean = true,
var miseProfile: String = "",
var miseConfigEnvironment: String = "",
) : Cloneable {
public override fun clone() =
MiseRunConfigurationState(
useMiseDirEnv = useMiseDirEnv,
miseProfile = miseProfile,
miseConfigEnvironment = miseConfigEnvironment,
)

fun mergeProjectState(projectState: MiseState): MiseRunConfigurationState =
this.copy(
useMiseDirEnv = projectState.useMiseDirEnv,
miseProfile = projectState.miseProfile,
miseConfigEnvironment = projectState.miseConfigEnvironment,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class MiseConfigurable(
private val project: Project,
) : SearchableConfigurable {
private val myMiseDirEnvCb = JBCheckBox("Use environment variables from mise")
private val myMiseProfileTf = JBTextField()
private val myMiseConfigEnvironmentTf = JBTextField()

override fun getDisplayName(): String = "Mise Settings"

override fun createComponent(): JComponent {
val service = MiseSettings.getService(project)

myMiseDirEnvCb.isSelected = service.state.useMiseDirEnv
myMiseProfileTf.text = service.state.miseProfile
myMiseConfigEnvironmentTf.text = service.state.miseConfigEnvironment

return JPanel(BorderLayout()).apply {
add(
Expand Down Expand Up @@ -56,8 +56,8 @@ class MiseConfigurable(
"Load environment variables from mise configuration file(s)",
)
}
row("Profile:") {
cell(myMiseProfileTf)
row("Config Environment:") {
cell(myMiseConfigEnvironmentTf)
.comment(
"""
Specify the mise configuration environment to use (leave empty for default) <br/>
Expand All @@ -76,14 +76,14 @@ class MiseConfigurable(
override fun isModified(): Boolean {
val service = MiseSettings.getService(project)
return myMiseDirEnvCb.isSelected != service.state.useMiseDirEnv ||
myMiseProfileTf.text != service.state.miseProfile
myMiseConfigEnvironmentTf.text != service.state.miseConfigEnvironment
}

override fun apply() {
if (isModified) {
val service = MiseSettings.getService(project)
service.state.useMiseDirEnv = myMiseDirEnvCb.isSelected
service.state.miseProfile = myMiseProfileTf.text
service.state.miseConfigEnvironment = myMiseConfigEnvironmentTf.text
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import java.io.File
data class MiseState(
var executablePath: String = "",
var useMiseDirEnv: Boolean = true,
var miseProfile: String = "",
var miseConfigEnvironment: String = "",
) : Cloneable {
public override fun clone(): MiseState =
MiseState(
executablePath = executablePath,
useMiseDirEnv = useMiseDirEnv,
miseProfile = miseProfile,
miseConfigEnvironment = miseConfigEnvironment,
)
}

Expand All @@ -50,7 +50,7 @@ class MiseSettings(
state = MiseState(
executablePath = state.executablePath.takeIf { it.isNotEmpty() } ?: getMiseExecutablePath() ?: "",
useMiseDirEnv = state.useMiseDirEnv,
miseProfile = state.miseProfile,
miseConfigEnvironment = state.miseConfigEnvironment,
)

if (state.executablePath.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ abstract class AbstractProjectSdkSetup :
val devToolName = getDevToolName()
val miseNotificationService = project.service<MiseNotificationService>()

val profile = MiseSettings.getService(project).state.miseProfile
val toolsResult = MiseCommandLineHelper.getDevTools(workDir = project.basePath, profile = profile)
val configEnvironment = MiseSettings.getService(project).state.miseConfigEnvironment
val toolsResult =
MiseCommandLineHelper.getDevTools(workDir = project.basePath, configEnvironment = configEnvironment)
val tools = toolsResult.fold(
onSuccess = { tools -> tools[devToolName] },
onFailure = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MiseRootNode(
private fun getToolNodes(settings: MiseSettings): Collection<MiseToolConfigDirectoryNode> {
val toolsByToolNames = MiseCommandLineHelper.getDevTools(
workDir = nodeProject.basePath,
profile = settings.state.miseProfile
configEnvironment = settings.state.miseConfigEnvironment
).fold(
onSuccess = { tools -> tools },
onFailure = {
Expand Down Expand Up @@ -62,7 +62,7 @@ class MiseRootNode(
private fun getEnvironmentNodes(settings: MiseSettings): Collection<MiseEnvironmentNode> {
val envs = MiseCommandLineHelper.getEnvVars(
workDir = nodeProject.basePath,
profile = settings.state.miseProfile
configEnvironment = settings.state.miseConfigEnvironment
).fold(
onSuccess = { envs -> envs },
onFailure = {
Expand All @@ -85,7 +85,7 @@ class MiseRootNode(
private fun getTaskNodes(settings: MiseSettings): Collection<MiseTaskNode> {
val tasks = MiseCommandLineHelper.getTasks(
workDir = nodeProject.basePath,
profile = settings.state.miseProfile
configEnvironment = settings.state.miseConfigEnvironment
).fold(
onSuccess = { tasks -> tasks },
onFailure = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class GoLandRunConfigurationExtension : GoRunConfigurationExtension() {
val projectState = project.service<MiseSettings>().state
val runConfigState = MiseRunConfigurationSettingsEditor.getMiseRunConfigurationState(configuration)

val (workDir, profile) = when {
projectState.useMiseDirEnv -> project.basePath to projectState.miseProfile
runConfigState?.useMiseDirEnv == true -> configuration.getWorkingDirectory() to runConfigState.miseProfile
val (workDir, configEnvironment) = when {
projectState.useMiseDirEnv -> project.basePath to projectState.miseConfigEnvironment
runConfigState?.useMiseDirEnv == true -> configuration.getWorkingDirectory() to runConfigState.miseConfigEnvironment
else -> return
}

MiseCommandLineHelper.getEnvVars(workDir, profile)
MiseCommandLineHelper.getEnvVars(workDir, configEnvironment)
.fold(
onSuccess = { envVars -> envVars },
onFailure = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ class GradleEnvironmentProvider : GradleExecutionEnvironmentProvider {
val projectState = project.service<MiseSettings>().state
val runConfigState = MiseRunConfigurationSettingsEditor.getMiseRunConfigurationState(gradleRunConfiguration)

val (workDir, profile) = when {
projectState.useMiseDirEnv -> project.basePath to projectState.miseProfile
val (workDir, configEnvironment) = when {
projectState.useMiseDirEnv -> project.basePath to projectState.miseConfigEnvironment
runConfigState?.useMiseDirEnv == true -> {
val sourceConfig = task.runProfile as ApplicationConfiguration
sourceConfig.project.basePath to runConfigState.miseProfile
sourceConfig.project.basePath to runConfigState.miseConfigEnvironment
}

else -> return environment
}

val miseEnvVars = MiseCommandLineHelper.getEnvVars(workDir, profile)
val miseEnvVars = MiseCommandLineHelper.getEnvVars(workDir, configEnvironment)
.fold(
onSuccess = { envVars -> envVars },
onFailure = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class IdeaRunConfigurationExtension : RunConfigurationExtension() {
val projectState = project.service<MiseSettings>().state
val runConfigState = MiseRunConfigurationSettingsEditor.getMiseRunConfigurationState(configuration)

val (workDir, profile) = when {
projectState.useMiseDirEnv -> project.basePath to projectState.miseProfile
runConfigState?.useMiseDirEnv == true -> params.workingDirectory to runConfigState.miseProfile
val (workDir, configEnvironment) = when {
projectState.useMiseDirEnv -> project.basePath to projectState.miseConfigEnvironment
runConfigState?.useMiseDirEnv == true -> params.workingDirectory to runConfigState.miseConfigEnvironment
else -> return
}

val envVars = MiseCommandLineHelper.getEnvVars(workDir, profile)
val envVars = MiseCommandLineHelper.getEnvVars(workDir, configEnvironment)
.fold(
onSuccess = { envVars -> envVars },
onFailure = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ class NodeRunConfigurationExtension : AbstractNodeRunConfigurationExtension() {
val projectState = project.service<MiseSettings>().state
val runConfigState = MiseRunConfigurationSettingsEditor.getMiseRunConfigurationState(configuration)

val (workDir, profile) =
val (workDir, configEnvironment) =
when {
projectState.useMiseDirEnv -> project.basePath to projectState.miseProfile
runConfigState?.useMiseDirEnv == true -> environment.modulePath to runConfigState.miseProfile
projectState.useMiseDirEnv -> project.basePath to projectState.miseConfigEnvironment
runConfigState?.useMiseDirEnv == true -> environment.modulePath to runConfigState.miseConfigEnvironment
else -> return null
}

return object : NodeRunConfigurationLaunchSession() {
override fun addNodeOptionsTo(targetRun: NodeTargetRun) {
val envVars = MiseCommandLineHelper.getEnvVars(workDir, profile)
val envVars = MiseCommandLineHelper.getEnvVars(workDir, configEnvironment)
.fold(
onSuccess = { envVars -> envVars },
onFailure = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class RiderPatchCommandLineExtension : PatchCommandLineExtension {

val miseEnvVars = MiseCommandLineHelper.getEnvVars(
workDir = project.solutionDirectoryPath.toAbsolutePath().toString(),
profile = projectState.miseProfile
configEnvironment = projectState.miseConfigEnvironment
).fold(
onSuccess = { envVars -> envVars },
onFailure = {
Expand Down
Loading

0 comments on commit 4a2c92c

Please sign in to comment.