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

Expansion of ~ stopped working on windows CMD (M2_HOME not properly set) #467

Closed
maybeec opened this issue Sep 21, 2020 · 9 comments · Fixed by #468
Closed

Expansion of ~ stopped working on windows CMD (M2_HOME not properly set) #467

maybeec opened this issue Sep 21, 2020 · 9 comments · Fixed by #468
Labels
bug Something isn't working scripts related to shell scripts (bash and CMD) windows specific for Microsoft Windows OS

Comments

@maybeec
Copy link
Member

maybeec commented Sep 21, 2020

Expected behavior

As a user, I want to use devonfw-ide on windows so that I can execute maven builds on a devonfw console.

Actual behavior

M2_REPO is not recognized and thus every mvn command is running on ~/.m2/repository in the current execution path.

Steps to reproduce (bug) / Use Case of feature request (enhancement)

  1. Set export M2_REPO=~/.m2/repository in devon.properties
  2. open a devon cmd
  3. run mvn -X or `echo %M2_REPO%

Related/Dependent Issues

Comments/Hints:

Affected version:

  • OS: Windows
@maybeec maybeec added bug Something isn't working scripts related to shell scripts (bash and CMD) blocker severe bug that blocks users in their daily work and has to be fixed asap labels Sep 21, 2020
@hohwille hohwille changed the title M2_HOME not properly set on cmd Expansion of ~ stopped working on windows CMD (M2_HOME not properly set) Sep 22, 2020
@hohwille
Copy link
Member

I do not know if this is blocking you: You can edit the variable and manually replace ~ with something like C:\Users\«mylogin». However, we accept this is a stupid bug that needs to be fixed asap.

@hohwille
Copy link
Member

The bug starts in the code here:

rem resolve ~ to user home (USERPROFILE)

So the problem is that this script has been refactored in commit ad2cf72#diff-78672940921d6ea3caa0fafb3281c3b2 but the part to resolve the tilde ~ that is not understood by windows properly was not changed accordingly. So before there where two variables var (variable name/key) and value (value of the env. variable) and now we only have line (entire line of variable assignment).
Hence the code can not work:

@hohwille
Copy link
Member

The problem is that windows BAT/CMD (and partially shell-scripting in general) is not a reasonable programming language but something for quick hacks and this really applies to BAT and CMD that is historically grown since many decades.
That is also why we redesigned from oasp4j-ide to devonfw-ide and reduced the amount of BAT/CMD scripting to an absolute minimum.
Anyhow, not an excuse for my lack in QA when I fixed #395 but introduced this bug here.

I will try to come up with a fix for this issue and replace ~ with the proper value of %USERPROFILE% and hopefully manage to do so without breaking something else. In reasonable programming languages replacing a substring in a string with the value of a variable is a trivial one-liner. In BAT/CMD hell this is a real challenge...

@hohwille
Copy link
Member

As expected already replacing a simple ~ with some static text is requiring tons of magic hacks in CMD replacing it with the content of a variable might be the work of a PhD thesis:
https://stackoverflow.com/questions/57610104/how-do-i-escape-tilde-in-batch-file-on-replacing-it-with-a-different-charact

@hohwille
Copy link
Member

Characters like ~, * or = are already reserved vor variable replacement syntax in CMD. Furhter there is no such concept of escaping. Maybe I could try to create a loop that iterates the string character by character and thereby appends the resolved string by copying the characters but replacing ~ with %USERPROFILE%.
However, we need to read all contents of multiple devon.properties files line by line. If that processing is getting much slower the usability will be pain. Maybe we have to implement a native program for windows compiled for x68 architecture and ship it with devonfw-ide.
If you have any cool ideas how to fix this easily please help us.

@hohwille hohwille removed the blocker severe bug that blocks users in their daily work and has to be fixed asap label Sep 22, 2020
@hohwille
Copy link
Member

I removed blocker label als you actually tweaked the default config that does not come with a ~:

export M2_REPO=${DEVON_IDE_HOME}/conf/.m2/repository

You may also use something like ${HOME} or ${USERPROFILE} instead of ~ as a workaround or even easier simply use the hardcoded path to your home directory if you already tweak your devon.properties.
Further you can simply stop using this crappy CMD and always use git-bash instead that is not affected.

Finally, tools like the JVM or Maven should already be capable to understand a path starting with ~ and those tools could implement this much easier than us in CMD hacks.
Still looking for a solution but as long as I am lost alone in CMD space I might not be able to fix this quickly...

@hohwille
Copy link
Member

hohwille commented Sep 22, 2020

I found that CMD uses ^ as escape character and in some other cases even \. It tested all possible scenarios but this does not work in any way with variable replacement.

@hohwille
Copy link
Member

According to maintenance it would be best to support only bash and stop users from using CMD, powershell or cygwin in devonfw-ide.
However, for freedome of usage all major windows shells shall be supported - even though it drives me nuts...
The biggest joke of CMD is that SHIFT command does not affect %* - see https://ss64.com/nt/shift.html.

@hohwille
Copy link
Member

hohwille commented Sep 22, 2020

I just figured out that CMD only supports 2 levels of nesting if «condition» ( «cmd1» ) else ( «cmd2» ). As it also does not support else if I can not append parameters like this:

  if not "%~9" == "" (
    set line=!line! %~3 %~4 %~5 %~6 %~7 %~8 %~9
  ) else (
    if not "%~8" == "" (
      set line=!line! %~3 %~4 %~5 %~6 %~7 %~8
    ) else (
      if not "%~7" == "" (
        set line=!line! %~3 %~4 %~5 %~6 %~7
      ) else (
        if not "%~6" == "" (
          set line=!line! %~3 %~4 %~5 %~6
        ) else (
          if not "%~5" == "" (
            set line=!line! %~3 %~4 %~5
          ) else (
            if not "%~4" == "" (
              set line=!line! %~3 %~4
            ) else (
              if not "%~3" == "" (
                set line=!line! %~3
              )
            )
          )
        )
      )
    )
  )

@hohwille hohwille linked a pull request Sep 22, 2020 that will close this issue
@hohwille hohwille added the windows specific for Microsoft Windows OS label Sep 22, 2020
@hohwille hohwille added this to the release:2020.08.002 milestone Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working scripts related to shell scripts (bash and CMD) windows specific for Microsoft Windows OS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants