Skip to content

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

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

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
  • Change requires CSR request JDK-8351447 to be approved

Issues

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

Reviewers

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

Sorry, something went wrong.

@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

@alexeysemenyukoracle This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

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

Reviewed-by: almatvee

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 9 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@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

@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.

@alexeysemenyukoracle
Copy link
Member Author

/csr

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Mar 6, 2025
@openjdk
Copy link

openjdk bot commented Mar 6, 2025

@alexeysemenyukoracle has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@alexeysemenyukoracle please create a CSR request for issue JDK-8341641 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

@openjdk
Copy link

openjdk bot commented Mar 18, 2025

@alexeysemenyukoracle this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout JDK-8341641-master
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Mar 18, 2025
@openjdk openjdk bot added rfr Pull request is ready for review and removed rfr Pull request is ready for review merge-conflict Pull request has merge conflict with target branch csr Pull request needs approved CSR before integration labels Apr 1, 2025
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.

Latest changes looks good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 3, 2025
@alexeysemenyukoracle
Copy link
Member Author

I'll update the tests to cover case sensitivity differences on Unix and Windows.

@openjdk
Copy link

openjdk bot commented Apr 9, 2025

@alexeysemenyukoracle Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Apr 9, 2025
@openjdk
Copy link

openjdk bot commented Apr 9, 2025

@alexeysemenyukoracle Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

… are case-insesitive on Windows)
@openjdk
Copy link

openjdk bot commented Apr 9, 2025

@alexeysemenyukoracle Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

@alexeysemenyukoracle
Copy link
Member Author

Updated the implementation and tests to comply with the CSR. @sashamatveev PTAL

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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 10, 2025
@alexeysemenyukoracle
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Apr 10, 2025

Going to push as commit 45b7c74.
Since your change was applied there have been 9 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 10, 2025
@openjdk openjdk bot closed this Apr 10, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 10, 2025
@openjdk
Copy link

openjdk bot commented Apr 10, 2025

@alexeysemenyukoracle Pushed as commit 45b7c74.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.


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 "}"
Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing a possible fix would be to use

`${`

or

"`${`"

instead.

Alternatively, we need to tell pandoc to not try and use any encoded TeX math in markdown files.

Copy link
Member Author

Choose a reason for hiding this comment

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

I filed https://bugs.openjdk.org/browse/JDK-8354320 to fix the warning

Copy link
Member Author

@alexeysemenyukoracle alexeysemenyukoracle Apr 10, 2025

Choose a reason for hiding this comment

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

Adding backslash character (\) before the dollar character ("${" -> "\${") suppressed the warning, and the man page looks as expected.

PR #24585

Copy link
Member

Choose a reason for hiding this comment

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

As I said in that PR, yes, it silences the warning, but it is not standard markdown, and will be rendered incorrectly by a standard markdown renderer.

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

Successfully merging this pull request may close these issues.

None yet

4 participants