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

#321: refactoring to improve path conversion logic #393

Merged
merged 10 commits into from
Jun 18, 2024

Conversation

hohwille
Copy link
Member

Fixes #321

  • remove path conversion logic from EnvironmentCommandlet and moved it to WindowsPathSyntax
  • instead just determine proper WindowsPathSyntax according to OS and --bash flag
  • pass this WindowsPathSyntax to collectVariables method of EnvironmentVariables that was extended with a variant taking this parameter.
  • This passes it further to getValue method that has been extended in the same way.
  • Again it is passed further to getDefaultValueAsString method of VariableDefinition that has been extended accordingly.
  • Finally, VariableDefinitionPath and VariableDefinitionSystemPath now honor this new parameter to do the actual path conversion.

@hohwille hohwille added this to the release:2024.06.001 milestone Jun 14, 2024
@hohwille hohwille added enhancement New feature or request environment EnvironmentCommandlet, env variables, path, etc. windows specific for Microsoft Windows OS labels Jun 14, 2024
@hohwille hohwille self-assigned this Jun 14, 2024
@hohwille
Copy link
Member Author

Seems I did something wrong. My code/test behaves differently on Linux and therefore fails:

[ERROR] Tests run: 6, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.015 s <<< FAILURE! -- in com.devonfw.tools.ide.os.WindowsPathSyntaxTest
[ERROR] com.devonfw.tools.ide.os.WindowsPathSyntaxTest.testMsys -- Time elapsed: 0.007 s <<< FAILURE!
org.opentest4j.AssertionFailedError: 

expected: "/c/Windows/system32/drivers/etc/hosts"
 but was: "C:\Windows\system32\drivers\etc\hosts"

Seems that Path on Linux represents the exact path given as string differently than on Windows...

@hohwille
Copy link
Member Author

Ok the Linux/Mac error is a nice one:
If we do Path.of("C:\Windows\system32\drivers\etc\hosts") on Windows, we get the proper absolute path while on Linux or Mac, we get a relative Path with just one segment (file or folder) named C:\Windows\system32\drivers\etc\hosts.
OS abstraction is usually great in Java and you get reproducible behavior on any OS but not work here since the FileSystem implementation is intentionally OS specific. So either we have to ignore such tests if we are not on Windows or we have to build in ugly workarounds/hacks for it...

@slskiba
Copy link
Contributor

slskiba commented Jun 17, 2024

With the missing change you pushed, output looks good now for env on Windows. However for env --bash, some variables are still not converted correctly:

ide> env --bash
export PATH="/c/projects/IDEasy/software/node:/ [...]
[...]
export AWS_SHARED_CREDENTIALS_FILE="C:\projects\IDEasy\conf\aws\credentials"
IDE_HOME="/c/projects/IDEasy"
export MAVEN_ARGS="-s C:\projects\IDEasy\conf\mvn\settings.xml"
[...]

@hohwille
Copy link
Member Author

I have updated, tested, and debugged my code with more care and detail.

export AWS_SHARED_CREDENTIALS_FILE="C:\projects\IDEasy\conf\aws\credentials"

This is fixed on my end now.

export MAVEN_ARGS="-s C:\projects\IDEasy\conf\mvn\settings.xml"

I added a change to "fix" this but commented it out since it is most probably correct as is and "fixing" it to git-bash syntax might even break maven.
We can test this and if it works with maven (even without IDEasy involved) properly with git-bash syntax, we can comment in the out-commented code to avoid potential confusion.
However, in general on Windows the Windows Paths are typically correct and even required for native processes. Only to make things working in git-bash itself, we need all this messy path conversion stuff.
I also have some doubts that converting M2_REPO to git-bash syntax will be correct and not cause any maven bug.

@coveralls
Copy link
Collaborator

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9547168999

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 164 unchanged lines in 10 files lost coverage.
  • Overall coverage decreased (-0.05%) to 60.189%

Files with Coverage Reduction New Missed Lines %
com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java 2 74.07%
com/devonfw/tools/ide/variable/VariableDefinition.java 3 57.14%
com/devonfw/tools/ide/environment/EnvironmentVariablesMap.java 5 60.0%
com/devonfw/tools/ide/variable/VariableDefinitionPath.java 5 55.56%
com/devonfw/tools/ide/common/SystemPath.java 8 76.87%
com/devonfw/tools/ide/context/IdeContext.java 11 42.55%
com/devonfw/tools/ide/environment/AbstractEnvironmentVariables.java 12 78.24%
com/devonfw/tools/ide/os/WindowsPathSyntax.java 15 73.13%
com/devonfw/tools/ide/process/ProcessContextImpl.java 21 75.49%
com/devonfw/tools/ide/context/AbstractIdeContext.java 82 56.91%
Totals Coverage Status
Change from base Build 9515396777: -0.05%
Covered Lines: 4749
Relevant Lines: 7589

💛 - Coveralls

Copy link
Contributor

@slskiba slskiba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now works as I would expect it to 👍

