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

devonfw / IDEasy / 19751480105

28 Nov 2025 01:26AM UTC coverage: 69.441% (+0.3%) from 69.136%
19751480105

push

github

web-flow
#1613: fixed duplicated CVE check and refactored installation routine (#1614)

3696 of 5851 branches covered (63.17%)

Branch coverage included in aggregate %.

9620 of 13325 relevant lines covered (72.2%)

3.14 hits per line

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

72.03
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.install(request);
×
128
  }
129

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

355
    return null;
×
356
  }
357

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

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

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

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

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

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

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

411
      ((ArrayNode) profilesList).add(gitBashProfile);
5✔
412

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

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

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

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

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

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

478
    modifyShellRc(filename, ideRoot, true, extraLine);
6✔
479
  }
1✔
480

481
  private void removeFromShellRc(String filename, Path ideRoot) {
482

483
    modifyShellRc(filename, ideRoot, false, null);
6✔
484
  }
1✔
485

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

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

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

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

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

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

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

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

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

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

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