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

devonfw / IDEasy / 20271179405

16 Dec 2025 02:21PM UTC coverage: 70.061% (-0.08%) from 70.142%
20271179405

push

github

web-flow
#1660: status robustness #1475: fix tests to work offline (#1661)

3965 of 6233 branches covered (63.61%)

Branch coverage included in aggregate %.

10162 of 13931 relevant lines covered (72.95%)

3.15 hits per line

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

71.99
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 getInstalledEdition() {
83

84
    return this.tool;
3✔
85
  }
86

87
  @Override
88
  public String getConfiguredEdition() {
89

90
    return this.tool;
3✔
91
  }
92

93
  @Override
94
  public VersionIdentifier getConfiguredVersion() {
95

96
    UpgradeMode upgradeMode = this.mode;
3✔
97
    if (upgradeMode == null) {
2!
98
      if (IdeVersion.isSnapshot()) {
2!
99
        upgradeMode = UpgradeMode.SNAPSHOT;
3✔
100
      } else {
101
        if (IdeVersion.getVersionIdentifier().getDevelopmentPhase().isStable()) {
×
102
          upgradeMode = UpgradeMode.STABLE;
×
103
        } else {
104
          upgradeMode = UpgradeMode.UNSTABLE;
×
105
        }
106
      }
107
    }
108
    return upgradeMode.getVersion();
3✔
109
  }
110

111
  @Override
112
  public Path getToolPath() {
113

114
    return this.context.getIdeInstallationPath();
×
115
  }
116

117
  @Override
118
  protected ToolInstallation doInstall(ToolInstallRequest request) {
119

120
    this.context.requireOnline("upgrade of IDEasy", true);
5✔
121

122
    if (IdeVersion.isUndefined() && !this.context.isForceMode()) {
6!
123
      VersionIdentifier version = IdeVersion.getVersionIdentifier();
2✔
124
      this.context.warning("You are using IDEasy version {} which indicates local development - skipping upgrade.", version);
10✔
125
      return toolAlreadyInstalled(request);
4✔
126
    }
127
    return super.doInstall(request);
×
128
  }
129

130
  /**
131
   * @return the latest released {@link VersionIdentifier version} of IDEasy.
132
   */
133
  public VersionIdentifier getLatestVersion() {
134

135
    if (!this.context.isForceMode()) {
4!
136
      VersionIdentifier currentVersion = IdeVersion.getVersionIdentifier();
2✔
137
      if (IdeVersion.isUndefined()) {
2!
138
        return currentVersion;
2✔
139
      }
140
    }
141
    VersionIdentifier configuredVersion = getConfiguredVersion();
×
142
    return getToolRepository().resolveVersion(this.tool, getConfiguredEdition(), configuredVersion, this);
×
143
  }
144

145
  /**
146
   * Checks if an update is available and logs according information.
147
   *
148
   * @return {@code true} if an update is available, {@code false} otherwise.
149
   */
150
  public boolean checkIfUpdateIsAvailable() {
151
    VersionIdentifier installedVersion = getInstalledVersion();
3✔
152
    this.context.success("Your version of IDEasy is {}.", installedVersion);
10✔
153
    if (IdeVersion.isSnapshot()) {
2!
154
      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✔
155
    }
156
    if (this.context.isOffline()) {
4✔
157
      this.context.warning("Skipping check for newer version of IDEasy because you are offline.");
4✔
158
      return false;
2✔
159
    }
160
    VersionIdentifier latestVersion = getLatestVersion();
3✔
161
    if (installedVersion.equals(latestVersion)) {
4!
162
      this.context.success("Your are using the latest version of IDEasy and no update is available.");
4✔
163
      return false;
2✔
164
    } else {
165
      this.context.interaction("Your version of IDEasy is {} but version {} is available. Please run the following command to upgrade to the latest version:\n"
×
166
          + "ide upgrade", installedVersion, latestVersion);
167
      return true;
×
168
    }
169
  }
170

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

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

245
  private void setGitLongpaths() {
246
    this.context.getGitContext().findGitRequired();
5✔
247
    Path configPath = this.context.getUserHome().resolve(".gitconfig");
6✔
248
    FileAccess fileAccess = this.context.getFileAccess();
4✔
249
    IniFile iniFile = fileAccess.readIniFile(configPath);
4✔
250
    IniSection coreSection = iniFile.getOrCreateSection("core");
4✔
251
    coreSection.setProperty("longpaths", "true");
4✔
252
    fileAccess.writeIniFile(iniFile, configPath);
4✔
253
  }
