Skip to content

Feature/2165 interactive template variables#2179

Open
Paras14 wants to merge 2 commits into
devonfw:mainfrom
Paras14:feature/2165-interactive-template-variables
Open

Feature/2165 interactive template variables#2179
Paras14 wants to merge 2 commits into
devonfw:mainfrom
Paras14:feature/2165-interactive-template-variables

Conversation

@Paras14

@Paras14 Paras14 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

This PR fixes #2165

Implemented changes:

  • Extended VariableSyntax.SQUARE to additionally match $[ask:VARIABLE] and $[secret:VARIABLE] expressions.
  • Added IdeContext.askForSecret for masked console input via Console.readPassword.
  • During variable resolution, ask expressions for undefined variables prompt the user and persist the entered value to the user's conf/ide.properties so they are not asked again.
  • Ask expressions for already defined variables resolve like plain variables without any interaction.
  • In batch mode ask expressions are skipped with a warning.
  • Updated configurator.adoc and added tests in EnvironmentVariablesTest.

As discussed with @hohwille, the prefix syntax encodes secret vs. plain in the name instead of using function arguments, which aligns it with the $[secret:name] syntax introduced by #2162. A future @function(args) syntax as proposed in #989 can be added as a further alternative in the same regex. Motivated by #412 to preconfigure AI assistant plugins with a backend URL and API key that must not be committed to the settings repository. See also #987.


Testing instructions

Tested on Windows using PowerShell. Strongly recommended to run an actual PowerShell window, as masking needs System.console(), which is null in IDE consoles and when input is piped, and there the input stays visible
with a warning by design.

  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=C:\temp\cp.txt"
    $CP = (Get-Content C:\temp\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: "<repo>\cli\target\classes")_
    
  2. In a test project create IDEasy\settings\workspace\update\ai-test.properties:

    ai.backend.url=$[ask:MY_URL]
    ai.api.key=$[secret:MY_TOKEN]
    

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

  3. From the project directory, run the local build:

    cd C:\projects\IDEasy
    java -cp "$CLASSES;$CP" com.devonfw.tools.ide.cli.Ideasy update
    

    You are prompted before any downloads: MY_URL with visible input,
    MY_TOKEN with hidden(masked) input. Each prompt names the file requiring it.

    1. Check that IDEasy\workspaces\main\ai-test.properties contains the entered values
      with no $[...] left, and that both variables were written to
      conf\ide.properties exactly as typed.
  4. Run the same command again. You won't get any input prompts this time, the persisted values are reused.

  5. Add MY_OTHER=https://example.com to conf\ide.properties, then add the line
    ai.other=$[ask:MY_OTHER] to IDEasy\settings\workspace\update\ai-test.properties.
    Run again. There is no prompt, and IDEasy\workspaces\main\ai-test.properties
    contains ai.other=https://example.com.

  6. Remove MY_URL and MY_TOKEN from IDEasy\conf\ide.properties and run with --batch.
    No input prompts, but one warning per expression, and the $[ask:...] and $[secret:...]
    text is left untouched in the output.


Checklist for this PR

  • When running mvn clean test locally all tests pass and build is successful
  • PR title is of the form #«issue-id»: «brief summary»
  • 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
  • You followed all coding conventions
  • You have added the issue implemented by your PR in CHANGELOG.adoc
  • 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 Jul 21, 2026
@Paras14 Paras14 self-assigned this Jul 21, 2026
@Paras14 Paras14 moved this from 🆕 New to Team Review in IDEasy board Jul 21, 2026
@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 29803149984

Coverage decreased (-0.04%) to 72.439%

Details

  • Coverage decreased (-0.04%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 144 coverage regressions across 6 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

144 previously-covered lines in 6 files lost coverage.

File Lines Losing Coverage Coverage
com/devonfw/tools/ide/context/AbstractIdeContext.java 99 70.06%
com/devonfw/tools/ide/environment/AbstractEnvironmentVariables.java 19 81.65%
com/devonfw/tools/ide/context/IdeContext.java 16 78.57%
com/devonfw/tools/ide/context/IdeContextConsole.java 7 0.0%
com/devonfw/tools/ide/variable/VariableSyntax.java 2 85.71%
com/devonfw/tools/ide/version/VersionSegment.java 1 90.03%

Coverage Stats

Coverage Status
Relevant Lines: 16950
Covered Lines: 12804
Line Coverage: 75.54%
Relevant Branches: 7574
Covered Branches: 4961
Branch Coverage: 65.5%
Branches in Coverage %: Yes
Coverage Strength: 3.2 hits per line

💛 - Coveralls

@QuangAnhLe QuangAnhLe moved this from Team Review to 🏗 In progress in IDEasy board Jul 22, 2026
@QuangAnhLe QuangAnhLe moved this from 🏗 In progress to Team Review in IDEasy board Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Team Review

Development

Successfully merging this pull request may close these issues.

prompt user for template variables at apply time

3 participants