@coveralls
Copy link
Collaborator

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9551353700

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 170 unchanged lines in 10 files lost coverage.
  • Overall coverage decreased (-0.05%) to 60.189%

Files with Coverage Reduction New Missed Lines %
com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java 2 74.07%
com/devonfw/tools/ide/variable/VariableDefinition.java 3 57.14%
com/devonfw/tools/ide/environment/EnvironmentVariablesMap.java 5 60.0%
com/devonfw/tools/ide/variable/VariableDefinitionPath.java 5 55.56%
com/devonfw/tools/ide/context/IdeContext.java 11 42.55%
com/devonfw/tools/ide/environment/AbstractEnvironmentVariables.java 12 78.24%
com/devonfw/tools/ide/common/SystemPath.java 14 76.87%
com/devonfw/tools/ide/os/WindowsPathSyntax.java 15 73.13%
com/devonfw/tools/ide/process/ProcessContextImpl.java 21 75.49%
com/devonfw/tools/ide/context/AbstractIdeContext.java 82 56.91%
Totals Coverage Status
Change from base Build 9515396777: -0.05%
Covered Lines: 4749
Relevant Lines: 7589

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 18, 2024

Pull Request Test Coverage Report for Build 9566600800

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 170 unchanged lines in 10 files lost coverage.
  • Overall coverage decreased (-0.05%) to 60.009%

Files with Coverage Reduction New Missed Lines %
com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java 2 74.07%
com/devonfw/tools/ide/variable/VariableDefinition.java 3 57.14%
com/devonfw/tools/ide/environment/EnvironmentVariablesMap.java 5 60.0%
com/devonfw/tools/ide/variable/VariableDefinitionPath.java 5 55.56%
com/devonfw/tools/ide/context/IdeContext.java 11 42.55%
com/devonfw/tools/ide/environment/AbstractEnvironmentVariables.java 12 78.24%
com/devonfw/tools/ide/common/SystemPath.java 14 76.87%
com/devonfw/tools/ide/os/WindowsPathSyntax.java 15 73.01%
com/devonfw/tools/ide/process/ProcessContextImpl.java 21 75.49%
com/devonfw/tools/ide/context/AbstractIdeContext.java 82 56.81%
Totals Coverage Status
Change from base Build 9552528477: -0.05%
Covered Lines: 4754
Relevant Lines: 7615

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 18, 2024

Pull Request Test Coverage Report for Build 9566610153

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 170 unchanged lines in 10 files lost coverage.
  • Overall coverage decreased (-0.05%) to 60.009%

Files with Coverage Reduction New Missed Lines %
com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java 2 74.07%
com/devonfw/tools/ide/variable/VariableDefinition.java 3 57.14%
com/devonfw/tools/ide/environment/EnvironmentVariablesMap.java 5 60.0%
com/devonfw/tools/ide/variable/VariableDefinitionPath.java 5 55.56%
com/devonfw/tools/ide/context/IdeContext.java 11 42.55%
com/devonfw/tools/ide/environment/AbstractEnvironmentVariables.java 12 78.24%
com/devonfw/tools/ide/common/SystemPath.java 14 76.87%
com/devonfw/tools/ide/os/WindowsPathSyntax.java 15 73.01%
com/devonfw/tools/ide/process/ProcessContextImpl.java 21 75.49%
com/devonfw/tools/ide/context/AbstractIdeContext.java 82 56.81%
Totals Coverage Status
Change from base Build 9552528477: -0.05%
Covered Lines: 4754
Relevant Lines: 7615

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 18, 2024

Pull Request Test Coverage Report for Build 9566925479

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 170 unchanged lines in 10 files lost coverage.
  • Overall coverage decreased (-0.05%) to 60.038%

Files with Coverage Reduction New Missed Lines %
com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java 2 74.07%
com/devonfw/tools/ide/variable/VariableDefinition.java 3 57.14%
com/devonfw/tools/ide/environment/EnvironmentVariablesMap.java 5 60.0%
com/devonfw/tools/ide/variable/VariableDefinitionPath.java 5 55.56%
com/devonfw/tools/ide/context/IdeContext.java 11 42.55%
com/devonfw/tools/ide/environment/AbstractEnvironmentVariables.java 12 78.24%
com/devonfw/tools/ide/common/SystemPath.java 14 76.87%
com/devonfw/tools/ide/os/WindowsPathSyntax.java 15 73.01%
com/devonfw/tools/ide/process/ProcessContextImpl.java 21 75.49%
com/devonfw/tools/ide/context/AbstractIdeContext.java 82 56.81%
Totals Coverage Status
Change from base Build 9566917428: -0.05%
Covered Lines: 4761
Relevant Lines: 7622

💛 - Coveralls

@hohwille hohwille merged commit 158fe03 into devonfw:main Jun 18, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request environment EnvironmentCommandlet, env variables, path, etc. windows specific for Microsoft Windows OS
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Paths not formatted correctly when running ide env --bash
3 participants