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

allow expressions in template variable definitions #989

Open
hohwille opened this issue Jan 24, 2025 · 0 comments
Open

allow expressions in template variable definitions #989

hohwille opened this issue Jan 24, 2025 · 0 comments
Labels
configuration should be configurable or configuration change enhancement New feature or request merger settings ide-settings repo and replated processes and features

Comments

@hohwille
Copy link
Member

Currently we support variable expressions like $[IDE_HOME] in templates.
In such case if the variable is defined, the expression is literally replaced with its value.
This is fine for most of our use-cases.

However, in some cases we might end up with resolving $[IDE_HOME]/software/mvn to D:\projects\my-project/software/mvn on Windows.
Often tools are tolerant and will accept this mixed up path syntax.
However, in some cases backslashes may need extra escaping and the result may not work.
Also we have cases like this:
https://github.com/devonfw/ide-settings/blob/3c41b5e27ad4baa90d4e3ffdf2ac16ca5e95d11a/intellij/workspace/update/.intellij/config/options/nodejs.xml#L4-L5

    <!-- ATTENTION: Will only work on windows so far -->
    <local-interpreter path="$[IDE_HOME]/software/node/node.exe" merge:id="name()"/>

We could still workaround this somehow by adding a variable EXECUTABLE_SUFFIX set to .exe in settings/ide.properties and then a MacOS or linux user could override the property as empty (EXECUTABLE_SUFFIX=) in his config/ide.properties to make that portable.

Expression Syntax

The syntax still needs to be refined but here are some first ideas:

$[@path('unix', '${IDE_HOME}/software/node/node?(.exe|.sh|)')]

I know the syntax looks strange but this is a first draft:

  • We try to stick with out existing $[...] syntax so our regex replace approach can stay
  • Therefore, we also do not nest $[...] but use ${...} inside as otherwise it will become more tricky to find the end of the regex expression.
  • In this example if the content inside $[...] starts with an at sign @, then we assume we do not have a plain variable name but an expression/function
  • The name of the function is starting after the @ sign and ending before the opening parenthesis ( that must always be present - here path in the function name
  • The function can take any number of arguments and ends with the closing parenthesis ).
  • Each argument for the function is enclosed with quotes - both single quotes ' and double quotes " are supported.
  • Variable expressions in curly syntax are resolved inside the function arguments - here ${IDE_HOME}
  • A function takes a list of arguments and returns a String as result. That result will be the resolved value the entire expression ($[...]) will be replaced with.
  • Here the path function would be called with two String arguments unix and e.g. /home/mylogin/projects/example/software/node/node?(.exe|.sh|).
  • The path function could now extract /home/mylogin/projects/example/software/node/node and then iterate the suffixes ".exe", ".sh", and "" and during the iteration check if that java.nio.Path exists. If it exists it will be converted to a String using unix syntax (so if we are on Windows and have backslashes as separators they will be replaced with normal slashes) and that String is returned. If no Path exists, a warning is logged but the last iterated suffix will be used (here the empty String).
  • Again this is all just an example, we could also pass '/' as first argument and consider it as folder separator and could pass \\ as alternative or the empty String '' to keep the OS default - whatever.
  • We could even have a function without arguments: $[@currentDateTime()]
@hohwille hohwille added configuration should be configurable or configuration change enhancement New feature or request merger settings ide-settings repo and replated processes and features labels Jan 24, 2025
@github-project-automation github-project-automation bot moved this to 🆕 New in IDEasy board Jan 24, 2025
@hohwille hohwille moved this from 🆕 New to Refinement in IDEasy board Jan 24, 2025
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 settings ide-settings repo and replated processes and features
Projects
Status: Refinement
Development

No branches or pull requests

1 participant