1✔
254

255
  /**
256
   * Sets up Windows Terminal with Git Bash integration.
257
   */
258
  public void setupWindowsTerminal() {
259
    if (!this.context.getSystemInfo().isWindows()) {
×
260
      return;
×
261
    }
262
    if (!isWindowsTerminalInstalled()) {
×
263
      try {
264
        installWindowsTerminal();
×
265
      } catch (Exception e) {
×
266
        this.context.error(e, "Failed to install Windows Terminal!");
×
267
      }
×
268
    }
269
    configureWindowsTerminalGitBash();
×
270
  }
×
271

272
  /**
273
   * Checks if Windows Terminal is installed.
274
   *
275
   * @return {@code true} if Windows Terminal is installed, {@code false} otherwise.
276
   */
277
  private boolean isWindowsTerminalInstalled() {
278
    try {
279
      ProcessResult result = this.context.newProcess()
×
280
          .executable("powershell")
×
281
          .addArgs("-Command", "Get-AppxPackage -Name Microsoft.WindowsTerminal")
×
282
          .run(ProcessMode.DEFAULT_CAPTURE);
×
283
      return result.isSuccessful() && !result.getOut().isEmpty();
×
284
    } catch (Exception e) {
×
285
      this.context.debug("Failed to check Windows Terminal installation: {}", e.getMessage());
×
286
      return false;
×
287
    }
288
  }
289

290
  /**
291
   * Installs Windows Terminal using winget.
292
   */
293
  private void installWindowsTerminal() {
294
    try {
295
      this.context.info("Installing Windows Terminal...");
×
296
      ProcessResult result = this.context.newProcess()
×
297
          .executable("winget")
×
298
          .addArgs("install", "Microsoft.WindowsTerminal")
×
299
          .run(ProcessMode.DEFAULT);
×
300
      if (result.isSuccessful()) {
×
301
        this.context.success("Windows Terminal has been installed successfully.");
×
302
      } else {
303
        this.context.warning("Failed to install Windows Terminal. Please install it manually from Microsoft Store.");
×
304
      }
305
    } catch (Exception e) {
×
306
      this.context.warning("Failed to install Windows Terminal: {}. Please install it manually from Microsoft Store.", e.getMessage());
×
307
    }
×
308
  }
×
309

310
  /**
311
   * Configures Git Bash integration in Windows Terminal.
312
   */
313
  protected void configureWindowsTerminalGitBash() {
314
    Path settingsPath = getWindowsTerminalSettingsPath();
3✔
315
    if (settingsPath == null || !Files.exists(settingsPath)) {
7!
316
      this.context.warning("Windows Terminal settings file not found. Cannot configure Git Bash integration.");
×
317
      return;
×
318
    }
319

320
    try {
321
      Path bashPath = this.context.findBash();
4✔
322
      if (bashPath == null) {
2!
323
        this.context.warning("Git Bash not found. Cannot configure Windows Terminal integration.");
×
324
        return;
×
325
      }
326

327
      configureGitBashProfile(settingsPath, bashPath.toString());
5✔
328
      this.context.success("Git Bash has been configured in Windows Terminal.");
4✔
329
    } catch (Exception e) {
×
330
      this.context.warning("Failed to configure Git Bash in Windows Terminal: {}", e.getMessage());
×
331
    }
1✔
332
  }
1✔
333

334
  /**
335
   * Gets the Windows Terminal settings file path.
336
   *
337
   * @return the {@link Path} to the Windows Terminal settings file, or {@code null} if not found.
338
   */
339
  protected Path getWindowsTerminalSettingsPath() {
340
    Path localAppData = this.context.getUserHome().resolve("AppData").resolve("Local");
8✔
341
    Path packagesPath = localAppData.resolve("Packages");
4✔
342

343
    // Try the new Windows Terminal package first
344
    Path newTerminalPath = packagesPath.resolve("Microsoft.WindowsTerminal_8wekyb3d8bbwe")
4✔
345
        .resolve("LocalState").resolve("settings.json");
4✔
346
    if (Files.exists(newTerminalPath)) {
5!
347
      return newTerminalPath;
2✔
348
    }
349

350
    // Try the old Windows Terminal Preview package
351
    Path previewPath = packagesPath.resolve("Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe")
×
352
        .resolve("LocalState").resolve("settings.json");
×
353
    if (Files.exists(previewPath)) {
×
354
      return previewPath;
×
355
    }
356

357
    return null;
×
358
  }
