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

devonfw / IDEasy / 19651727463

24 Nov 2025 10:43PM UTC coverage: 69.156% (+0.1%) from 69.024%
19651727463

push

github

web-flow
#1144: #1145: CVE warnings and suggestions (#1593)

Co-authored-by: KianRolf <kian.loroff@capgemini.com>
Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>

3613 of 5721 branches covered (63.15%)

Branch coverage included in aggregate %.

9387 of 13077 relevant lines covered (71.78%)

3.15 hits per line

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

70.42
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;
3✔
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 ToolInstallation install(boolean silent) {
113

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

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

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

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

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

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

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

237
  private void setGitLongpaths() {
238
    this.context.getGitContext().findGitRequired();
5✔
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
      try {
256
        installWindowsTerminal();
×
257
      } catch (Exception e) {
×
258
        this.context.error(e, "Failed to install Windows Terminal!");
×
259
      }
×
260
    }
261
    configureWindowsTerminalGitBash();
×
262
  }
×
263

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

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

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

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

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

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

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

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

349
    return null;
×
350
  }
351

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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