Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8341641: Make %APPDATA% and %LOCALAPPDATA% env variables available in *.cfg files #23923

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

alexeysemenyukoracle
Copy link
Member

@alexeysemenyukoracle alexeysemenyukoracle commented Mar 5, 2025

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
Welcome $USER!
USER
USER=John
Welcome John!
Welcome $USER!
USER
not set
Welcome $USER!
Unset variables are not expanded.
Welcome $USER2
USER2
USER2=John
Welcome John!
Welcome ${USER}2
USER
USER=John
Welcome John2!
Welcome $USER-2
USER
USER=John
Welcome John-2!
Welcome ${USER-2}
USER-2
USER-2=John
Welcome John!
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
Hello \$A! Bye $B
B
B=John
Hello $A! Bye John
Hello \${A}! Bye $B
B
B=John
Hello ${A}! Bye John

\\ character combination escapes \:

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

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

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

Expansion is non-recursive:

String Variables Variable Values Expanded string Note
Hello $A!
A
A=$B
B=John
Hello $B
Variable "B" will not be expanded

Values of APPDIR, BINDIR, and ROOTDIR environment variables are ignored, and these names are substituted by values calculated by jpackage app launcher as previously.

$APPDIR is equivalent to ${APPDIR}.
$BINDIR is equivalent to ${BINDIR}.
$ROOTDIR is equivalent to ${ROOTDIR}.

You will find two entities dealing with token replacement in this patch:


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8341641: Make %APPDATA% and %LOCALAPPDATA% env variables available in *.cfg files (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23923/head:pull/23923
$ git checkout pull/23923

Update a local copy of the PR:
$ git checkout pull/23923
$ git pull https://git.openjdk.org/jdk.git pull/23923/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23923

View PR using the GUI difftool:
$ git pr show -t 23923

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23923.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 5, 2025

👋 Welcome back asemenyuk! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Mar 5, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Mar 5, 2025

@alexeysemenyukoracle The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@alexeysemenyukoracle alexeysemenyukoracle marked this pull request as ready for review March 6, 2025 01:04
@alexeysemenyukoracle
Copy link
Member Author

@sashamatveev PTAL

@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 6, 2025
@mlbridge
Copy link

mlbridge bot commented Mar 6, 2025

Webrevs

@sashamatveev
Copy link
Member

If you do echo on macOS in terminal for unset variable it will be expanded to empty string, so for "Unset variables are not expanded." should we have Welcome ! instead of Welcome $USER!?

Copy link
Member

@sashamatveev sashamatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall with minor comment and question.

for (; it != end; ++it) {
if (it->type() == ESCAPED_CHAR) {
ss << it->value().substr(1);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else { in one line for consistency.

@openjdk
Copy link

openjdk bot commented Mar 6, 2025

⚠️ @alexeysemenyukoracle This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

@alexeysemenyukoracle
Copy link
Member Author

This is true for any shell behavior. It is also true that some shells fail to expand undefined variables if configured accordingly. Bash, for example:

bash -c 'FOO=10; echo FOO=$FOO; unset FOO; set -u; echo FOO=$FOO'

Output:

FOO=10
bash: line 1: FOO: unbound variable

.cfg files are not scripts and jpackage app launcher is not an interpreter. Performed string substitution is less variable expansion and more token replacement; if token value is not available, it is not replaced.
Regardless of handling undefined variables, users have to deal with the consequences. Say they pass --java-options -DmyAppData=$HOME/.myData option to jackage and HOME variable happens undefined on a machine where installed app is launched. How would /.myData be better than $HOME/.myData? At least it is clear something went wrong in the second case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs [email protected] rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

3 participants