-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRunAnythingConfigurationOptions.kt
More file actions
90 lines (76 loc) · 3.01 KB
/
Copy pathRunAnythingConfigurationOptions.kt
File metadata and controls
90 lines (76 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright 2022 A Veenstra
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.aveenstra.runAnything
import com.intellij.execution.configuration.EnvironmentVariablesData
import com.intellij.execution.configurations.RunConfigurationOptions
import com.intellij.execution.configurations.RuntimeConfigurationException
import com.intellij.openapi.options.ConfigurationException
import com.intellij.util.xmlb.annotations.OptionTag
import com.jetbrains.rd.util.put
class RunAnythingConfigurationOptions : RunConfigurationOptions() {
@get:OptionTag
var command by string("")
@get:OptionTag
var arguments by string("")
@get:OptionTag
var workingDirectory by string("")
@get:OptionTag
var environmentVariables by map<String, String>()
@get:OptionTag
var isPassParentEnvs by property(true)
@get:OptionTag
var inputEnabled by property(false)
@get:OptionTag
var inputText by string("")
@get:OptionTag
var inputClose by property(true)
@Throws(ConfigurationException::class)
fun validateCommand(command: String?) {
if (command.isNullOrBlank()) {
throw ConfigurationException("No command given")
}
}
@set:Throws(ConfigurationException::class)
var environmentVariablesData: EnvironmentVariablesData
get() = EnvironmentVariablesData.create(environmentVariables, isPassParentEnvs)
set(environmentVariablesData) {
environmentVariables = validateEnvironmentVariables(environmentVariablesData.envs)
isPassParentEnvs = environmentVariablesData.isPassParentEnvs
}
@Throws(ConfigurationException::class)
fun validateEnvironmentVariables(newEnvironment: Map<String, String>): MutableMap<String, String> {
val result = HashMap<String, String>(newEnvironment.size)
for (entry in newEnvironment.entries) {
if (entry.key.isBlank()) {
throw ConfigurationException("Empty environment keys are not allowed")
}
result.put(entry)
}
return result
}
@Throws(RuntimeConfigurationException::class)
fun validateAll() {
try {
validateCommand(command)
validateEnvironmentVariables(environmentVariables)
} catch (e: ConfigurationException) {
val newE = RuntimeConfigurationException(e.message, e.title)
newE.originator = e.originator
newE.stackTrace = e.stackTrace
throw newE
}
}
}