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

#298: refactoring setting environment variables #1098

Conversation

paz-capgemini
Copy link
Contributor

Fixes #298

  • refactored the setting of environment variables for certain tools

@paz-capgemini paz-capgemini self-assigned this Feb 28, 2025
@coveralls
Copy link
Collaborator

coveralls commented Feb 28, 2025

Pull Request Test Coverage Report for Build 13701033161

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 12 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.2%) to 68.471%

Files with Coverage Reduction New Missed Lines %
com/devonfw/tools/ide/tool/az/Azure.java 4 22.22%
com/devonfw/tools/ide/tool/aws/Aws.java 8 48.48%
Totals Coverage Status
Change from base Build 13696612753: 0.2%
Covered Lines: 7887
Relevant Lines: 11072

💛 - Coveralls

Copy link
Member

@hohwille hohwille left a comment

Choose a reason for hiding this comment

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

@paz-capgemini thanks for your PR. All looks good to me. Great job 👍
I assume that this is in draft mode since you are still working on a JUnit test for this.
I will therefore wait for updates and until you take this out of draft mode.
However, I already give my approval since the main code changes are complete and correct.

I was thinking to only set these variables if they are not already set.
However, I now came to the idea that it would be smarter to create a separate feature/story/PR for that and that we can do that already in [Local]ToolCommandlet where we call this setEnvironment method. After PR #1085 is merged, we could simply create a wrapper for ProcessContext as implementation of EnvironmentContext that implements withEnvVar such that only if the variable is not already defined, it will be set in the ProcessContext.
So we leave this out of this PR.

@paz-capgemini
Copy link
Contributor Author

The linux test for Aws, or to be more precise testing the symlink part seems to be a bit more complicated. That applies to the Azure test as well since inside the postInstall also creates a symlink.

Even on linux itself, the test fails due to the following problem:
When trying to create the symlink, it either fails because the directory does not exist or if it does exist, then it fails with a FileAlreadyExistsException.

If the folder already exists:

16:04:35.287 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Tool aws not installed in /home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/project/software/aws
16:04:35.510 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Tool aws has 0 other tool(s) as dependency
16:04:35.511 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Could not find version 2.24.15 so using 'default' for aws/aws
16:04:35.512 [main] - WARN  - c.d.tools.ide.log.IdeSubLoggerSlf4j - Found directory for download at target/test-projects/aws/repository/aws/aws/default/linux hence copying without extraction!
16:04:35.513 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Starting to copy target/test-projects/aws/repository/aws/aws/default/linux recursively to /home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15
16:04:35.522 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Running command '/home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15/install' using bash with arguments '-i' '/home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15' '-b' '/home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15' ...
16:04:35.558 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Creating relative symbolic link /home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15/aws pointing to aws
16:04:35.559 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Step 'Install aws' ended with failure.

java.lang.RuntimeException: java.nio.file.FileAlreadyExistsException: /home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15/aws

    at com.devonfw.tools.ide.io.FileAccessImpl.symlink(FileAccessImpl.java:505)
    at com.devonfw.tools.ide.tool.aws.Aws.postExtract(Aws.java:57)
    at com.devonfw.tools.ide.io.FileAccessImpl.postExtractHook(FileAccessImpl.java:594)
    at com.devonfw.tools.ide.io.FileAccessImpl.extract(FileAccessImpl.java:556)
    at com.devonfw.tools.ide.tool.LocalToolCommandlet.installTool(LocalToolCommandlet.java:218)
    at com.devonfw.tools.ide.tool.LocalToolCommandlet.installTool(LocalToolCommandlet.java:167)
    at com.devonfw.tools.ide.tool.LocalToolCommandlet.install(LocalToolCommandlet.java:80)
    at com.devonfw.tools.ide.tool.ToolCommandlet.install(ToolCommandlet.java:246)
    at com.devonfw.tools.ide.tool.ToolCommandlet.install(ToolCommandlet.java:235)
    at com.devonfw.tools.ide.tool.aws.AwsTest.testAwsInstallLinux(AwsTest.java:108)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.nio.file.FileAlreadyExistsException: /home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15/aws
    at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:94)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
    at java.base/sun.nio.fs.UnixFileSystemProvider.createSymbolicLink(UnixFileSystemProvider.java:537)
    at java.base/java.nio.file.Files.createSymbolicLink(Files.java:1070)
    at com.devonfw.tools.ide.io.FileAccessImpl.symlink(FileAccessImpl.java:497)
    ... 12 more

