All Downloads are FREE. Search and download functionalities are using the official Maven repository.

util.EnvironmentVariableTool Maven / Gradle / Ivy

There is a newer version: 20240707
Show newest version

package util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;



public class EnvironmentVariableTool {
  private static final Pattern environmentVariablePattern = Pattern.compile("\\$\\{.*\\}");
  
  public static String replace(String originalPath){
    String value = originalPath;
    Matcher m = environmentVariablePattern.matcher(originalPath);
    while (m.find()) {
      String envVar = m.group(); 
      String envValue = System.getenv(envVar.substring(2, envVar.length()-1));
      if (envValue != null) {
          value = value.replace(envVar, envValue);
      }
    }
    return value;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy