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 23 forks source link

ide create installs wrong Java version #588

Closed hohwille closed 2 months ago

hohwille commented 2 months ago

Expected behavior

As a IDEasy user, I want to setup a project with create command and get a consistent result so that I can rely on IDEasy.

Actual behavior

I get a wrong Java version installed:

Successfully installed java in version 22.0.2_9

However, if I look at settings/ide.properties to see what has been configured, I find this:

JAVA_VERSION=21*

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

  1. ide create demoproject -

Related/Dependent Issues

May be related to #131 However, with Java versions we already had strange effects because of this underscore semantics. See also #235

Comments/Hints:

If I later go the the project and call ide update, then it installs 21.0.4_7:

Successfully installed java in version 21.0.4_7 replacing previous version 22.0.2_9

This does not make sense.

Affected version:

hohwille commented 2 months ago

This bug is not specific for JAVA_VERSION. There is a severe design flaw in how we implemented CreateCommandlet: It creates the IdeContext to run the command from the current project or with no custom variables if we are not inside an IDE project. After cloning the settings, we need to create a new IdeContext or more likely update the existing IdeContext with the new cloned settings and new IDE_HOME location. This is currently not happening. As a result, I am installing the new project with the settings of the previous project where I did run the ide create command. This can have severe implications and cause effects that even wont repair themselves if I later run ide update on that newly created project.

hohwille commented 2 months ago

OK, I debugged the creation process and I was wrong with my previous comment: The code (setIdeHome) properly re-initializes the IdeContext but the problem is that it does that before cloning the settings. As a result there are no settings and the variables are empty. Hence no JAVA_VERSION or other such variables are defined and as a result we always get the latest version and not the versions configured in the settings. The reason that java gets installed with no variable defined comes from here: https://github.com/devonfw/IDEasy/blob/b782cc655a9cadab5a2a9e8a4962276536e5c196/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java#L32

So we install mvn by default that has a dependency to java. As a result, we just need to first clone the settings and initialize the config folder and then re-initialize the IdeContext.

hohwille commented 2 months ago

The only disadvantage I can see with the current solution is that we create and load the EnvironmentVariables three times:

  1. for the project where ide create is invoked
  2. on the new project before it is populated with settings
  3. on the new project after it is populated

We cannot easily omit 1. and we surely want 3. what is the actual fix of this issue. Omitting 2. would save some millis and directory operations but IMHO we should go for KISS and consistency.