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

devonfw / IDEasy / 17052100412

18 Aug 2025 08:46PM UTC coverage: 69.087% (-0.3%) from 69.386%
17052100412

push

github

web-flow
#1221: Added windows terminal integration (#1450)

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

3377 of 5335 branches covered (63.3%)

Branch coverage included in aggregate %.

8801 of 12292 relevant lines covered (71.6%)

3.14 hits per line

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

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

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

10
import com.devonfw.tools.ide.cli.CliException;
11
import com.devonfw.tools.ide.commandlet.UpgradeMode;
12
import com.devonfw.tools.ide.common.SimpleSystemPath;
13
import com.devonfw.tools.ide.common.Tag;
14
import com.devonfw.tools.ide.context.IdeContext;
15
import com.devonfw.tools.ide.git.GitContext;
16
import com.devonfw.tools.ide.git.GitContextImpl;
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.MavenRepository;
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(MavenRepository.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_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
    GitContext gitContext = new GitContextImpl(this.context);
6✔
238
    gitContext.verifyGitInstalled();
2✔
239
    Path configPath = this.context.getUserHome().resolve(".gitconfig");
6✔
240
    FileAccess fileAccess = this.context.getFileAccess();
4✔
241
    IniFile iniFile = fileAccess.readIniFile(configPath);
4✔
242
    IniSection coreSection = iniFile.getOrCreateSection("core");
4✔
243
    coreSection.setProperty("longpaths", "true");
4✔
244
    fileAccess.writeIniFile(iniFile, configPath);
4✔
245
  }
1✔
246

247
  /**
248
   * Sets up Windows Terminal with Git Bash integration.
249
   */
250
  public void setupWindowsTerminal() {
251
    if (!this.context.getSystemInfo().isWindows()) {
×
252
      return;
×
253
    }
254
    if (!isWindowsTerminalInstalled()) {
×
255
      installWindowsTerminal();
×
256
    }
257
    configureWindowsTerminalGitBash();
×
258
  }
×
259

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

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

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

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

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

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

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

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

345
    return null;
×
346
  }
347

348
  /**
349
   * Configures Git Bash profile in Windows Terminal settings.
350
   *
351
   * @param settingsPath the {@link Path} to the Windows Terminal settings file.
352
   * @param bashPath the path to the Git Bash executable.
353
   */
354
  private void configureGitBashProfile(Path settingsPath, String bashPath) throws Exception {
355
    FileAccess fileAccess = this.context.getFileAccess();
4✔
356
    String settingsContent = fileAccess.readFileContent(settingsPath);
4✔
357

358
    ObjectMapper mapper = new ObjectMapper();
4✔
359
    JsonNode rootNode = mapper.readTree(settingsContent);
4✔
360
    ObjectNode root = (ObjectNode) rootNode;
3✔
361

362
    // Get or create profiles object
363
    ObjectNode profiles = (ObjectNode) root.get("profiles");
5✔
364
    if (profiles == null) {
2!
365
      profiles = mapper.createObjectNode();
×
366
      root.set("profiles", profiles);
×
367
    }
368

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

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

385
    // Add Git Bash profile if it doesn't exist
386
    if (!gitBashProfileExists) {
2!
387
      ObjectNode gitBashProfile = mapper.createObjectNode();
3✔
388
      String newGuid = "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}";
2✔
389
      String iconPath = getGitBashIconPath(bashPath);
4✔
390
      String startingDirectory = this.context.getIdeRoot().toString();
5✔
391

392
      gitBashProfile.put("guid", newGuid);
5✔
393
      gitBashProfile.put("name", "Git Bash");
5✔
394
      gitBashProfile.put("commandline", bashPath);
5✔
395
      gitBashProfile.put("icon", iconPath);
5✔
396
      gitBashProfile.put("startingDirectory", startingDirectory);
5✔
397

398
      ((ArrayNode) profilesList).add(gitBashProfile);
5✔
399

400
      // Set Git Bash as default profile
401
      root.put("defaultProfile", newGuid);
5✔
402

403
      // Write back to file
404
      String updatedContent = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root);
5✔
405
      fileAccess.writeFileContent(updatedContent, settingsPath);
4✔
406
    }
407
  }
1✔
408

409
  private String getGitBashIconPath(String bashPath) {
410
    Path iconPath = Path.of("C:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico");
5✔
411
    if (Files.exists(iconPath)) {
5!
412
      return iconPath.toString();
×
413
    } else {
414
      this.context.debug("Git Bash icon not found at {}. Using default icon.", iconPath);
10✔
415
      return "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png";
2✔
416
    }
417
  }
418

419
  static String removeObsoleteEntryFromWindowsPath(String userPath) {
420
    return removeEntryFromWindowsPath(userPath, IDE_BIN);
4✔
421
  }
422

423
  static String removeEntryFromWindowsPath(String userPath, String suffix) {
424
    int len = userPath.length();
3✔
425
    int start = 0;
2✔
426
    while ((start >= 0) && (start < len)) {
5!
427
      int end = userPath.indexOf(';', start);
5✔
428
      if (end < 0) {
2✔
429
        end = len;
2✔
430
      }
431
      String entry = userPath.substring(start, end);
5✔
432
      if (entry.endsWith(suffix)) {
4✔
433
        String prefix = "";
2✔
434
        int offset = 1;
2✔
435
        if (start > 0) {
2✔
436
          prefix = userPath.substring(0, start - 1);
7✔
437
          offset = 0;
2✔
438
        }
439
        if (end == len) {
3✔
440
          return prefix;
2✔
441
        } else {
442
          return removeEntryFromWindowsPath(prefix + userPath.substring(end + offset), suffix);
10✔
443
        }
444
      }
445
      start = end + 1;
4✔
446
    }
1✔
447
    return userPath;
2✔
448
  }
449

450
  /**
451
   * Adds ourselves to the shell RC (run-commands) configuration file.
452
   *
453
   * @param filename the name of the RC file.
454
   * @param ideRoot the IDE_ROOT {@link Path}.
455
   */
456
  private void addToShellRc(String filename, Path ideRoot, String extraLine) {
457

458
    modifyShellRc(filename, ideRoot, true, extraLine);
6✔
459
  }
1✔
460

461
  private void removeFromShellRc(String filename, Path ideRoot) {
462

463
    modifyShellRc(filename, ideRoot, false, null);
6✔
464
  }
1✔
465

466
  /**
467
   * Adds ourselves to the shell RC (run-commands) configuration file.
468
   *
469
   * @param filename the name of the RC file.
470
   * @param ideRoot the IDE_ROOT {@link Path}.
471
   */
472
  private void modifyShellRc(String filename, Path ideRoot, boolean add, String extraLine) {
473

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

517
  private static boolean isObsoleteRcLine(String line) {
518
    if (line.startsWith("alias ide=")) {
4!
519
      return true;
×
520
    } else if (line.startsWith("export IDE_ROOT=")) {
4!
521
      return true;
×
522
    } else if (line.equals("ide")) {
4✔
523
      return true;
2✔
524
    } else if (line.equals("ide init")) {
4✔
525
      return true;
2✔
526
    } else if (line.startsWith("source \"$IDE_ROOT/_ide/")) {
4✔
527
      return true;
2✔
528
    }
529
    return false;
2✔
530
  }
531

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

534
    Path artifactPath = cwd.resolve(artifactName);
4✔
535
    if (Files.exists(artifactPath)) {
5!
536
      installationArtifacts.add(artifactPath);
5✔
537
    } else if (required) {
×
538
      this.context.error("Missing required file {}", artifactName);
×
539
      return false;
×
540
    }
541
    return true;
2✔
542
  }
543

