RFR: 8341641: Make %APPDATA% and %LOCALAPPDATA% env variables available in *.cfg files [v10]

Magnus Ihse Bursie ihse at openjdk.org
Thu Apr 10 14:46:42 UTC 2025


On Wed, 9 Apr 2025 20:56:03 GMT, Alexey Semenyuk <asemenyuk at openjdk.org> wrote:

>> jpackage app laucnher will expand environment variables in .cfg files.
>> 
>> Previously jpackage app launcher only replaced `$APPDIR`, `$BINDIR`, and `$ROOTDIR` tokens with the corresponding path values. With this patch, any environment variable can be expanded. The syntax is shell-like `$ENV_VAR_NAME` or `${ENV_VAR_NAME}`. If `$ENV_VAR_NAME` syntax is used, the variable name stops at the first character outside of `[a-zA-Z0-9_]` character range. If `${ENV_VAR_NAME}` syntax is used, the variable name stops at the first `}` character after `${` substring. E.g:
>> | String    | Variables | Variable Values | Expanded String | Note |
>> | -------- | ------- |------- |------- |------- |
>> | <pre>Welcome $USER!</pre>  | <pre>USER</pre> | <pre>USER=John</pre> | <pre>Welcome John!</pre> ||
>> | <pre>Welcome $USER!</pre>  | <pre>USER</pre> | <pre>not set</pre> | <pre>Welcome $USER!</pre> | Unset variables are not expanded. |
>> | <pre>Welcome $USER2</pre> | <pre>USER2</pre>   | <pre>USER2=John</pre> | <pre>Welcome John!</pre> ||
>> | <pre>Welcome ${USER}2!</pre> | <pre>USER</pre>  | <pre>USER=John</pre> | <pre>Welcome John2!</pre> ||
>> | <pre>Welcome $USER-2!</pre> | <pre>USER</pre>   | <pre>USER=John</pre> | <pre>Welcome John-2!</pre> ||
>> | <pre>Welcome ${USER-2}!</pre> | <pre>USER-2</pre>   | <pre>USER-2=John</pre> | <pre>Welcome John!</pre> | `USER-2` is likely to be an invalid env variable name, but jpackage launcher is not validating names. |
>> 
>> `$` character combination prevents variable expansion:
>> | String    | Variables | Variable Values | Expanded String |
>> | -------- | ------- |------- |------- |
>> | <pre>Hello \$A! Bye $B</pre>  | B | <pre>B=John</pre> | <pre>Hello $A! Bye John</pre> |
>> | <pre>Hello \${A}! Bye $B</pre>  | B | <pre>B=John</pre> | <pre>Hello ${A}! Bye John</pre> |
>> 
>> `\` character combination escapes ``:
>> | String    | Variables | Variable Values | Expanded String |
>> | -------- | ------- |------- |------- |
>> | <pre>Hello \\\$A! Bye $B</pre>  | A, B | <pre>A=Ana</pre><pre>B=John</pre> | <pre>Hello \\Ana! Bye John</pre> |
>> 
>> If `` character is not followed by another `` character or `$` character, it is interpreted as a regular character:
>> | String    | Expanded string |
>> | -------- | ------- |
>> |<pre>a\\b\\c</pre>|<pre>a\\b\\c</pre>|
>> 
>> 
>> Expansion is non-recursive:
>> | String    | Variables | Variable Values | Expanded String | Note |
>> | -------- | ------- |------- |------- |------- |
>> | <pre>Hello $A!</pre>  | A | <pre>A...
>
> Alexey Semenyuk has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains one new commit since the last revision:
> 
>   Update tests and implementation to comply with the CSR (env var names are case-insesitive on Windows)

src/jdk.jpackage/share/man/jpackage.md line 228:

> 226:     An expandable substring should be enclosed between the dollar
> 227:     sign character ($) and the first following non-alphanumeric
> 228:     character. Alternatively, it can be enclosed between "${" and "}"

This did not sit well with pandoc, that reports:

[WARNING] Could not convert TeX math ) and the first following non-alphanumeric character. Alternatively, it can be enclosed between ", rendering as TeX:
  e enclosed between "
                     ^
  unexpected '"'
  expecting "\\bangle", "\\brace", "\\brack", "\\choose", "\\displaystyle", "\\textstyle", "\\scriptstyle", "\\scriptscriptstyle", "{", "\\operatorname", letter, digit, ".", "!", "'", "''", "'''", "''''", "*", "+", ",", "-", ".", "/", ":", ":=", ";", "<", "=", ">", "?", "@", "~", "_", "^", "\\left", "\", "\\hyperref" or end of input

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/23923#discussion_r2037591430


More information about the core-libs-dev mailing list