359

360
  /**
361
   * Configures Git Bash profile in Windows Terminal settings.
362
   *
363
   * @param settingsPath the {@link Path} to the Windows Terminal settings file.
364
   * @param bashPath the path to the Git Bash executable.
365
   */
366
  private void configureGitBashProfile(Path settingsPath, String bashPath) throws Exception {
367

368
    ObjectMapper mapper = new ObjectMapper();
4✔
369
    ObjectNode root;
370
    try (Reader reader = Files.newBufferedReader(settingsPath)) {
3✔
371
      JsonNode rootNode = mapper.readTree(reader);
4✔
372
      root = (ObjectNode) rootNode;
3✔
373
    }
374

375
    // Get or create profiles object
376
    ObjectNode profiles = (ObjectNode) root.get("profiles");
5✔
377
    if (profiles == null) {
2!
378
      profiles = mapper.createObjectNode();
×
379
      root.set("profiles", profiles);
×
380
    }
381

382
    // Get or create list array of profiles object
383
    JsonNode profilesList = profiles.get("list");
4✔
384
    if (profilesList == null || !profilesList.isArray()) {
5!
385
      profilesList = mapper.createArrayNode();
×
386
      profiles.set("list", profilesList);
×
387
    }
388

389
    // Check if Git Bash profile already exists
390
    boolean gitBashProfileExists = false;
2✔
391
    for (JsonNode profile : profilesList) {
10✔
392
      if (profile.has("name") && profile.get("name").asText().equals("Git Bash")) {
11!
393
        gitBashProfileExists = true;
×
394
        break;
×
395
      }
396
    }
1✔
397

398
    // Add Git Bash profile if it doesn't exist
399
    if (gitBashProfileExists) {
2!
400
      this.context.info("Git Bash profile already exists in {}.", settingsPath);
×
401
    } else {
402
      ObjectNode gitBashProfile = mapper.createObjectNode();
3✔
403
      String newGuid = "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}";
2✔
404
      String iconPath = getGitBashIconPath(bashPath);
4✔
405
      String startingDirectory = this.context.getIdeRoot().toString();
5✔
406

407
      gitBashProfile.put("guid", newGuid);
5✔
408
      gitBashProfile.put("name", "Git Bash");
5✔
409
      gitBashProfile.put("commandline", bashPath);
5✔
410
      gitBashProfile.put("icon", iconPath);
5✔
411
      gitBashProfile.put("startingDirectory", startingDirectory);
5✔
412

413
      ((ArrayNode) profilesList).add(gitBashProfile);
5✔
414

415
      // Set Git Bash as default profile
416
      root.put("defaultProfile", newGuid);
5✔
417

418
      // Write back to file
419
      try (Writer writer = Files.newBufferedWriter(settingsPath)) {
5✔
420
        mapper.writerWithDefaultPrettyPrinter().writeValue(writer, root);
5✔
421
      }
422
    }
423
  }
1✔
424

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

441
  static String removeObsoleteEntryFromWindowsPath(String userPath) {
442
    return removeEntryFromWindowsPath(userPath, IDE_BIN);
4✔
443
  }
444

445
  static String removeEntryFromWindowsPath(String userPath, String suffix) {
446
    int len = userPath.length();
3✔
447
    int start = 0;
2✔
448
    while ((start >= 0) && (start < len)) {
5!
449
      int end = userPath.indexOf(';', start);
5✔
450
      if (end < 0) {
2✔
451
        end = len;
2✔
452
      }
453
      String entry = userPath.substring(start, end);
5✔
454
      if (entry.endsWith(suffix)) {
4✔
455
        String prefix = "";
2✔
456
        int offset = 1;
2✔
457
        if (start > 0) {
2✔
458
          prefix = userPath.substring(0, start - 1);
7✔
459
          offset = 0;
2✔
460
        }
461
        if (end == len) {
3✔
462
          return prefix;
2✔
463
        } else {
464
          return removeEntryFromWindowsPath(prefix + userPath.substring(end + offset), suffix);
10✔
465
        }
466
      }
467
      start = end + 1;
4✔
468
    }
1✔
469
    return userPath;
2✔
470
  }
471

472
  /**
473
   * Adds ourselves to the shell RC (run-commands) configuration file.
474
   *
475
   * @param filename the name of the RC file.
476
   * @param ideRoot the IDE_ROOT {@link Path}.
477
   */
478
  private void addToShellRc(String filename, Path ideRoot, String extraLine) {
479

480
    modifyShellRc(filename, ideRoot, true, extraLine);
6✔
481
  }
1✔
482

483
  private void removeFromShellRc(String filename, Path ideRoot) {
484

485
    modifyShellRc(filename, ideRoot, false, null);
6✔
486
  }
1✔
487

488
  /**
489
   * Adds ourselves to the shell RC (run-commands) configuration file.
490
   *
491
   * @param filename the name of the RC file.
492
   * @param ideRoot the IDE_ROOT {@link Path}.
493
   */
494
  private void modifyShellRc(String filename, Path ideRoot, boolean add, String extraLine) {
495

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

539
  private static boolean isObsoleteRcLine(String line) {
540
    if (line.startsWith("alias ide=")) {
4!
541
      return true;
×
542
    } else if (line.startsWith("export IDE_ROOT=")) {
4!
543
      return true;
×
544
    } else if (line.equals("ide")) {
4✔
545
      return true;
2✔
546
    } else if (line.equals("ide init")) {
4✔
547
      return true;
2✔
548
    } else if (line.startsWith("source \"$IDE_ROOT/_ide/")) {
4✔
549
      return true;
2✔
550
    }
551
    return false;
2✔
552
  }
553

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

556
    Path artifactPath = cwd.resolve(artifactName);
4✔
557
    if (Files.exists(artifactPath)) {
5!
558
      installationArtifacts.add(artifactPath);
5✔
559
    } else if (required) {
×
560
      this.context.error("Missing required file {}", artifactName);
×
561
      return false;
×
562
    }
563
    return true;
2✔
564
  }
565

566
  private Path determineIdeRoot(Path cwd) {
567
    Path ideRoot = this.context.getIdeRoot();
4✔
568
    if (ideRoot == null) {
2!
569
      Path home = this.context.getUserHome();
4✔
570
      Path installRoot = home;
2✔
571
      if (this.context.getSystemInfo().isWindows()) {
5✔
572
        if (!cwd.startsWith(home)) {
4!
573
          installRoot = cwd.getRoot();
×
574
        }
575
      }
576
      ideRoot = installRoot.resolve(IdeContext.FOLDER_PROJECTS);
4✔
577
    } else {
1✔
578
      assert (Files.isDirectory(ideRoot)) : "IDE_ROOT directory does not exist!";
×
579
    }
580
    return ideRoot;
2✔
581
  }
582

583
  /**
584
   * Uninstalls IDEasy entirely from the system.
585
   */
586
  public void uninstallIdeasy() {
587

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

602
  private void deleteDownloadCache() {
603
    Path downloadPath = this.context.getDownloadPath();
4✔
604
    this.context.info("Deleting download cache from {}", downloadPath);
10✔
605
    this.context.getFileAccess().delete(downloadPath);
5✔
606
  }
1✔
607

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

620
  private void uninstallIdeasyWindowsEnv(Path ideRoot) {
621
    if (!this.context.getSystemInfo().isWindows()) {
5✔
622
      return;
1✔
623
    }
624
    WindowsHelper helper = WindowsHelper.get(this.context);
4✔
625
    helper.removeUserEnvironmentValue(IdeVariables.IDE_ROOT.getName());
4✔
626
    String userPath = helper.getUserEnvironmentValue(IdeVariables.PATH.getName());
5✔
627
    if (userPath == null) {
2!
628
      this.context.error("Could not read user PATH from registry!");
×
629
    } else {
630
      this.context.info("Found user PATH={}", userPath);
10✔
631
      String newUserPath = userPath;
2✔
632
      if (!userPath.isEmpty()) {
3!
633
        SimpleSystemPath path = SimpleSystemPath.of(userPath, ';');
4✔
634
        path.removeEntries(s -> s.endsWith(IDE_BIN) || s.endsWith(IDE_INSTALLATION_BIN));
15!
635
        newUserPath = path.toString();
3✔
636
      }
637
      if (newUserPath.equals(userPath)) {
4!
638
        this.context.error("Could not find IDEasy in PATH:\n{}", userPath);
×
639
      } else {
640
        helper.setUserEnvironmentValue(IdeVariables.PATH.getName(), newUserPath);
5✔
641
      }
642
    }
643
  }
1✔
644
}
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