17
17
import com .intellij .openapi .project .Project ;
18
18
import com .intellij .openapi .project .ProjectUtil ;
19
19
import com .intellij .openapi .ui .DialogWrapper ;
20
+ import com .intellij .openapi .util .text .StringUtil ;
20
21
import com .intellij .openapi .vfs .VirtualFile ;
21
22
import com .intellij .ui .components .JBLabel ;
22
23
import com .intellij .ui .components .JBTextField ;
24
+ import com .intellij .util .EnvironmentUtil ;
23
25
import com .intellij .util .ui .FormBuilder ;
24
26
import io .github .cdimascio .dotenv .Dotenv ;
25
27
import io .github .cdimascio .dotenv .DotenvBuilder ;
26
28
import org .jetbrains .annotations .NotNull ;
27
29
import org .jetbrains .annotations .Nullable ;
30
+ import org .jetbrains .annotations .VisibleForTesting ;
28
31
29
32
import javax .swing .*;
30
33
import java .util .Arrays ;
39
42
*/
40
43
public class GraphQLConfigVariableAwareEndpoint {
41
44
45
+ @ VisibleForTesting
42
46
Function <String , String > GET_ENV_VAR = System ::getProperty ;
43
47
44
48
private final static Pattern ENV_PATTERN = Pattern .compile ("\\ $\\ {(?<var>[^}]*)}" );
@@ -92,7 +96,7 @@ public String expandVariables(String rawValue) {
92
96
93
97
Matcher matcher = ENV_PATTERN .matcher (rawValue );
94
98
95
- StringBuffer sb = new StringBuffer (rawValue .length ());
99
+ StringBuilder sb = new StringBuilder (rawValue .length ());
96
100
while (matcher .find ()) {
97
101
String var = matcher .group (1 );
98
102
String [] parts = var .split (":" );
@@ -117,16 +121,17 @@ public String expandVariables(String rawValue) {
117
121
continue ;
118
122
}
119
123
120
- // Try to load the variable from the system
124
+ // Try to load the variable from the jvm parameters
121
125
String varValue = GET_ENV_VAR .apply (varName );
122
-
123
126
// If the variable wasn't found in the system try to see if the user has a .env file with the variable
124
- if (varValue == null || varValue . trim (). isEmpty ( )) {
127
+ if (StringUtil . isEmptyOrSpaces ( varValue )) {
125
128
varValue = tryToGetVariableFromDotEnvFile (varName );
126
129
}
127
-
130
+ if (StringUtil .isEmptyOrSpaces (varValue )) {
131
+ varValue = EnvironmentUtil .getValue (varName );
132
+ }
128
133
// If it still wasn't found present the user with a dialog to enter the variable
129
- if (varValue == null || varValue . trim (). isEmpty ( )) {
134
+ if (StringUtil . isEmptyOrSpaces ( varValue )) {
130
135
final VariableDialog dialog = new VariableDialog (project , varName );
131
136
if (dialog .showAndGet ()) {
132
137
varValue = dialog .getValue ();
0 commit comments