Class EnvVariablesVar


public class EnvVariablesVar extends DefaultingVar
Environment variable variable resolver.

The format for this var is "$E{envVar[,defaultValue]}".

Example:

// Create a variable resolver that resolves environment variables (e.g. "$E{PATH}") VarResolver varResolver = VarResolver.create().vars(EnvVariablesVar.class).build(); // Use it! System.out.println(varResolver.resolve("Environment variable PATH is set to $E{PATH}"));

Since this is a SimpleVar, any variables contained in the result will be recursively resolved.
Likewise, if the arguments contain any variables, those will be resolved before they are passed to this var.

See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • resolve

      public String resolve(VarResolverSession session, String varVal)
      Description copied from class: Var
      The interface that needs to be implemented for subclasses of SimpleVar.
      Specified by:
      resolve in class Var
      Parameters:
      session - The session object used for a single instance of a var resolution.
      varVal - The inside argument of the variable.
      Returns:
      The resolved value.
    • isStable

      protected boolean isStable()
      Process environment variables are immutable for the lifetime of the JVM, so this var opts in to compile-time stable-value folding.

      Compiled templates resolve $E{...} references once at compile time and replace them with literal segments — the runtime dispatch is eliminated.

      Overrides:
      isStable in class Var
      Returns:
      Always true.