544
  private Path determineIdeRoot(Path cwd) {
545
    Path ideRoot = this.context.getIdeRoot();
4✔
546
    if (ideRoot == null) {
2!
547
      Path home = this.context.getUserHome();
4✔
548
      Path installRoot = home;
2✔
549
      if (this.context.getSystemInfo().isWindows()) {
5✔
550
        if (!cwd.startsWith(home)) {
4!
551
          installRoot = cwd.getRoot();
×
552
        }
553
      }
554
      ideRoot = installRoot.resolve(IdeContext.FOLDER_PROJECTS);
4✔
555
    } else {
1✔
556
      assert (Files.isDirectory(ideRoot)) : "IDE_ROOT directory does not exist!";
×
557
    }
558
    return ideRoot;
2✔
559
  }
560

561
  /**
562
   * Uninstalls IDEasy entirely from the system.
563
   */
564
  public void uninstallIdeasy() {
565

566
    Path ideRoot = this.context.getIdeRoot();
4✔
567
    removeFromShellRc(BASHRC, ideRoot);
4✔
568
    removeFromShellRc(ZSHRC, ideRoot);
4✔
569
    Path idePath = this.context.getIdePath();
4✔
570
    uninstallIdeasyWindowsEnv(ideRoot);
3✔
571
    uninstallIdeasyIdePath(idePath);
3✔
572
    deleteDownloadCache();
2✔
573
    this.context.success("IDEasy has been uninstalled from your system.");
4✔
574
    this.context.interaction("ATTENTION:\n"
10✔
575
        + "In order to prevent data-loss, we do not delete your projects and git repositories!\n"
576
        + "To entirely get rid of IDEasy, also check your IDE_ROOT folder at:\n"
577
        + "{}", ideRoot);
578
  }
1✔
579

580
  private void deleteDownloadCache() {
581
    Path downloadPath = this.context.getDownloadPath();
4✔
582
    this.context.info("Deleting download cache from {}", downloadPath);
10✔
583
    this.context.getFileAccess().delete(downloadPath);
5✔
584
  }
1✔
585

586
  private void uninstallIdeasyIdePath(Path idePath) {
587
    if (this.context.getSystemInfo().isWindows()) {
5✔
588
      this.context.newProcess().executable("bash").addArgs("-c",
17✔
589
          "sleep 10 && rm -rf \"" + WindowsPathSyntax.MSYS.format(idePath) + "\"").run(ProcessMode.BACKGROUND);
5✔
590
      this.context.interaction("To prevent windows file locking errors, we perform an asynchronous deletion of {} in background now.\n"
11✔
591
          + "Please close all terminals and wait a minute for the deletion to complete before running other commands.", idePath);
592
    } else {
593
      this.context.info("Finally deleting {}", idePath);
10✔
594
      this.context.getFileAccess().delete(idePath);
5✔
595
    }
596
  }
1✔
597

598
  private void uninstallIdeasyWindowsEnv(Path ideRoot) {
599
    if (!this.context.getSystemInfo().isWindows()) {
5✔
600
      return;
1✔
601
    }
602
    WindowsHelper helper = WindowsHelper.get(this.context);
4✔
603
    helper.removeUserEnvironmentValue(IdeVariables.IDE_ROOT.getName());
4✔
604
    String userPath = helper.getUserEnvironmentValue(IdeVariables.PATH.getName());
5✔
605
    if (userPath == null) {
2!
606
      this.context.error("Could not read user PATH from registry!");
×
607
    } else {
608
      this.context.info("Found user PATH={}", userPath);
10✔
609
      String newUserPath = userPath;
2✔
610
      if (!userPath.isEmpty()) {
3!
611
        SimpleSystemPath path = SimpleSystemPath.of(userPath, ';');
4✔
612
        path.removeEntries(s -> s.endsWith(IDE_BIN) || s.endsWith(IDE_INSTALLATION_BIN));
15!
613
        newUserPath = path.toString();
3✔
614
      }
615
      if (newUserPath.equals(userPath)) {
4!
616
        this.context.error("Could not find IDEasy in PATH:\n{}", userPath);
×
617
      } else {
618
        helper.setUserEnvironmentValue(IdeVariables.PATH.getName(), newUserPath);
5✔
619
      }
620
    }
621
  }
1✔
622
}
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