If the folder does not exist:

16:08:41.769 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Deleting target/test-projects/aws ...
16:08:41.782 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Starting to copy src/test/resources/ide-projects/aws recursively to target/test-projects/aws
16:08:41.829 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Tool aws not installed in /home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/project/software/aws
16:08:42.063 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Tool aws has 0 other tool(s) as dependency
16:08:42.064 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Could not find version 2.24.15 so using 'default' for aws/aws
16:08:42.066 [main] - WARN  - c.d.tools.ide.log.IdeSubLoggerSlf4j - Found directory for download at target/test-projects/aws/repository/aws/aws/default/linux hence copying without extraction!
16:08:42.067 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Starting to copy target/test-projects/aws/repository/aws/aws/default/linux recursively to /home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15
16:08:42.077 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Running command '/home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15/install' using bash with arguments '-i' '/home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15' '-b' '/home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15' ...
16:08:42.102 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Step 'Install aws' ended with failure.

java.lang.RuntimeException: Failed to replace absolute link (/home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15/aws) provided by AWS install script with relative link.

    at com.devonfw.tools.ide.tool.aws.Aws.postExtract(Aws.java:59)
    at com.devonfw.tools.ide.io.FileAccessImpl.postExtractHook(FileAccessImpl.java:594)
    at com.devonfw.tools.ide.io.FileAccessImpl.extract(FileAccessImpl.java:556)
    at com.devonfw.tools.ide.tool.LocalToolCommandlet.installTool(LocalToolCommandlet.java:218)
    at com.devonfw.tools.ide.tool.LocalToolCommandlet.installTool(LocalToolCommandlet.java:167)
    at com.devonfw.tools.ide.tool.LocalToolCommandlet.install(LocalToolCommandlet.java:80)
    at com.devonfw.tools.ide.tool.ToolCommandlet.install(ToolCommandlet.java:246)
    at com.devonfw.tools.ide.tool.ToolCommandlet.install(ToolCommandlet.java:235)
    at com.devonfw.tools.ide.tool.aws.AwsTest.testAwsInstallLinux(AwsTest.java:108)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.nio.file.NoSuchFileException: /home/pazngo/projects/myproject/workspaces/main/IDEasy/cli/target/test-projects/aws/_ide/software/default/aws/aws/2.24.15/aws
    at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
    at java.base/sun.nio.fs.UnixPath.toRealPath(UnixPath.java:834)
    at com.devonfw.tools.ide.tool.aws.Aws.postExtract(Aws.java:57)
    ... 11 more

After some consideration with @jan-vcapgemini , we came to the conclusion that the complexity is quite high to resolve this and the benefit is not that large.

@paz-capgemini paz-capgemini marked this pull request as ready for review March 6, 2025 15:13
Copy link
Member

@hohwille hohwille left a comment

Choose a reason for hiding this comment

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

@paz-capgemini thanks for also adding the test for AWS slightly increasing our coverage. Great job!👍

For the record: AwsTest.testAwsSetEnvironment is also performing the installation of AWS. It could therefore be merged with testAwsInstall to avoid "waste". I know that it is also beneficial to have dedicated tests for smaller aspects, but all these tests using newContext are recursively copying a directory structure and initialising the context with it what is slow compared to a plain class test. Since this is just a personal flavour and there is absolutely nothing wrong with your test, I merge it as is. Currently our CI times are still good enough and we do not yet need to squeeze every second we can out of the build times.

@hohwille hohwille merged commit 673c5f2 into devonfw:main Mar 7, 2025
4 checks passed
@hohwille hohwille added this to the release:2025.03.001 milestone Mar 7, 2025
@hohwille hohwille added the reviewed Marks PRs that have been presented in the sprint-review meeting or that do not need to be presented. label Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reviewed Marks PRs that have been presented in the sprint-review meeting or that do not need to be presented.
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Refactoring setting of environment variables
4 participants