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: Unresolved
    • 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!

      \$ 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.

            asemenyuk Alexey Semenyuk
            webbuggrp Webbug Group
            Alexander Matveev
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: