Skip to content

Commit 8ba76dc

Browse files
#1559: Fix duplicated PATH entry (#1566)
Co-authored-by: Jörg Hohwiller <[email protected]>
1 parent 669ec08 commit 8ba76dc

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Release with new features and bugfixes:
1111
* https://github.com/devonfw/IDEasy/issues/1169[#1169]: mklink fails if link already exists
1212
* https://github.com/devonfw/IDEasy/issues/1553[#1553]: IDEasy is slow since 2025.09.001
1313
* https://github.com/devonfw/IDEasy/issues/1555[#1555]: Handle npm_config_prefix environment variable
14+
* https://github.com/devonfw/IDEasy/issues/1559[#1559]: IDEasy MSI installer creates multiple PATH entries
1415
* https://github.com/devonfw/IDEasy/issues/1551[#1551]: Display network connection issues in status
1516
* https://github.com/devonfw/IDEasy/issues/1560[#1560]: Enable trace logging in IDEasy setup script
1617

cli/src/main/java/com/devonfw/tools/ide/tool/IdeasyCommandlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private void installIdeasyWindowsEnv(Path ideRoot, Path installationPath) {
227227
+ "Otherwise all is correct and you can continue.");
228228
this.context.askToContinue("Are you sure you want to override your PATH?");
229229
} else {
230-
path.removeEntries(s -> s.endsWith(IDE_BIN));
230+
path.removeEntries(s -> s.endsWith(IDE_INSTALLATION_BIN));
231231
}
232232
path.getEntries().add(ideasyBinPath.toString());
233233
helper.setUserEnvironmentValue(IdeVariables.PATH.getName(), path.toString());

cli/src/test/java/com/devonfw/tools/ide/tool/IdeasyCommandletTest.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,34 @@ public void testRemoveObsoleteEntryFromWindowsPath() {
3737
assertThat(IdeasyCommandlet.removeObsoleteEntryFromWindowsPath(path)).isEqualTo(path);
3838
}
3939

40-
/** Test of {@link IdeasyCommandlet#installIdeasy(Path)}. */
40+
/**
41+
* Tests if the installation on windows did not add a 2nd path to IDEasy to the PATH environment variable and instead removed the old one and updated it.
42+
* See:
43+
* <a href="https://github.com/devonfw/IDEasy/issues/1559">#1559</a> for reference.
44+
*/
45+
@Test
46+
public void testInstallDoesNotAddPathEntryTwiceOnWindows() {
47+
// arrange
48+
SystemInfo systemInfo = SystemInfoMock.of("windows");
49+
IdeTestContext context = newContext("install");
50+
context.setIdeRoot(null);
51+
context.setSystemInfo(systemInfo);
52+
context.getStartContext().setForceMode(true);
53+
WindowsHelper helper = context.getWindowsHelper();
54+
String originalPath = helper.getUserEnvironmentValue("PATH");
55+
IdeasyCommandlet ideasy = new IdeasyCommandlet(context);
56+
// act
57+
ideasy.installIdeasy(context.getUserHome().resolve("Downloads/ide-cli"));
58+
String newPath = originalPath.replace("C:\\projects\\_ide\\installation\\bin;", "");
59+
// assert
60+
assertThat(helper.getUserEnvironmentValue("PATH")).isEqualTo(newPath + ";" + context.getUserHome().resolve("projects/_ide/installation/bin"));
61+
}
62+
63+
/**
64+
* Test of {@link IdeasyCommandlet#installIdeasy(Path)}.
65+
*
66+
* @param os to use
67+
*/
4168
@ParameterizedTest
4269
@ValueSource(strings = { "windows", "mac", "linux" })
4370
public void testInstallIdeasy(String os) {
@@ -51,7 +78,7 @@ public void testInstallIdeasy(String os) {
5178
WindowsHelper helper = context.getWindowsHelper();
5279
String originalPath = helper.getUserEnvironmentValue("PATH");
5380
if (systemInfo.isWindows()) {
54-
helper.setUserEnvironmentValue("PATH", "C:\\projects\\_ide\\bin;" + originalPath);
81+
helper.setUserEnvironmentValue("PATH", "C:\\projects\\_ide\\installation\\bin;" + originalPath);
5582
}
5683
Path ideRoot = context.getUserHome().resolve("projects");
5784
String addedRcLines =
@@ -73,7 +100,8 @@ public void testInstallIdeasy(String os) {
73100
verifyInstallation(releasePath);
74101
if (systemInfo.isWindows()) {
75102
assertThat(helper.getUserEnvironmentValue("IDE_ROOT")).isEqualTo(ideRoot.toString());
76-
assertThat(helper.getUserEnvironmentValue("PATH")).isEqualTo(originalPath + ";" + context.getUserHome().resolve("projects/_ide/installation/bin"));
103+
String newPath = originalPath.replace("C:\\projects\\_ide\\installation\\bin;", "");
104+
assertThat(helper.getUserEnvironmentValue("PATH")).isEqualTo(newPath + ";" + context.getUserHome().resolve("projects/_ide/installation/bin"));
77105
assertThat(context.getUserHome().resolve(".gitconfig")).hasContent("[core]\nlongpaths = true");
78106
}
79107
assertThat(context.getUserHome().resolve(".bashrc")).hasContent(addedRcLines);

0 commit comments

Comments
 (0)