• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 19640865660

24 Nov 2025 04:05PM UTC coverage: 69.024% (+0.1%) from 68.924%
19640865660

push

github

web-flow
#1561: Fix BASH_PATH not used properly (#1577)

Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>

3562 of 5651 branches covered (63.03%)

Branch coverage included in aggregate %.

9262 of 12928 relevant lines covered (71.64%)

3.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.13
cli/src/main/java/com/devonfw/tools/ide/tool/IdeasyCommandlet.java
1
package com.devonfw.tools.ide.tool;
2

3
import java.io.Reader;
4
import java.io.Writer;
5
import java.nio.file.Files;
6
import java.nio.file.Path;
7
import java.util.ArrayList;
8
import java.util.Iterator;
9
import java.util.List;
10
import java.util.Set;
11

12
import com.devonfw.tools.ide.cli.CliException;
13
import com.devonfw.tools.ide.commandlet.UpgradeMode;
14
import com.devonfw.tools.ide.common.SimpleSystemPath;
15
import com.devonfw.tools.ide.common.Tag;
16
import com.devonfw.tools.ide.context.IdeContext;
17
import com.devonfw.tools.ide.io.FileAccess;
18
import com.devonfw.tools.ide.io.ini.IniFile;
19
import com.devonfw.tools.ide.io.ini.IniSection;
20
import com.devonfw.tools.ide.os.WindowsHelper;
21
import com.devonfw.tools.ide.os.WindowsPathSyntax;
22
import com.devonfw.tools.ide.process.ProcessMode;
23
import com.devonfw.tools.ide.process.ProcessResult;
24
import com.devonfw.tools.ide.tool.mvn.MvnArtifact;
25
import com.devonfw.tools.ide.tool.mvn.MvnBasedLocalToolCommandlet;
26
import com.devonfw.tools.ide.tool.repository.MvnRepository;
27
import com.devonfw.tools.ide.variable.IdeVariables;
28
import com.devonfw.tools.ide.version.IdeVersion;
29
import com.devonfw.tools.ide.version.VersionIdentifier;
30
import com.fasterxml.jackson.databind.JsonNode;
31
import com.fasterxml.jackson.databind.ObjectMapper;
32
import com.fasterxml.jackson.databind.node.ArrayNode;
33
import com.fasterxml.jackson.databind.node.ObjectNode;
34

35
/**
36
 * {@link MvnBasedLocalToolCommandlet} for IDEasy (ide-cli).
37
 */
