Skip to content

#989: allow expressions in template variable definitions - #2282

Open
Paras14 wants to merge 5 commits into
devonfw:mainfrom
Paras14:feature/989-expression-functions
Open

#989: allow expressions in template variable definitions#2282
Paras14 wants to merge 5 commits into
devonfw:mainfrom
Paras14:feature/989-expression-functions

Conversation

@Paras14

@Paras14 Paras14 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

This PR fixes #989

Implements #989 and supersedes the $[ask:...] / $[secret:...] syntax of #2179.

Closes #2165.

Implemented changes

  • Added new package com.devonfw.tools.ide.expression with the expression syntax @«function-name»([«arg»[,«arg»]*]) resolved during variable resolution.
  • ExpressionFunction - interface implemented by every function.
  • ExpressionFunctionManager - registry to look up functions by name so further functions can be registered with new IDEasy releases.
  • ExpressionParser - locates function calls and parses their arguments. A RegEx is only used to locate the start of a call, the argument list is scanned manually since a RegEx cannot express a balanced list of arguments containing quoted commas, quoted parenthesis or nested calls.
  • ExpressionContext - gives a function access to the IdeContext, variable lookup and persistence.
  • Added function @path(«path»[, unix|native]) that normalises a path, by default replacing backslashes with slashes.
  • Added functions @ask-variable(«name»[, «question»[, «default»]]) and @ask-secret(...) with masked input. An already defined variable is returned without asking, an empty 1st argument always asks, and an empty string as 3rd argument permits empty input.
  • Added functions @if-windows, @if-mac, @if-linux and @if-unix that insert their argument if the OS matches.
  • Added IdeContext.askForSecret(String, String) analogous to askForInput. AbstractIdeContext implements the prompt loop and the batch mode contract and delegates reading to the new protected readSecretLine(), which IdeContextConsole overrides with Console.readPassword().
  • Values entered for a workspace template are persisted to conf/ide.properties so the question is only asked the first time. A value that could not be asked for in batch mode is not persisted.
  • Arguments are resolved through the regular variable resolution, so a String argument may itself contain variables (e.g. @path('$[IDE_HOME]/software/node')).
  • Text that does not call a registered function is left untouched.

Testing instructions

Masked input needs a real console, so run this from a normal terminal and not from the IDE.

  1. Build the branch and dump the classpath, from the repository root:
mvn -pl cli -am install -DskipTests
mvn -pl cli dependency:build-classpath "-Dmdep.outputFile=cp.txt"
$CP = (Get-Content cli\cp.txt -Raw).Trim()
$CLASSES = "C:\projects\IDEasy\workspaces\main\IDEasy\cli\target\classes"

(make sure you add your path correctly for the cli target classes: "\cli\target\classes")

  1. In a test project create IDEasy\settings\workspace\update\ai-test.properties:
ai.backend.url=@ask-variable('MY_URL')
ai.api.key=@ask-secret('MY_TOKEN', 'Enter your API key (from the portal):')
ai.node.path=@path('$[IDE_HOME]/software/node/node', native)
ai.other=@ask-secret('MY_OPTIONAL', 'Password (may be empty):', '')

Make sure MY_URL, MY_TOKEN and MY_OPTIONAL are not yet defined in IDEasy\conf\ide.properties.

  1. From the project directory, run the local build:
java -cp "$CLASSES;$CP" com.devonfw.tools.ide.cli.Ideasy update
  1. You are asked three times. MY_URL is echoed while typing, MY_TOKEN and MY_OPTIONAL are not. The question for MY_TOKEN is shown as given, including the parenthesis. Press enter without typing anything for MY_OPTIONAL.

  2. IDEasy\workspaces\main\ai-test.properties contains the three entered values and ai.node.path with backslashes. IDEasy\conf\ide.properties contains MY_URL, MY_TOKEN and MY_OPTIONAL.

  3. Run again. There is no prompt and the file keeps the same values.

  4. Remove MY_URL, MY_TOKEN and MY_OPTIONAL from IDEasy\conf\ide.properties and run again with --batch. There is no prompt, the workspace merge fails with CliAbortException: Aborted by end-user. and nothing is added to IDEasy\conf\ide.properties, as an undefined variable cannot be asked for in batch mode.


Checklist for this PR

Make sure everything is checked before merging this PR. For further info please also see
our DoD.

  • When running mvn clean test locally all tests pass and build is successful
  • PR title is of the form #«issue-id»: «brief summary» (e.g. #921: fixed setup.bat). If no issue ID exists, title only.
  • PR top-level comment summarizes what has been done and contains link to addressed issue(s)
  • PR and issue(s) have suitable labels
  • Issue is set to In Progress and assigned to you or there is no issue (might happen for very small PRs)
  • You followed all coding conventions
  • You have added the issue implemented by your PR in CHANGELOG.adoc unless issue is labeled
    with internal
  • You have formulated clear instructions on how to test your contribution under "Testing instructions"

@github-project-automation github-project-automation Bot moved this to 🆕 New in IDEasy board Aug 6, 2026
@Paras14 Paras14 self-assigned this Aug 6, 2026
@Paras14 Paras14 moved this from 🆕 New to Team Review in IDEasy board Aug 6, 2026
@Paras14 Paras14 added enhancement New feature or request configuration should be configurable or configuration change settings ide-settings repo and replated processes and features merger workspace template merger (XML, JSON, properties) ready-to-implement labels Aug 6, 2026
@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 31163534185

Coverage increased (+0.2%) to 73.032%

Details

  • Coverage increased (+0.2%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 148 coverage regressions across 4 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

148 previously-covered lines in 4 files lost coverage.

File Lines Losing Coverage Coverage
com/devonfw/tools/ide/context/AbstractIdeContext.java 104 71.46%
com/devonfw/tools/ide/context/IdeContext.java 20 76.92%
com/devonfw/tools/ide/environment/AbstractEnvironmentVariables.java 17 82.73%
com/devonfw/tools/ide/context/IdeContextConsole.java 7 0.0%

Coverage Stats

Coverage Status
Relevant Lines: 17691
Covered Lines: 13477
Line Coverage: 76.18%
Relevant Branches: 7847
Covered Branches: 5174
Branch Coverage: 65.94%
Branches in Coverage %: Yes
Coverage Strength: 3.24 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration should be configurable or configuration change enhancement New feature or request merger workspace template merger (XML, JSON, properties) ready-to-implement settings ide-settings repo and replated processes and features

Projects

Status: Team Review

Development

Successfully merging this pull request may close these issues.

prompt user for template variables at apply time allow expressions in template variable definitions

3 participants