Class SystemPropertiesVar


public class SystemPropertiesVar extends DefaultingVar
System property variable resolver.

The format for this var is "$S{systemProperty[,defaultValue]}"

Example:

// Create a variable resolver that resolves system properties (e.g. "$S{java.home}") VarResolver varResolver = VarResolver.create().vars(SystemPropertiesVar.class).build(); // Use it! System.out.println(varResolver.resolve("java.home is set to $S{java.home}"));

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 key)
      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.
      key - The inside argument of the variable.
      Returns:
      The resolved value.
    • isStable

      protected boolean isStable()
      System properties are mutable in principle (via System.setProperty(java.lang.String, java.lang.String)) but treated as stable in normal application code. This var opts in to compile-time stable-value folding.
      Caveat:

      If a deployment relies on System.setProperty(java.lang.String, java.lang.String) mutations after VarResolver build, those mutations will not be picked up by templates that were compiled before the mutation. Either re-build the resolver after the property change, or override this method to return false via a subclass.

      Overrides:
      isStable in class Var
      Returns:
      Always true for the default implementation.