38
public class IdeasyCommandlet extends MvnBasedLocalToolCommandlet {
39

40
  /** The {@link MvnArtifact} for IDEasy. */
41
  public static final MvnArtifact ARTIFACT = MvnArtifact.ofIdeasyCli("*!", "tar.gz", "${os}-${arch}");
6✔
42

43
  private static final String BASH_CODE_SOURCE_FUNCTIONS = "source \"$IDE_ROOT/_ide/installation/functions\"";
44

45
  /** The {@link #getName() tool name}. */
46
  public static final String TOOL_NAME = "ideasy";
47
  public static final String BASHRC = ".bashrc";
48
  public static final String ZSHRC = ".zshrc";
49
  public static final String IDE_BIN = "\\_ide\\bin";
50
  public static final String IDE_INSTALLATION_BIN = "\\_ide\\installation\\bin";
51

52
  private final UpgradeMode mode;
53

54
  /**
55
   * The constructor.
56
   *
57
   * @param context the {@link IdeContext}.
58
   */
59
  public IdeasyCommandlet(IdeContext context) {
60
    this(context, UpgradeMode.STABLE);
4✔
61
  }
1✔
62

63
  /**
64
   * The constructor.
65
   *
66
   * @param context the {@link IdeContext}.
67
   * @param mode the {@link UpgradeMode}.
68
   */
69
  public IdeasyCommandlet(IdeContext context, UpgradeMode mode) {
70

71
    super(context, TOOL_NAME, ARTIFACT, Set.of(Tag.PRODUCTIVITY, Tag.IDE));
8✔
72
    this.mode = mode;
3✔
73
  }
1✔
74

75
  @Override
76
  public VersionIdentifier getInstalledVersion() {
77

78
    return IdeVersion.getVersionIdentifier();
2✔
79
  }
80

81
  @Override
82
  public String getConfiguredEdition() {
83

84
    return this.tool;
×
85
  }
86

87
  @Override
88
  public VersionIdentifier getConfiguredVersion() {
89

90
    UpgradeMode upgradeMode = this.mode;
×
91
    if (upgradeMode == null) {
×
92
      if (IdeVersion.isSnapshot()) {
×
93
        upgradeMode = UpgradeMode.SNAPSHOT;
×
94
      } else {
95
        if (IdeVersion.getVersionIdentifier().getDevelopmentPhase().isStable()) {
×
96
          upgradeMode = UpgradeMode.STABLE;
×
97
        } else {
98
          upgradeMode = UpgradeMode.UNSTABLE;
×
99
        }
100
      }
101
    }
102
    return upgradeMode.getVersion();
×
103
  }
104

105
  @Override
106
  public Path getToolPath() {
107

108
    return this.context.getIdeInstallationPath();
×
109
  }
110

111
  @Override
112
  public boolean install(boolean silent) {
113

114
    this.context.requireOnline("upgrade of IDEasy", true);
5✔
115

116
    if (IdeVersion.isUndefined() && !this.context.isForceMode()) {
6!
117
      this.context.warning("You are using IDEasy version {} which indicates local development - skipping upgrade.", IdeVersion.getVersionString());
10✔
118
      return false;
2✔
119
    }
120
    return super.install(silent);
×
121
  }
122

123
  /**
124
   * @return the latest released {@link VersionIdentifier version} of IDEasy.
125
   */
126
  public VersionIdentifier getLatestVersion() {
127

128
    VersionIdentifier currentVersion = IdeVersion.getVersionIdentifier();
2✔
129
    if (IdeVersion.isUndefined()) {
2!
130
      return currentVersion;
2✔
131
    }
132
    VersionIdentifier configuredVersion = getConfiguredVersion();
×
133
    return getToolRepository().resolveVersion(this.tool, getConfiguredEdition(), configuredVersion, this);
×
134
  }
135

136
  /**
137
   * Checks if an update is available and logs according information.
138
   *
139
   * @return {@code true} if an update is available, {@code false} otherwise.
140
   */
141
  public boolean checkIfUpdateIsAvailable() {
142
    VersionIdentifier installedVersion = getInstalledVersion();
3✔
143
    this.context.success("Your version of IDEasy is {}.", installedVersion);
10✔
144
    if (IdeVersion.isSnapshot()) {
2!
145
      this.context.warning("You are using a SNAPSHOT version of IDEasy. For stability consider switching to a stable release via 'ide upgrade --mode=stable'");
4✔
146
    }
147
    if (this.context.isOffline()) {
4✔
148
      this.context.warning("Skipping check for newer version of IDEasy because you are offline.");
4✔
149
      return false;
2✔
150
    }
151
    VersionIdentifier latestVersion = getLatestVersion();
3✔
152
    if (installedVersion.equals(latestVersion)) {
4!
153
      this.context.success("Your are using the latest version of IDEasy and no update is available.");
4✔
154
      return false;
2✔
155
    } else {
156
      this.context.interaction("Your version of IDEasy is {} but version {} is available. Please run the following command to upgrade to the latest version:\n"
×
157
          + "ide upgrade", installedVersion, latestVersion);
158
      return true;
×
159
    }
160
  }
161

162
  /**
163
   * Initial installation of IDEasy.
164
   *
165
   * @param cwd the {@link Path} to the current working directory.
166
   * @see com.devonfw.tools.ide.commandlet.InstallCommandlet
167
   */
168
  public void installIdeasy(Path cwd) {
169
    Path ideRoot = determineIdeRoot(cwd);
4✔
170
    Path idePath = ideRoot.resolve(IdeContext.FOLDER_UNDERSCORE_IDE);
4✔
171
    Path installationPath = idePath.resolve(IdeContext.FOLDER_INSTALLATION);
4✔
172
    Path ideasySoftwarePath = idePath.resolve(IdeContext.FOLDER_SOFTWARE).resolve(MvnRepository.ID).resolve(IdeasyCommandlet.TOOL_NAME)
8✔
173
        .resolve(IdeasyCommandlet.TOOL_NAME);
2✔
174
    Path ideasyVersionPath = ideasySoftwarePath.resolve(IdeVersion.getVersionString());
4✔
175
    if (Files.isDirectory(ideasyVersionPath)) {
5!
176
      throw new CliException("IDEasy is already installed at " + ideasyVersionPath + " - if your installation is broken, delete it manually and rerun setup!");
×
177
    }
178
    FileAccess fileAccess = this.context.getFileAccess();
4✔
179
    List<Path> installationArtifacts = new ArrayList<>();
4✔
180
    boolean success = true;
2✔
181
    success &= addInstallationArtifact(cwd, "bin", true, installationArtifacts);
9✔
182
    success &= addInstallationArtifact(cwd, "functions", true, installationArtifacts);
9✔
183
    success &= addInstallationArtifact(cwd, "internal", true, installationArtifacts);
9✔
184
    success &= addInstallationArtifact(cwd, "system", true, installationArtifacts);
9✔
185
    success &= addInstallationArtifact(cwd, "IDEasy.pdf", true, installationArtifacts);
9✔
186
    success &= addInstallationArtifact(cwd, "setup", true, installationArtifacts);
9✔
187
    success &= addInstallationArtifact(cwd, "setup.bat", false, installationArtifacts);
9✔
188
    if (!success) {
2!
189
      throw new CliException("IDEasy release is inconsistent at " + cwd);
×
190
    }
191
    fileAccess.mkdirs(ideasyVersionPath);
3✔
192
    for (Path installationArtifact : installationArtifacts) {
10✔
193
      fileAccess.copy(installationArtifact, ideasyVersionPath);
4✔
194
    }
1✔
195
    this.context.writeVersionFile(IdeVersion.getVersionIdentifier(), ideasyVersionPath);
5✔
196
    fileAccess.symlink(ideasyVersionPath, installationPath);
4✔
197
    addToShellRc(BASHRC, ideRoot, null);
5✔
198
    addToShellRc(ZSHRC, ideRoot, "autoload -U +X bashcompinit && bashcompinit");
5✔
199
    installIdeasyWindowsEnv(ideRoot, installationPath);
4✔
200
    this.context.success("IDEasy has been installed successfully on your system.");
4✔
201
    this.context.warning("IDEasy has been setup for new shells but it cannot work in your current shell(s).\n"
4✔
202
        + "Reboot or open a new terminal to make it work.");
203
  }
1✔
204

205
  private void installIdeasyWindowsEnv(Path ideRoot, Path installationPath) {
206
    if (!this.context.getSystemInfo().isWindows()) {
5✔
207
      return;
1✔
208
    }
209
    WindowsHelper helper = WindowsHelper.get(this.context);
4✔
210
    helper.setUserEnvironmentValue(IdeVariables.IDE_ROOT.getName(), ideRoot.toString());
6✔
211
    String userPath = helper.getUserEnvironmentValue(IdeVariables.PATH.getName());
5✔
212
    if (userPath == null) {
2!
213
      this.context.error("Could not read user PATH from registry!");
×
214
    } else {
215
      this.context.info("Found user PATH={}", userPath);
10✔
216
      Path ideasyBinPath = installationPath.resolve("bin");
4✔
217
      SimpleSystemPath path = SimpleSystemPath.of(userPath, ';');
4✔
218
      if (path.getEntries().isEmpty()) {
4!
219
        this.context.warning("ATTENTION:\n"
×
220
            + "Your user specific PATH variable seems to be empty.\n"
221
            + "You can double check this by pressing [Windows][r] and launch the program SystemPropertiesAdvanced.\n"
222
            + "Then click on 'Environment variables' and check if 'PATH' is set in the 'user variables' from the upper list.\n"
223
            + "In case 'PATH' is defined there non-empty and you get this message, please abort and give us feedback:\n"
224
            + "https://github.com/devonfw/IDEasy/issues\n"
225
            + "Otherwise all is correct and you can continue.");
226
        this.context.askToContinue("Are you sure you want to override your PATH?");
×
227
      } else {
228
        path.removeEntries(s -> s.endsWith(IDE_INSTALLATION_BIN));
7✔
229
      }
230
      path.getEntries().add(ideasyBinPath.toString());
6✔
231
      helper.setUserEnvironmentValue(IdeVariables.PATH.getName(), path.toString());
6✔
232
      setGitLongpaths();
2✔
233
    }
234
  }
1✔
235

236
  private void setGitLongpaths() {
237
    this.context.getGitContext().findGitRequired();
5✔
238
    Path configPath = this.context.getUserHome().resolve(".gitconfig");
6✔
239
    FileAccess fileAccess = this.context.getFileAccess();
4✔
240
    IniFile iniFile = fileAccess.readIniFile(configPath);
4✔
241
    IniSection coreSection = iniFile.getOrCreateSection("core");
4✔
242
    coreSection.setProperty("longpaths", "true");
4✔
243
    fileAccess.writeIniFile(iniFile, configPath);
4✔
244
  }
1✔
245

246
  /**
247
   * Sets up Windows Terminal with Git Bash integration.
248
   */
249
  public void setupWindowsTerminal() {
250
    if (!this.context.getSystemInfo().isWindows()) {
×
251
      return;
×
252
    }
253
    if (!isWindowsTerminalInstalled()) {
×
254
      try {
255
        installWindowsTerminal();
×
256
      } catch (Exception e) {
×
257
        this.context.error(e, "Failed to install Windows Terminal!");
×
258
      }
×
259
    }
260
    configureWindowsTerminalGitBash();
×
261
  }
×
262

263
  /**
264
   * Checks if Windows Terminal is installed.
265
   *
266
   * @return {@code true} if Windows Terminal is installed, {@code false} otherwise.
267
   */
268
  private boolean isWindowsTerminalInstalled() {
269
    try {
270
      ProcessResult result = this.context.newProcess()
×
271
          .executable("powershell")
×
272
          .addArgs("-Command", "Get-AppxPackage -Name Microsoft.WindowsTerminal")
×
273
          .run(ProcessMode.DEFAULT_CAPTURE);
×
274
      return result.isSuccessful() && !result.getOut().isEmpty();
×
275
    } catch (Exception e) {
×
276
      this.context.debug("Failed to check Windows Terminal installation: {}", e.getMessage());
×
277
      return false;
×
278
    }
279
  }
280

281
  /**
282
   * Installs Windows Terminal using winget.
283
   */
284
  private void installWindowsTerminal() {
285
    try {
286
      this.context.info("Installing Windows Terminal...");
×
287
      ProcessResult result = this.context.newProcess()
×
288
          .executable("winget")
×
289
          .addArgs("install", "Microsoft.WindowsTerminal")
×
290
          .run(ProcessMode.DEFAULT);
×
291
      if (result.isSuccessful()) {
×
292
        this.context.success("Windows Terminal has been installed successfully.");
×
293
      } else {
294
        this.context.warning("Failed to install Windows Terminal. Please install it manually from Microsoft Store.");
×
295
      }
296
    } catch (Exception e) {
×
297
      this.context.warning("Failed to install Windows Terminal: {}. Please install it manually from Microsoft Store.", e.getMessage());
×
298
    }
×
299
  }
×
300

301
  /**
302
   * Configures Git Bash integration in Windows Terminal.
303
   */
304
  protected void configureWindowsTerminalGitBash() {
305
    Path settingsPath = getWindowsTerminalSettingsPath();
3✔
306
    if (settingsPath == null || !Files.exists(settingsPath)) {
7!
307
      this.context.warning("Windows Terminal settings file not found. Cannot configure Git Bash integration.");
×
308
      return;
×
309
    }
310

311
    try {
312
      Path bashPath = this.context.findBash();
4✔
313
      if (bashPath == null) {
2!
314
        this.context.warning("Git Bash not found. Cannot configure Windows Terminal integration.");
×
315
        return;
×
316
      }
317

318
      configureGitBashProfile(settingsPath, bashPath.toString());
5✔
319
      this.context.success("Git Bash has been configured in Windows Terminal.");
4✔
320
    } catch (Exception e) {
×
321
      this.context.warning("Failed to configure Git Bash in Windows Terminal: {}", e.getMessage());
×
322
    }
1✔
323
  }
1✔
324

325
  /**
326
   * Gets the Windows Terminal settings file path.
327
   *
328
   * @return the {@link Path} to the Windows Terminal settings file, or {@code null} if not found.
329
   */
330
  protected Path getWindowsTerminalSettingsPath() {
331
    Path localAppData = this.context.getUserHome().resolve("AppData").resolve("Local");
8✔
332
    Path packagesPath = localAppData.resolve("Packages");
4✔
333

334
    // Try the new Windows Terminal package first
335
    Path newTerminalPath = packagesPath.resolve("Microsoft.WindowsTerminal_8wekyb3d8bbwe")
4✔
336
        .resolve("LocalState").resolve("settings.json");
4✔
337
    if (Files.exists(newTerminalPath)) {
5!
338
      return newTerminalPath;
2✔
339
    }
340

341
    // Try the old Windows Terminal Preview package
342
    Path previewPath = packagesPath.resolve("Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe")
×
343
        .resolve("LocalState").resolve("settings.json");
×
344
    if (Files.exists(previewPath)) {
×
345
      return previewPath;
×
346
    }
347

348
    return null;
×
349
  }
350

351
  /**
352
   * Configures Git Bash profile in Windows Terminal settings.
353
   *
354
   * @param settingsPath the {@link Path} to the Windows Terminal settings file.
355
   * @param bashPath the path to the Git Bash executable.
356
   */
357
  private void configureGitBashProfile(Path settingsPath, String bashPath) throws Exception {
358

359
    ObjectMapper mapper = new ObjectMapper();
4✔
360
    ObjectNode root;
361
    try (Reader reader = Files.newBufferedReader(settingsPath)) {
3✔
362
      JsonNode rootNode = mapper.readTree(reader);
4✔
363
      root = (ObjectNode) rootNode;
3✔
364
    }
365

366
    // Get or create profiles object
367
    ObjectNode profiles = (ObjectNode) root.get("profiles");
5✔
368
    if (profiles == null) {
2!
369
      profiles = mapper.createObjectNode();
×
370
      root.set("profiles", profiles);
×
371
    }
372

373
    // Get or create list array of profiles object
374
    JsonNode profilesList = profiles.get("list");
4✔
375
    if (profilesList == null || !profilesList.isArray()) {
5!
376
      profilesList = mapper.createArrayNode();
×
377
      profiles.set("list", profilesList);
×
378
    }
379

380
    // Check if Git Bash profile already exists
381
    boolean gitBashProfileExists = false;
2✔
382
    for (JsonNode profile : profilesList) {
10✔
383
      if (profile.has("name") && profile.get("name").asText().equals("Git Bash")) {
11!
384
        gitBashProfileExists = true;
×
385
        break;
×
386
      }
387
    }
1✔
388

389
    // Add Git Bash profile if it doesn't exist
390
    if (gitBashProfileExists) {
2!
391
      this.context.info("Git Bash profile already exists in {}.", settingsPath);
×
392
    } else {
393
      ObjectNode gitBashProfile = mapper.createObjectNode();
3✔
394
      String newGuid = "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}";
2✔
395
      String iconPath = getGitBashIconPath(bashPath);
4✔
396
      String startingDirectory = this.context.getIdeRoot().toString();
5✔
397

398
      gitBashProfile.put("guid", newGuid);
5✔
399
      gitBashProfile.put("name", "Git Bash");
5✔
400
      gitBashProfile.put("commandline", bashPath);
5✔
401
      gitBashProfile.put("icon", iconPath);
5✔
402
      gitBashProfile.put("startingDirectory", startingDirectory);
5✔
403

404
      ((ArrayNode) profilesList).add(gitBashProfile);
5✔
405

406
      // Set Git Bash as default profile
407
      root.put("defaultProfile", newGuid);
5✔
408

409
      // Write back to file
410
      try (Writer writer = Files.newBufferedWriter(settingsPath)) {
5✔
411
        mapper.writerWithDefaultPrettyPrinter().writeValue(writer, root);
5✔
412
      }
413
    }
414
  }
1✔
415

416
  private String getGitBashIconPath(String bashPathString) {
417
    Path bashPath = Path.of(bashPathString);
5✔
418
    // "C:\\Program Files\\Git\\bin\\bash.exe"
419
    // "C:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico"
420
    Path parent = bashPath.getParent();
3✔
421
    if (parent != null) {
2!
422
      Path iconPath = parent.resolve("mingw64/share/git/git-for-windows.ico");
4✔
423
      if (Files.exists(iconPath)) {
5!
424
        this.context.debug("Found git-bash icon at {}", iconPath);
×
425
        return iconPath.toString();
×
426
      }
427
      this.context.debug("Git Bash icon not found at {}. Using default icon.", iconPath);
10✔
428
    }
429
    return "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png";
2✔
430
  }
431

432
  static String removeObsoleteEntryFromWindowsPath(String userPath) {
433
    return removeEntryFromWindowsPath(userPath, IDE_BIN);
4✔
434
  }
435

436
  static String removeEntryFromWindowsPath(String userPath, String suffix) {
437
    int len = userPath.length();
3✔
438
    int start = 0;
2✔
439
    while ((start >= 0) && (start < len)) {
5!
440
      int end = userPath.indexOf(';', start);
5✔
441
      if (end < 0) {
2✔
442
        end = len;
2✔
443
      }
444
      String entry = userPath.substring(start, end);
5✔
445
      if (entry.endsWith(suffix)) {
4✔
446
        String prefix = "";
2✔
447
        int offset = 1;
2✔
448
        if (start > 0) {
2✔
449
          prefix = userPath.substring(0, start - 1);
7✔
450
          offset = 0;
2✔
451
        }
452
        if (end == len) {
3✔
453
          return prefix;
2✔
454
        } else {
455
          return removeEntryFromWindowsPath(prefix + userPath.substring(end + offset), suffix);
10✔
456
        }
457
      }
458
      start = end + 1;
4✔
459
    }
1✔
460
    return userPath;
2✔
461
  }
462

463
  /**
464
   * Adds ourselves to the shell RC (run-commands) configuration file.
465
   *
466
   * @param filename the name of the RC file.
467
   * @param ideRoot the IDE_ROOT {@link Path}.
468
   */
469
  private void addToShellRc(String filename, Path ideRoot, String extraLine) {
470

471
    modifyShellRc(filename, ideRoot, true, extraLine);
6✔
472
  }
1✔
473

474
  private void removeFromShellRc(String filename, Path ideRoot) {
475

476
    modifyShellRc(filename, ideRoot, false, null);
6✔
477
  }
1✔
478

479
  /**
480
   * Adds ourselves to the shell RC (run-commands) configuration file.
481
   *
482
   * @param filename the name of the RC file.
483
   * @param ideRoot the IDE_ROOT {@link Path}.
484
   */
485
  private void modifyShellRc(String filename, Path ideRoot, boolean add, String extraLine) {
486

487
    if (add) {
2✔
488
      this.context.info("Configuring IDEasy in {}", filename);
11✔
489
    } else {
490
      this.context.info("Removing IDEasy from {}", filename);
10✔
491
    }
492
    Path rcFile = this.context.getUserHome().resolve(filename);
6✔
493
    FileAccess fileAccess = this.context.getFileAccess();
4✔
494
    List<String> lines = fileAccess.readFileLines(rcFile);
4✔
495
    if (lines == null) {
2✔
496
      if (!add) {
2!
497
        return;
×
498
      }
499
      lines = new ArrayList<>();
5✔
500
    } else {
501
      // since it is unspecified if the returned List may be immutable we want to get sure
502
      lines = new ArrayList<>(lines);
5✔
503
    }
504
    Iterator<String> iterator = lines.iterator();
3✔
505
    int removeCount = 0;
2✔
506
    while (iterator.hasNext()) {
3✔
507
      String line = iterator.next();
4✔
508
      line = line.trim();
3✔
509
      if (isObsoleteRcLine(line)) {
3✔
510
        this.context.info("Removing obsolete line from {}: {}", filename, line);
14✔
511
        iterator.remove();
2✔
512
        removeCount++;
2✔
513
      } else if (line.equals(extraLine)) {
4✔
514
        extraLine = null;
2✔
515
      }
516
    }
1✔
517
    if (add) {
2✔
518
      if (extraLine != null) {
2!
519
        lines.add(extraLine);
×
520
      }
521
      if (!this.context.getSystemInfo().isWindows()) {
5✔
522
        lines.add("export IDE_ROOT=\"" + WindowsPathSyntax.MSYS.format(ideRoot) + "\"");
7✔
523
      }
524
      lines.add(BASH_CODE_SOURCE_FUNCTIONS);
4✔
525
    }
526
    fileAccess.writeFileLines(lines, rcFile);
4✔
527
    this.context.debug("Successfully updated {}", filename);
10✔
528
  }
1✔
529

530
  private static boolean isObsoleteRcLine(String line) {
531
    if (line.startsWith("alias ide=")) {
4!
532
      return true;
×
533
    } else if (line.startsWith("export IDE_ROOT=")) {
4!
534
      return true;
×
535
    } else if (line.equals("ide")) {
4✔
536
      return true;
2✔
537
    } else if (line.equals("ide init")) {
4✔
538
      return true;
2✔
539
    } else if (line.startsWith("source \"$IDE_ROOT/_ide/")) {
4✔
540
      return true;
2✔
541
    }
542
    return false;
2✔
543
  }
544

545
  private boolean addInstallationArtifact(Path cwd, String artifactName, boolean required, List<Path> installationArtifacts) {
546

547
    Path artifactPath = cwd.resolve(artifactName);
4✔
548
    if (Files.exists(artifactPath)) {
5!
549
      installationArtifacts.add(artifactPath);
5✔
550
    } else if (required) {
×
551
      this.context.error("Missing required file {}", artifactName);
×
552
      return false;
×
553
    }
554
    return true;
2✔
555
  }
556

557
  private Path determineIdeRoot(Path cwd) {
558
    Path ideRoot = this.context.getIdeRoot();
4✔
559
    if (ideRoot == null) {
2!
560
      Path home = this.context.getUserHome();
4✔
561
      Path installRoot = home;
2✔
562
      if (this.context.getSystemInfo().isWindows()) {
5✔
563
        if (!cwd.startsWith(home)) {
4!
564
          installRoot = cwd.getRoot();
×
565
        }
566
      }
567
      ideRoot = installRoot.resolve(IdeContext.FOLDER_PROJECTS);
4✔
568
    } else {
1✔
569
      assert (Files.isDirectory(ideRoot)) : "IDE_ROOT directory does not exist!";
×
570
    }
571
    return ideRoot;
2✔
572
  }
573

574
  /**
575
   * Uninstalls IDEasy entirely from the system.
576
   */
577
  public void uninstallIdeasy() {
578

579
    Path ideRoot = this.context.getIdeRoot();
4✔
580
    removeFromShellRc(BASHRC, ideRoot);
4✔
581
    removeFromShellRc(ZSHRC, ideRoot);
4✔
582
    Path idePath = this.context.getIdePath();
4✔
583
    uninstallIdeasyWindowsEnv(ideRoot);
3✔
584
    uninstallIdeasyIdePath(idePath);
3✔
585
    deleteDownloadCache();
2✔
586
    this.context.success("IDEasy has been uninstalled from your system.");
4✔
587
    this.context.interaction("ATTENTION:\n"
10✔
588
        + "In order to prevent data-loss, we do not delete your projects and git repositories!\n"
589
        + "To entirely get rid of IDEasy, also check your IDE_ROOT folder at:\n"
590
        + "{}", ideRoot);
591
  }
1✔
592

593
  private void deleteDownloadCache() {
594
    Path downloadPath = this.context.getDownloadPath();
4✔
595
    this.context.info("Deleting download cache from {}", downloadPath);
10✔
596
    this.context.getFileAccess().delete(downloadPath);
5✔
597
  }
1✔
598

599
  private void uninstallIdeasyIdePath(Path idePath) {
600
    if (this.context.getSystemInfo().isWindows()) {
5✔
601
      this.context.newProcess().executable("bash").addArgs("-c",
17✔
602
          "sleep 10 && rm -rf \"" + WindowsPathSyntax.MSYS.format(idePath) + "\"").run(ProcessMode.BACKGROUND);
5✔
603
      this.context.interaction("To prevent windows file locking errors, we perform an asynchronous deletion of {} in background now.\n"
11✔
604
          + "Please close all terminals and wait a minute for the deletion to complete before running other commands.", idePath);
605
    } else {
606
      this.context.info("Finally deleting {}", idePath);
10✔
607
      this.context.getFileAccess().delete(idePath);
5✔
608
    }
609
  }
1✔
610

611
  private void uninstallIdeasyWindowsEnv(Path ideRoot) {
612
    if (!this.context.getSystemInfo().isWindows()) {
5✔
613
      return;
1✔
614
    }
615
    WindowsHelper helper = WindowsHelper.get(this.context);
4✔
616
    helper.removeUserEnvironmentValue(IdeVariables.IDE_ROOT.getName());
4✔
617
    String userPath = helper.getUserEnvironmentValue(IdeVariables.PATH.getName());
5✔
618
    if (userPath == null) {
2!
619
      this.context.error("Could not read user PATH from registry!");
×
620
    } else {
621
      this.context.info("Found user PATH={}", userPath);
10✔
622
      String newUserPath = userPath;
2✔
623
      if (!userPath.isEmpty()) {
3!
624
        SimpleSystemPath path = SimpleSystemPath.of(userPath, ';');
4✔
625
        path.removeEntries(s -> s.endsWith(IDE_BIN) || s.endsWith(IDE_INSTALLATION_BIN));
15!
626
        newUserPath = path.toString();
3✔
627
      }
628
      if (newUserPath.equals(userPath)) {
4!
629
        this.context.error("Could not find IDEasy in PATH:\n{}", userPath);
×
630
      } else {
631
        helper.setUserEnvironmentValue(IdeVariables.PATH.getName(), newUserPath);
5✔
632
      }
633
    }
634
  }
1✔
635
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc