#989: allow expressions in template variable definitions - #2282
Open
Paras14 wants to merge 5 commits into
Open
Conversation
…/989-expression-functions
Collaborator
Coverage Report for CI Build 31163534185Coverage increased (+0.2%) to 73.032%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions148 previously-covered lines in 4 files lost coverage.
Coverage Stats💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes #989
Implements #989 and supersedes the
$[ask:...]/$[secret:...]syntax of #2179.Closes #2165.
Implemented changes
com.devonfw.tools.ide.expressionwith 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 theIdeContext, variable lookup and persistence.@path(«path»[, unix|native])that normalises a path, by default replacing backslashes with slashes.@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.@if-windows,@if-mac,@if-linuxand@if-unixthat insert their argument if the OS matches.IdeContext.askForSecret(String, String)analogous toaskForInput.AbstractIdeContextimplements the prompt loop and the batch mode contract and delegates reading to the new protectedreadSecretLine(), whichIdeContextConsoleoverrides withConsole.readPassword().conf/ide.propertiesso the question is only asked the first time. A value that could not be asked for in batch mode is not persisted.@path('$[IDE_HOME]/software/node')).Testing instructions
Masked input needs a real console, so run this from a normal terminal and not from the IDE.
(make sure you add your path correctly for the cli target classes: "\cli\target\classes")
IDEasy\settings\workspace\update\ai-test.properties:Make sure
MY_URL,MY_TOKENandMY_OPTIONALare not yet defined inIDEasy\conf\ide.properties.You are asked three times.
MY_URLis echoed while typing,MY_TOKENandMY_OPTIONALare not. The question forMY_TOKENis shown as given, including the parenthesis. Press enter without typing anything forMY_OPTIONAL.IDEasy\workspaces\main\ai-test.propertiescontains the three entered values andai.node.pathwith backslashes.IDEasy\conf\ide.propertiescontainsMY_URL,MY_TOKENandMY_OPTIONAL.Run again. There is no prompt and the file keeps the same values.
Remove
MY_URL,MY_TOKENandMY_OPTIONALfromIDEasy\conf\ide.propertiesand run again with--batch. There is no prompt, the workspace merge fails withCliAbortException: Aborted by end-user.and nothing is added toIDEasy\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.
mvn clean testlocally all tests pass and build is successful#«issue-id»: «brief summary»(e.g.#921: fixed setup.bat). If no issue ID exists, title only.In Progressand assigned to you or there is no issue (might happen for very small PRs)with
internal