1717import com .intellij .openapi .project .Project ;
1818import com .intellij .openapi .project .ProjectUtil ;
1919import com .intellij .openapi .ui .DialogWrapper ;
20+ import com .intellij .openapi .util .text .StringUtil ;
2021import com .intellij .openapi .vfs .VirtualFile ;
2122import com .intellij .ui .components .JBLabel ;
2223import com .intellij .ui .components .JBTextField ;
24+ import com .intellij .util .EnvironmentUtil ;
2325import com .intellij .util .ui .FormBuilder ;
2426import io .github .cdimascio .dotenv .Dotenv ;
2527import io .github .cdimascio .dotenv .DotenvBuilder ;
2628import org .jetbrains .annotations .NotNull ;
2729import org .jetbrains .annotations .Nullable ;
30+ import org .jetbrains .annotations .VisibleForTesting ;
2831
2932import javax .swing .*;
3033import java .util .Arrays ;
3942 */
4043public class GraphQLConfigVariableAwareEndpoint {
4144
45+ @ VisibleForTesting
4246 Function <String , String > GET_ENV_VAR = System ::getProperty ;
4347
4448 private final static Pattern ENV_PATTERN = Pattern .compile ("\\ $\\ {(?<var>[^}]*)}" );
@@ -92,7 +96,7 @@ public String expandVariables(String rawValue) {
9296
9397 Matcher matcher = ENV_PATTERN .matcher (rawValue );
9498
95- StringBuffer sb = new StringBuffer (rawValue .length ());
99+ StringBuilder sb = new StringBuilder (rawValue .length ());
96100 while (matcher .find ()) {
97101 String var = matcher .group (1 );
98102 String [] parts = var .split (":" );
@@ -117,16 +121,17 @@ public String expandVariables(String rawValue) {
117121 continue ;
118122 }
119123
120- // Try to load the variable from the system
124+ // Try to load the variable from the jvm parameters
121125 String varValue = GET_ENV_VAR .apply (varName );
122-
123126 // 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 )) {
125128 varValue = tryToGetVariableFromDotEnvFile (varName );
126129 }
127-
130+ if (StringUtil .isEmptyOrSpaces (varValue )) {
131+ varValue = EnvironmentUtil .getValue (varName );
132+ }
128133 // 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 )) {
130135 final VariableDialog dialog = new VariableDialog (project , varName );
131136 if (dialog .showAndGet ()) {
132137 varValue = dialog .getValue ();
0 commit comments