From 3fcd896a717ce9c738a89e4b19bd0d5c76933894 Mon Sep 17 00:00:00 2001
From: Ouchen <mouchen1998+maingit@gmail.com>
Date: Fri, 23 Feb 2024 15:23:41 +0100
Subject: [PATCH 1/3] Fix paths problem

---
 .../main/java/com/devonfw/tools/ide/common/SystemPath.java  | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java b/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
index a3b5415af..e22c752a3 100644
--- a/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
+++ b/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
@@ -67,7 +67,8 @@ public SystemPath(String envPath, Path softwarePath, char pathSeparator, IdeCont
       } else {
         Path duplicate = this.tool2pathMap.putIfAbsent(tool, path);
         if (duplicate != null) {
-          context.warning("Duplicated tool path for tool: {} at path: {} with duplicated path: {}.", tool, path, duplicate);
+          context.warning("Duplicated tool path for tool: {} at path: {} with duplicated path: {}.", tool, path,
+              duplicate);
         }
       }
     }
@@ -167,11 +168,12 @@ public Path getPath(String tool) {
 
   /**
    * @param tool the name of the tool.
-   * @param path the new {@link #getPath(String) tool bin path}.
+   * @param path the new {@link #getPath(String) tool bin path} and {@link #paths}.
    */
   public void setPath(String tool, Path path) {
 
     this.tool2pathMap.put(tool, path);
+    this.paths.add(0, path);
   }
 
   @Override

From 9a4254e17f6e6a548cb55a41f8f11db87b51f8ec Mon Sep 17 00:00:00 2001
From: Ouchen <mouchen1998+maingit@gmail.com>
Date: Mon, 26 Feb 2024 11:42:47 +0100
Subject: [PATCH 2/3] Revert "Fix paths problem"

This reverts commit 3fcd896a717ce9c738a89e4b19bd0d5c76933894.
---
 .../main/java/com/devonfw/tools/ide/common/SystemPath.java  | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java b/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
index e22c752a3..a3b5415af 100644
--- a/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
+++ b/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
@@ -67,8 +67,7 @@ public SystemPath(String envPath, Path softwarePath, char pathSeparator, IdeCont
       } else {
         Path duplicate = this.tool2pathMap.putIfAbsent(tool, path);
         if (duplicate != null) {
-          context.warning("Duplicated tool path for tool: {} at path: {} with duplicated path: {}.", tool, path,
-              duplicate);
+          context.warning("Duplicated tool path for tool: {} at path: {} with duplicated path: {}.", tool, path, duplicate);
         }
       }
     }
@@ -168,12 +167,11 @@ public Path getPath(String tool) {
 
   /**
    * @param tool the name of the tool.
-   * @param path the new {@link #getPath(String) tool bin path} and {@link #paths}.
+   * @param path the new {@link #getPath(String) tool bin path}.
    */
   public void setPath(String tool, Path path) {
 
     this.tool2pathMap.put(tool, path);
-    this.paths.add(0, path);
   }
 
   @Override

From fbc47b548af4199b87b5251bbaff78fefa4b91cc Mon Sep 17 00:00:00 2001
From: Ouchen <mouchen1998+maingit@gmail.com>
Date: Mon, 26 Feb 2024 11:51:31 +0100
Subject: [PATCH 3/3] Fix paths problem by also iterating through tool2pathMap

---
 .../java/com/devonfw/tools/ide/common/SystemPath.java     | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java b/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
index a3b5415af..a1bb433b3 100644
--- a/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
+++ b/cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
@@ -139,6 +139,14 @@ public Path findBinary(Path toolPath) {
     String fileName = toolPath.getFileName().toString();
 
     if (parent == null) {
+
+      for (Path path : tool2pathMap.values()) {
+        Path binaryPath = findBinaryInOrder(path, fileName);
+        if (binaryPath != null) {
+          return binaryPath;
+        }
+      }
+
       for (Path path : this.paths) {
         Path binaryPath = findBinaryInOrder(path, fileName);
         if (binaryPath != null) {