devonfw / IDEasy

Tool to automate the setup and updates of a development environment for any project (Successor of devonfw-ide).
Apache License 2.0
8 stars 21 forks source link

Create ide wrapper script #63

Closed hohwille closed 6 months ago

hohwille commented 1 year ago

As a devonfw-ide user, I want to be able to use the new ide CLI seamlessly so that I can continue to work like I was used to with devonfw-ide. That is if I just call ide this will set my environments according to the IDEasy project I am currently located in.

For this we have already implemented our Java IDE and build-process to create native image binaries. All this already supports an environment commandlet that prints out all the variables to set. However, a process (our ide.exe) cannot set/change the environments of the current shell (e.g. CMD, bash, or powershell) the user is currently running. Therefore we need a wrapper script similar like what we had before:

Instead that new script should be quite different:

To simplify things you may develop and provide ide (bash) and ide.bat in separate steps as individual PRs. As those files need to be included into our release package. My suggestion would be:

Again if you want to simplify. You can first place the scripts into the new location as a PR (first bullet point above) and later create a PR to integrate it and improve the release package.

Clarification of potential questions:

hohwille commented 8 months ago

Some simple testing:

hohwille@CE49454 MSYS /d/projects/IDEasy/test/bin
$ export PATH=/d/projects/IDEasy/software/node:/d/projects/IDEasy/software/java/bin:/d/projects/IDEasy/software/mvn/bin:/d/projects/IDEasy/software/node:/d/projects/IDEasy/software/mvn/bin:/d/projects/IDEasy/software/java/bin:/c/Users/hohwille/bin:/c/Program Files/Git/usr/local/bin:/c/Program Files/Git/usr/bin:/c/Program Files/Git/usr/bin:/c/Program Files/Git/opt/bin:/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.17.11461.0_x64__8wekyb3d8bbwe:/d/oracle-xe/product/18.0.0/dbhomeXE/bin:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program Files (x86)/GnuPG/bin:/c/Program Files/SlikSvn/bin:/c/Program Files/TortoiseSVN/bin:/c/Program Files/Git/cmd:/c/Program Files/Rancher Desktop/resources/resources/win32/bin:/c/Program Files/Rancher Desktop/resources/resources/linux/bin:/c/Users/hohwille/scripts:/c/Program Files/Git/usr/bin/vendor_perl:/c/Program Files/Git/usr/bin/core_perl
bash: syntax error near unexpected token `('

hohwille@CE49454 MSYS /d/projects/IDEasy/test/bin
$ export "PATH=/d/projects/IDEasy/software/node:/d/projects/IDEasy/software/java/bin:/d/projects/IDEasy/software/mvn/bin:/d/projects/IDEasy/software/node:/d/projects/IDEasy/software/mvn/bin:/d/projects/IDEasy/software/java/bin:/c/Users/hohwille/bin:/c/Program Files/Git/usr/local/bin:/c/Program Files/Git/usr/bin:/c/Program Files/Git/usr/bin:/c/Program Files/Git/opt/bin:/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.17.11461.0_x64__8wekyb3d8bbwe:/d/oracle-xe/product/18.0.0/dbhomeXE/bin:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program Files (x86)/GnuPG/bin:/c/Program Files/SlikSvn/bin:/c/Program Files/TortoiseSVN/bin:/c/Program Files/Git/cmd:/c/Program Files/Rancher Desktop/resources/resources/win32/bin:/c/Program Files/Rancher Desktop/resources/resources/linux/bin:/c/Users/hohwille/scripts:/c/Program Files/Git/usr/bin/vendor_perl:/c/Program Files/Git/usr/bin/core_perl"

So this ugly Windows Folders with white-space and parenthesis (Program Files (x86)) are some issue. Be aware of that in your wrapper script.

Another question would be why are there path entries duplicated? I see this:

So these duplicates are IMHO a bug of the EnvironmentCommandlet. Does not have to be fixed as part of this story, but should also be addressed.

hohwille commented 8 months ago
devonfw-ide environment variables have been set for /d/projects/IDEasy in workspace main

hohwille@CE49454 MINGW64 /d/projects/IDEasy/test/bin
$ echo $PATH
/d/projects/IDEasy/software/node:/d/projects/IDEasy/software/mvn/bin:/d/projects/IDEasy/software/java/bin:/c/Users/hohwille/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/hohwille/bin:/d/oracle-xe/product/18.0.0/dbhomeXE/bin:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program Files (x86)/GnuPG/bin:/c/Program Files/SlikSvn/bin:/c/Program Files/TortoiseSVN/bin:/cmd:/c/Program Files/Rancher Desktop/resources/resources/win32/bin:/c/Program Files/Rancher Desktop/resources/resources/linux/bin:/c/Users/hohwille/scripts:/usr/bin/vendor_perl:/usr/bin/core_perl

So no duplicates before invoking ideasy so a bug of EnvironmentCommandlet.

hohwille commented 8 months ago

Already found the source of the bug: https://github.com/devonfw/IDEasy/blob/7fcddb5a505db40275a4a04801fc5dd88d6d357a/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java#L109

IMHO we do not handle the different PATH syntax on windows between native Windows syntax (D:\projects\IDEasy\software) and Bash-Syntax (/d/projects/IDEasy/software). So before entering the loop we should check if we are on Windows and if so also compute the path transformation to bash syntax for softwarePath and pass the result also to getTool method: https://github.com/devonfw/IDEasy/blob/7fcddb5a505db40275a4a04801fc5dd88d6d357a/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java#L63

hohwille commented 8 months ago

Maybe we should split this story into 3 aspects:

hohwille commented 7 months ago

For the record: I am also thinking about renaming ideasy binary to something more special. Regular end-users will always use the ide wrapper script. When using code-completion in bash and typing id[Tab] the user will get ide and ideasy[.exe] as options what seems a little inconvenient. The other option would be to have our ideasy binary not in the PATH variable and therefore not in the bin folder where the ide script is located. But then the script needs some tweak to find ideasy. However, the latter option might be better.

hohwille commented 7 months ago

Auto-closed by PR #221 but not yet completed:

hohwille commented 6 months ago

Since this issue was magically reopend when I created #260 I can reuse it for another demand we need to implement:

$ ideasy env --bash
You are not inside an IDE installation: D:\projects
You are not inside an IDE installation: D:\projects

First line is on std out in white. Second line is on std err in red. The white output could be removed.

$ ideasy env --bash
export PATH="..."
MVN_VERSION="3.9.5"
INTELLIJ_VERSION="2023.3.2"
...

This is so far fully correct. However, when we just call ide as sourced script and you get the red error output if you are not inside a project but if you are in a project you get no output at all. Like with devon we should instead get something like this:

IDE environment variables have been set for /d/projects/IDEasy in workspace main

The message is already implemented here: https://github.com/devonfw/IDEasy/blob/be4ab474f32f343ff033c6de2e7acae90f0a0b1f/cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java#L252

Please note that you cannot output the message to std out from ideasy env --bash. So either we need to print it as error or we have to think of a different approach (but building it from the wrapper script does not seem to be a good idea as we also need an ide.bat script and we therefore want to have as little logic in these scripts as possible).