ProcessContext should compute PATH on run and not in constructor #556
Labels
enhancement
New feature or request
environment
EnvironmentCommandlet, env variables, path, etc.
process
executing external programs (ProcessContext)
As a IDEasy developer, I want to use
ProcessContext
seamlessly so that I do not cause bugs if I do not know its implementation details.The problem started in PR #515 with this code:
I left a review comment that we should move the duplicated code to create the
ProcessContext
before theif
statement to avoid redundancy.However, what we then figured out is the following:
this.context.newProcess()
is creating a newProcessContextImpl
and its constructor is computing all environment variables and setting them in theProcessBuilder
. Doing this at construction time in general makes sense since we might usewithEnvVar
method to override some environment variable.However, the when the environment variables are evaluated and set, this also includes the
PATH
variable:IDEasy/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java
Line 24 in c6c7d23
Therefore the recent path is evaluated from the
SystemPath
:IDEasy/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
Line 231 in c6c7d23
However, that value (can) change[s] during the installation of tools because if a tool gets newly installed a new folder like
software/«tool»/bin
may be created and therefore added toSystemPath
and therefore end up in the value ofPATH
.So if
install
is called after theProcessContext
is created, we can cause a bug.Even worse with the tool-dependencies approach we now have to create the
ProcessContext
before in order to pass it to theinstall
method and "tweak" it in there (e.g. fortomcat
the variableCATALINA_HOME
may be set and becausetomcat
depends onjava
it will delegate installation of a compatible version ofjava
and therefore setJAVA_HOME
to that installation).As a result we IMHO need to handle the
PATH
variable in a special way and when we callProcessContext.run()
we should compute the latestPATH
and set it as environment variable in theProcessBuilder
. IMHO it is simpler to just update thePATH
inrun()
and therefore "compute" it two times: at construction time and then again inrun()
. This does not harm since we manage thePATH
efficiently viaSystemPath
and actively update it frominstall
so we do not have to do directory traversals to compute thePATH
every time (only happens when IDEasy is launched and context is created).Theoretically some case could happen, where someone creates a
ProcessContext
and wants to set a customPATH
viawithEnvVar
and that would then stop working because we overwrite this later in therun
method. If somebody wants to solve this story with perfection, he could track this case and then prevent the auto-update, but it is also fine if we ignore this until this problem may ever happen and then create another bug issue for it.The text was updated successfully, but these errors were encountered: