Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8351447

Make %APPDATA% and %LOCALAPPDATA% env variables available in *.cfg files

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 25
    • tools
    • None
    • behavioral
    • low
    • Values of parameters with character sequences that didn't have special handling until this change will be different. However, these character sequences (\\, \$, ${, $) are not commonly used, so most users should not be impacted.
    • Other
    • Implementation

      Summary

      Support expansion of environment variables in jpackage app launcher initialization parameters.

      Problem

      Initialization parameters for an application can depend on the properties, the exact values of which are unknown when building the application installer. The values of these properties are known at runtime. Currently, jpackage app launcher supports three such properties:

      • APPDIR - path to the directory with the application's configuration data;
      • BINDIR - path to directory with application launchers;
      • ROOTDIR - path to the root application directory.

      Suppose user runs jpackage with "--java-options -Dinit-file=$APPDIR/init.cfg" command line. In that case, the jpackage app launcher will set the "init-file" system property to the path of the "init.cfg" file by replacing $APPDIR token with the path to the application's configuration data.

      The set of expandable tokens jpackage recognizes is limited. It would be good if it could handle environment variables similarly. E.g., it would be good if for "--java-options -Dinit-file=$HOME/init.cfg" command line, jackage app launcher would replace $HOME substring with value of HOME environment variable.

      Solution

      Make a jackage app launcher to handle environment variables similarly to how it handles $APPDIR, $BINDIR, and $ROOTDIR tokens.

      Specification

      In addition to the $APPDIR, $BINDIR, and $ROOTDIR tokens, the jpackage app launcher will recognize $ENV_VAR_NAME and ${ENV_VAR_NAME} patterns.

      If $ENV_VAR_NAME syntax is used, the variable name will stop at the first character outside of [A-Za-z_][A-Za-z0-9_]* character range.

      If ${ENV_VAR_NAME} syntax is used, the variable name will stop at the first } character after ${ substring.

      E.g.:

      String Variables Variable Values Expanded String
      Welcome $USER! USER USER=John Welcome John!
      Welcome $USER2! USER2 USER2=John Welcome John!
      Welcome ${USER}2! USER USER=John Welcome John2!
      Welcome $USER-2! USER USER=John Welcome John-2!

      Unset environment variables will not be expanded:

      String Variables Variable Values Expanded String
      Welcome $FOO! FOO not set Welcome $FOO!

      On Windows, names of environment variables are case insensitive, i.e., FOO and foo refer to the same environment variable. On Unix, names of environment variables are case sensitive, i.e., FOO and foo refer to different environment variables. Variable expansion will align with platform specifics:

      String Variables Variable Values Expanded String on Unix Expanded String on Windows
      $USER speaks $LANG USER, LANG USER=Lisa, lang=French Lisa speaks $LANG Lisa speaks French

      \$ substring will prevent variable expansion:

      String Variables Variable Values Expanded String
      Hello \$A! Bye $B B B=John Hello $A! Bye John
      Hello \${A}! Bye $B B B=John Hello ${A}! Bye John

      \\ substring will escape \ character:

      String Variables Variable Values Expanded String
      Hello \\$A! Bye $B A, B A=Ana, B=John Hello \$A! Bye John

      If \ character is not followed by another \ character or $ character, it will be interpreted as a regular character:

      String Expanded String
      a\b\c a\b\c

      Characters between ${ and } substrings will be interpreted as regular characters:

      String Variables
      Hello ${A$B}! A$B
      Hello ${A\\${B}}! A\\${B

      Expansion will be non-recursive:

      String Variables Variable Values Expanded String Notes
      Hello $A! A A=${B}, B=John Hello ${B}! Value of variable "A" is replaced verbatim

      If APPDIR, BINDIR, and ROOTDIR environment variables are set, their values will be ignored and substituted by the values calculated by jpackage app launcher. The names of these environment variables are case-insensitive on Windows and case-sensitive on Unix.

      jpackage help file will be updated. Section referencing --arguments and --java-options options will be changed from

      --arguments arguments
      
          Command line arguments to pass to the main class if no command
          line arguments are given to the launcher
      
          This option can be used multiple times.
      
      --java-options options
      
          Options to pass to the Java runtime
      
          This option can be used multiple times.

      to

      --arguments arguments
      
          Command line arguments to pass to the main class if no command
          line arguments are given to the launcher
      
          This option can be used multiple times.
      
          Value can contain substrings that will be expanded at runtime.
          Two types of such substrings are supported: environment variables
          and "APPDIR", "BINDIR", and "ROOTDIR" tokens.
      
          An expandable substring should be enclosed between the dollar
          sign character ($) and the first following non-alphanumeric
          character. Alternatively, it can be enclosed between "${" and "}"
          substrings.
      
          Expandable substrings are case-sensitive on Unix and
          case-insensitive on Windows. No string expansion occurs if the
          referenced environment variable is undefined.
      
          Environment variables with names "APPDIR", "BINDIR", and "ROOTDIR"
          will be ignored, and these expandable substrings will be
          replaced by values calculated by the app launcher.
      
          Prefix the dollar sign character with the backslash character (\)
          to prevent substring expansion.
      
      --java-options options
      
          Options to pass to the Java runtime
      
          This option can be used multiple times.
      
          Value can contain substrings that will be substituted at runtime, 
          such as for the --arguments option.

            asemenyuk Alexey Semenyuk
            webbuggrp Webbug Group
            Alexander Matveev, Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: