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

devonfw / IDEasy / 24732790894

21 Apr 2026 04:01PM UTC coverage: 70.599% (+0.009%) from 70.59%
24732790894

push

github

web-flow
#451: mac gatekeeper quarantine removal (#1794)

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

4325 of 6766 branches covered (63.92%)

Branch coverage included in aggregate %.

11197 of 15220 relevant lines covered (73.57%)

3.1 hits per line

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

80.36
cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java
1
package com.devonfw.tools.ide.tool;
2

3
import java.nio.file.Files;
4
import java.nio.file.LinkOption;
5
import java.nio.file.Path;
6
import java.util.Collection;
7
import java.util.Set;
8

9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11

12
import com.devonfw.tools.ide.cli.CliOfflineException;
13
import com.devonfw.tools.ide.common.Tag;
14
import com.devonfw.tools.ide.context.IdeContext;
15
import com.devonfw.tools.ide.io.FileAccess;
16
import com.devonfw.tools.ide.log.IdeLogLevel;
17
import com.devonfw.tools.ide.process.ProcessContext;
18
import com.devonfw.tools.ide.step.Step;
19
import com.devonfw.tools.ide.tool.repository.ToolRepository;
20
import com.devonfw.tools.ide.url.model.file.json.ToolDependency;
21
import com.devonfw.tools.ide.version.GenericVersionRange;
22
import com.devonfw.tools.ide.version.VersionIdentifier;
23
import com.devonfw.tools.ide.version.VersionRange;
24

25
/**
26
 * {@link ToolCommandlet} that is installed locally into the IDEasy.
27
 */
28
public abstract class LocalToolCommandlet extends ToolCommandlet {
29

30
  private static final Logger LOG = LoggerFactory.getLogger(LocalToolCommandlet.class);
4✔
31

32
  /**
33
   * The constructor.
34
   *
35
   * @param context the {@link IdeContext}.
36
   * @param tool the {@link #getName() tool name}.
37
   * @param tags the {@link #getTags() tags} classifying the tool. Should be created via {@link Set#of(Object) Set.of} method.
38
   */
39
  public LocalToolCommandlet(IdeContext context, String tool, Set<Tag> tags) {
40

41
    super(context, tool, tags);
5✔
42
  }
1✔
43

44
  /**
45
   * @return the {@link Path} where the tool is located (installed).
46
   */
47
  @Override
48
  public Path getToolPath() {
49
    if (this.context.getSoftwarePath() == null) {
4!
50
      return null;
×
51
    }
52
    return this.context.getSoftwarePath().resolve(getName());
7✔
53
  }
54

55
  /**
56
   * @return the {@link Path} where the executables of the tool can be found. Typically, a "bin" folder inside {@link #getToolPath() tool path}.
57
   */
58
  public Path getToolBinPath() {
59

60
    Path toolPath = getToolPath();
3✔
61
    if (toolPath == null) {
2!
62
      return null;
×
63
    }
64
    Path binPath = toolPath.resolve(IdeContext.FOLDER_BIN);
4✔
65
    if (Files.isDirectory(binPath)) {
5✔
66
      return binPath;
2✔
67
    }
68
    return toolPath;
2✔
69
  }
70

71
  /**
72
   * @return {@code true} to ignore a missing {@link IdeContext#FILE_SOFTWARE_VERSION software version file} in an installation, {@code false} delete the broken
73
   *     installation (default).
74
   */
75
  protected boolean isIgnoreMissingSoftwareVersionFile() {
76

77
    return false;
×
78
  }
79

80
  /**
81
   * @deprecated will be removed once all "dependencies.json" are created in ide-urls.
82
   */
83
  @Deprecated
84
  protected void installDependencies() {
85

86
  }
1✔
87

88
  @Override
89
  protected ToolInstallation doInstall(ToolInstallRequest request) {
90

91
    installDependencies();
2✔
92
    Step step = request.getStep();
3✔
93
    if (step == null) {
2!
94
      return doInstallStep(request);
4✔
95
    } else {
96
      return step.call(() -> doInstallStep(request),
×
97
          () -> createExistingToolInstallation(request));
×
98
    }
99
  }
100

101
  private ToolInstallation doInstallStep(ToolInstallRequest request) {
102

103
    // install configured version of our tool in the software repository if not already installed
104
    ToolInstallation installation = installTool(request);
4✔
105

106
    // check if we already have this version installed (linked) locally in IDE_HOME/software
107
    VersionIdentifier resolvedVersion = installation.resolvedVersion();
3✔
108
    if (request.isAlreadyInstalled()) {
3✔
109
      return installation;
2✔
110
    } else {
111
      LOG.debug("Installation from {} to {}.", request.getInstalled(), request.getRequested());
7✔
112
    }
113
    FileAccess fileAccess = this.context.getFileAccess();
4✔
114
    boolean ignoreSoftwareRepo = isIgnoreSoftwareRepo();
3✔
115
    Path toolPath = request.getToolPath();
3✔
116
    if (!ignoreSoftwareRepo) {
2✔
117
      // we need to link the version or update the link.
118
      if (Files.exists(toolPath, LinkOption.NOFOLLOW_LINKS)) {
9✔
119
        fileAccess.backup(toolPath);
4✔
120
      }
121
      fileAccess.mkdirs(toolPath.getParent());
4✔
122
      fileAccess.symlink(installation.linkDir(), toolPath);
5✔
123
    }
124
    if (!request.isExtraInstallation() && (installation.binDir() != null)) {
6!
125
      this.context.getPath().setPath(this.tool, installation.binDir());
8✔
126
    }
127
    postInstall(request);
3✔
128
    ToolEditionAndVersion installed = request.getInstalled();
3✔
129
    GenericVersionRange installedVersion = null;
2✔
130
    if (installed != null) {
2!
131
      installedVersion = installed.getVersion();
3✔
132
    }
133
    ToolEditionAndVersion requested = request.getRequested();
3✔
134
    ToolEdition toolEdition = requested.getEdition();
3✔
135
    Step step = request.getStep();
3✔
136
    if (installedVersion == null) {
2✔
137
      IdeLogLevel.SUCCESS.log(LOG, "Successfully installed {} in version {} at {}", toolEdition, resolvedVersion, toolPath);
19✔
138
    } else {
139
      IdeLogLevel.SUCCESS.log(LOG, "Successfully installed {} in version {} replacing previous version {} of {} at {}", toolEdition,
21✔
140
          resolvedVersion, installedVersion, installed.getEdition(), toolPath);
6✔
141
    }
142
    if (step != null) {
2!
143
      step.success(true);
×
144
    }
145
    return installation;
2✔
146
  }
147

148
  /**
149
   * Determines whether this tool should be installed directly in the software folder or in the software repository.
150
   *
151
   * @return {@code true} if the tool should be installed directly in the software folder, ignoring the central software repository; {@code false} if the tool
152
   *     should be installed in the central software repository (default behavior).
153
   */
154
  protected boolean isIgnoreSoftwareRepo() {
155

156
    return false;
2✔
157
  }
158

159
  /**
160
   * Performs the installation of the {@link #getName() tool} together with the environment context  managed by this
161
   * {@link com.devonfw.tools.ide.commandlet.Commandlet}.
162
   *
163
   * @param request the {@link ToolInstallRequest}.
164
   * @return the resulting {@link ToolInstallation}.
165
   */
166
  public ToolInstallation installTool(ToolInstallRequest request) {
167

168
    completeRequest(request); // most likely already done, but if installTool was called directly and not from install
3✔
169
    if (request.isInstallLoop()) {
3!
170
      return toolAlreadyInstalled(request);
×
171
    }
172
    ToolEditionAndVersion requested = request.getRequested();
3✔
173
    ToolEdition toolEdition = requested.getEdition();
3✔
174
    assert (toolEdition.tool().equals(this.tool)) : "Mismatch " + this.tool + " != " + toolEdition.tool();
7!
175
    String edition = toolEdition.edition();
3✔
176
    VersionIdentifier resolvedVersion = cveCheck(request);
4✔
177
    installToolDependencies(request);
3✔
178

179
    // cveCheck might have changed resolvedVersion so let us re-check...
180
    if (request.isAlreadyInstalled()) {
3✔
181
      return toolAlreadyInstalled(request);
4✔
182
    } else {
183
      ToolEditionAndVersion installed = request.getInstalled();
3✔
184
      LOG.debug("Installation from {} to {}.", installed, requested);
5✔
185
    }
186
    Path installationPath = getInstallationPath(edition, resolvedVersion);
5✔
187

188
    ProcessContext processContext = request.getProcessContext();
3✔
189
    boolean additionalInstallation = request.isAdditionalInstallation();
3✔
190
    boolean ignoreSoftwareRepo = isIgnoreSoftwareRepo();
3✔
191
    Path toolVersionFile = installationPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
192
    FileAccess fileAccess = this.context.getFileAccess();
4✔
193
    if (Files.isDirectory(installationPath)) {
5✔
194
      if (Files.exists(toolVersionFile)) {
5!
195
        if (!ignoreSoftwareRepo) {
2✔
196
          assert resolvedVersion.equals(getInstalledVersion(installationPath)) :
7!
197
              "Found version " + getInstalledVersion(installationPath) + " in " + toolVersionFile + " but expected " + resolvedVersion;
×
198
          LOG.debug("Version {} of tool {} is already installed at {}", resolvedVersion, toolEdition, installationPath);
17✔
199
          return createToolInstallation(installationPath, resolvedVersion, false, processContext, additionalInstallation);
8✔
200
        }
201
      } else {
202
        // Makes sure that IDEasy will not delete itself
203
        if (this.tool.equals(IdeasyCommandlet.TOOL_NAME)) {
×
204
          LOG.warn("Your IDEasy installation is missing the version file at {}", toolVersionFile);
×
205
          return createToolInstallation(installationPath, resolvedVersion, false, processContext, additionalInstallation);
×
206
        } else if (!isIgnoreMissingSoftwareVersionFile()) {
×
207
          LOG.warn("Deleting corrupted installation at {}", installationPath);
×
208
          fileAccess.delete(installationPath);
×
209
        }
210
      }
211
    }
212
    VersionIdentifier actualInstalledVersion = resolvedVersion;
2✔
213
    try {
214
      performToolInstallation(request, installationPath);
4✔
215
    } catch (CliOfflineException e) {
1✔
216
      // If we are offline and cannot download, check if we can continue with an existing installation
217
      ToolEditionAndVersion installed = request.getInstalled();
3✔
218
      if ((installed != null) && (installed.getResolvedVersion() != null)) {
5!
219
        LOG.warn("Cannot download {} in version {} because we are offline. Continuing with already installed version {}.", this.tool,
17✔
220
            resolvedVersion, installed.getResolvedVersion());
2✔
221
        // If offline and could not download, actualInstalledVersion will be the old version, not resolvedVersion
222
        // In that case, we need to recalculate the installation path for the actually installed version
223
        actualInstalledVersion = installed.getResolvedVersion();
3✔
224
        installationPath = getInstallationPath(edition, actualInstalledVersion);
6✔
225
      } else {
226
        // No existing installation available, re-throw the exception
227
        throw e;
2✔
228
      }
229
    }
1✔
230
    return createToolInstallation(installationPath, actualInstalledVersion, true, processContext, additionalInstallation);
8✔
231
  }
232

233
  /**
234
   * Performs the actual installation of the {@link #getName() tool} by downloading its binary, optionally extracting it, backing up any existing installation,
235
   * and writing the version file.
236
   * <p>
237
   * This method assumes that the version has already been resolved and dependencies installed. It handles the final steps of placing the tool into the
238
   * appropriate installation directory.
239
   *
240
   * @param request the {@link ToolInstallRequest}.
241
   * @param installationPath the target {@link Path} where the {@link #getName() tool} should be installed.
242
   */
243
  protected void performToolInstallation(ToolInstallRequest request, Path installationPath) {
244

245
    FileAccess fileAccess = this.context.getFileAccess();
4✔
246
    ToolEditionAndVersion requested = request.getRequested();
3✔
247
    VersionIdentifier resolvedVersion = requested.getResolvedVersion();
3✔
248
    Path downloadedToolFile = downloadTool(requested.getEdition().edition(), resolvedVersion);
7✔
249
    boolean extract = isExtract();
3✔
250
    if (!extract) {
2✔
251
      LOG.trace("Extraction is disabled for '{}' hence just moving the downloaded file {}.", this.tool, downloadedToolFile);
6✔
252
    }
253
    if (Files.isDirectory(installationPath)) {
5!
254
      if (this.tool.equals(IdeasyCommandlet.TOOL_NAME)) {
×
255
        LOG.warn("Your IDEasy installation is missing the version file.");
×
256
      } else {
257
        fileAccess.backup(installationPath);
×
258
      }
259
    }
260
    fileAccess.mkdirs(installationPath.getParent());
4✔
261
    fileAccess.extract(downloadedToolFile, installationPath, this::postExtract, extract);
7✔
262
    this.context.writeVersionFile(resolvedVersion, installationPath);
5✔
263
    // fix macOS Gatekeeper blocking - must run after version file is written but before any executables are launched
264
    getMacOsHelper().removeQuarantineAttribute(installationPath);
4✔
265
    LOG.debug("Installed {} in version {} at {}", this.tool, resolvedVersion, installationPath);
18✔
266
  }
1✔
267

268
  /**
269
   * @param edition the {@link #getConfiguredEdition() tool edition} to download.
270
   * @param resolvedVersion the resolved {@link VersionIdentifier version} to download.
271
   * @return the {@link Path} to the downloaded release file.
272
   */
273
  protected Path downloadTool(String edition, VersionIdentifier resolvedVersion) {
274
    return getToolRepository().download(this.tool, edition, resolvedVersion, this);
9✔
275
  }
276

277
  /**
278
   * Install this tool as dependency of another tool.
279
   *
280
   * @param versionRange the required {@link VersionRange}. See {@link ToolDependency#versionRange()}.
281
   * @param parentRequest the {@link ToolInstallRequest} of the tool causing this dependency.
282
   * @return the corresponding {@link ToolInstallation}.
283
   */
284
  public ToolInstallation installAsDependency(VersionRange versionRange, ToolInstallRequest parentRequest) {
285
    ToolInstallRequest request = new ToolInstallRequest(parentRequest);
5✔
286
    ToolEditionAndVersion requested = new ToolEditionAndVersion(getToolWithConfiguredEdition());
6✔
287
    request.setRequested(requested);
3✔
288
    VersionIdentifier configuredVersion = getConfiguredVersion();
3✔
289
    if (versionRange.contains(configuredVersion)) {
4✔
290
      // prefer configured version if contained in version range
291
      requested.setVersion(configuredVersion);
3✔
292
      // return install(true, configuredVersion, processContext, null);
293
      return install(request);
4✔
294
    } else {
295
      if (isIgnoreSoftwareRepo()) {
3!
296
        throw new IllegalStateException(
×
297
            "Cannot satisfy dependency to " + this.tool + " in version " + versionRange + " for " + parentRequest.getRequested()
×
298
                + " since it is conflicting with configured version "
299
                + configuredVersion
300
                + " and this tool does not support the software repository.");
301
      }
302
      LOG.info(
8✔
303
          "The tool {} requires {} in the version range {}, but your project uses version {}, which does not match."
304
              + " Therefore, we install a compatible version in that range.",
305
          parentRequest.getRequested().getEdition(), this.tool, versionRange, configuredVersion);
16✔
306
      requested.setVersion(versionRange);
3✔
307
      return installTool(request);
4✔
308
    }
309
  }
310

311
  /**
312
   * Installs the tool dependencies for the current tool.
313
   *
314
   * @param request the {@link ToolInstallRequest}.
315
   */
316
  protected void installToolDependencies(ToolInstallRequest request) {
317

318
    ToolEditionAndVersion requested = request.getRequested();
3✔
319
    VersionIdentifier version = requested.getResolvedVersion();
3✔
320
    ToolEdition toolEdition = requested.getEdition();
3✔
321
    Collection<ToolDependency> dependencies = getToolRepository().findDependencies(this.tool, toolEdition.edition(), version);
9✔
322
    int size = dependencies.size();
3✔
323
    LOG.debug("Tool {} has {} other tool(s) as dependency", toolEdition, size);
6✔
324
    for (ToolDependency dependency : dependencies) {
10✔
325
      LOG.trace("Ensuring dependency {} for tool {}", dependency.tool(), toolEdition);
6✔
326
      LocalToolCommandlet dependencyTool = this.context.getCommandletManager().getRequiredLocalToolCommandlet(dependency.tool());
7✔
327
      dependencyTool.installAsDependency(dependency.versionRange(), request);
6✔
328
    }
1✔
329
  }
1✔
330

331
  /**
332
   * Post-extraction hook that can be overridden to add custom processing after unpacking and before moving to the final destination folder.
333
   *
334
   * @param extractedDir the {@link Path} to the folder with the unpacked tool.
335
   */
336
  protected void postExtract(Path extractedDir) {
337

338
  }
1✔
339

340
  @Override
341
  public VersionIdentifier getInstalledVersion() {
342

343
    return getInstalledVersion(getToolPath());
5✔
344
  }
345

346
  /**
347
   * @param toolPath the installation {@link Path} where to find the version file.
348
   * @return the currently installed {@link VersionIdentifier version} of this tool or {@code null} if not installed.
349
   */
350
  protected VersionIdentifier getInstalledVersion(Path toolPath) {
351

352
    if (isToolNotInstalled(toolPath)) {
4✔
353
      return null;
2✔
354
    }
355
    Path versionLookupPath = getInstalledSoftwareRepoPath(toolPath, false);
5✔
356
    if (versionLookupPath == null) {
2✔
357
      versionLookupPath = toolPath;
2✔
358
    }
359
    Path toolVersionFile = versionLookupPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
360
    if (!Files.exists(toolVersionFile)) {
5✔
361
      Path legacyToolVersionFile = versionLookupPath.resolve(IdeContext.FILE_LEGACY_SOFTWARE_VERSION);
4✔
362
      if (Files.exists(legacyToolVersionFile)) {
5!
363
        toolVersionFile = legacyToolVersionFile;
3✔
364
      } else {
365
        LOG.warn("Tool {} is missing version file in {}", getName(), toolVersionFile);
×
366
        return null;
×
367
      }
368
    }
369
    String version = this.context.getFileAccess().readFileContent(toolVersionFile).trim();
7✔
370
    return VersionIdentifier.of(version);
3✔
371
  }
372

373
  @Override
374
  public String getInstalledEdition() {
375

376
    return getInstalledEdition(getToolPath());
5✔
377
  }
378

379
  /**
380
   * @param toolPath the installation {@link Path} where to find currently installed tool. The name of the parent directory of the real path corresponding
381
   *     to the passed {@link Path path} must be the name of the edition.
382
   * @return the installed edition of this tool or {@code null} if not installed.
383
   */
384
  protected String getInstalledEdition(Path toolPath) {
385
    if (isToolNotInstalled(toolPath)) {
4✔
386
      return null;
2✔
387
    }
388
    Path realPath = this.context.getFileAccess().toRealPath(toolPath);
6✔
389
    // if the realPath changed, a link has been resolved
390
    if (realPath.equals(toolPath)) {
4✔
391
      if (!isIgnoreSoftwareRepo()) {
3✔
392
        LOG.warn("Tool {} is not installed via software repository (maybe from devonfw-ide). Please consider reinstalling it.", this.tool);
5✔
393
      }
394
      // I do not see any reliable way how we could determine the edition of a tool that does not use software repo or that was installed by devonfw-ide
395
      return getConfiguredEdition();
3✔
396
    }
397
    Path toolRepoFolder = context.getSoftwareRepositoryPath().resolve(ToolRepository.ID_DEFAULT).resolve(this.tool);
9✔
398
    String edition = getEdition(toolRepoFolder, realPath);
5✔
399
    if (edition == null) {
2!
400
      edition = this.tool;
×
401
    }
402
    if (!getToolRepository().getSortedEditions(this.tool).contains(edition)) {
8✔
403
      LOG.warn("Undefined edition {} of tool {}", edition, this.tool);
6✔
404
    }
405
    return edition;
2✔
406
  }
407

408
  private String getEdition(Path toolRepoFolder, Path toolInstallFolder) {
409

410
    int toolRepoNameCount = toolRepoFolder.getNameCount();
3✔
411
    int toolInstallNameCount = toolInstallFolder.getNameCount();
3✔
412
    if (toolRepoNameCount < toolInstallNameCount) {
3!
413
      // ensure toolInstallFolder starts with $IDE_ROOT/_ide/software/default/«tool»
414
      for (int i = 0; i < toolRepoNameCount; i++) {
7✔
415
        if (!toolRepoFolder.getName(i).toString().equals(toolInstallFolder.getName(i).toString())) {
10!
416
          return null;
×
417
        }
418
      }
419
      return toolInstallFolder.getName(toolRepoNameCount).toString();
5✔
420
    }
421
    return null;
×
422
  }
423

424
  private Path getInstalledSoftwareRepoPath(Path toolPath) {
425
    return getInstalledSoftwareRepoPath(toolPath, false);
×
426
  }
427

428
  private Path getInstalledSoftwareRepoPath(Path toolPath, boolean logIfNotSoftwareRepo) {
429
    if (isToolNotInstalled(toolPath)) {
4!
430
      return null;
×
431
    }
432
    Path installPath = this.context.getFileAccess().toRealPath(toolPath);
6✔
433
    // if the installPath changed, a link has been resolved
434
    if (installPath.equals(toolPath)) {
4✔
435
      if (logIfNotSoftwareRepo && !isIgnoreSoftwareRepo()) {
2!
436
        LOG.warn("Tool {} is not installed via software repository (maybe from devonfw-ide). Please consider reinstalling it.", this.tool);
×
437
      }
438
      // I do not see any reliable way how we could determine the edition of a tool that does not use software repo or that was installed by devonfw-ide
439
      return null;
2✔
440
    }
441
    installPath = getValidInstalledSoftwareRepoPath(installPath, context.getSoftwareRepositoryPath());
7✔
442
    return installPath;
2✔
443
  }
444

445
  Path getValidInstalledSoftwareRepoPath(Path installPath, Path softwareRepoPath) {
446
    int softwareRepoNameCount = softwareRepoPath.getNameCount();
3✔
447
    int toolInstallNameCount = installPath.getNameCount();
3✔
448
    int targetToolInstallNameCount = softwareRepoNameCount + 4;
4✔
449

450
    // installPath can't be shorter than softwareRepoPath
451
    if (toolInstallNameCount < softwareRepoNameCount) {
3!
452
      LOG.warn("The installation path is not located within the software repository {}.", installPath);
×
453
      return null;
×
454
    }
455
    // ensure installPath starts with $IDE_ROOT/_ide/software/
456
    for (int i = 0; i < softwareRepoNameCount; i++) {
7✔
457
      if (!softwareRepoPath.getName(i).toString().equals(installPath.getName(i).toString())) {
10✔
458
        LOG.warn("The installation path is not located within the software repository {}.", installPath);
4✔
459
        return null;
2✔
460
      }
461
    }
462
    // return $IDE_ROOT/_ide/software/«id»/«tool»/«edition»/«version»
463
    if (toolInstallNameCount == targetToolInstallNameCount) {
3✔
464
      return installPath;
2✔
465
    } else if (toolInstallNameCount > targetToolInstallNameCount) {
3✔
466
      Path validInstallPath = installPath;
2✔
467
      for (int i = 0; i < toolInstallNameCount - targetToolInstallNameCount; i++) {
9✔
468
        validInstallPath = validInstallPath.getParent();
3✔
469
      }
470
      return validInstallPath;
2✔
471
    } else {
472
      LOG.warn("The installation path is faulty {}.", installPath);
4✔
473
      return null;
2✔
474
    }
475
  }
476

477
  private boolean isToolNotInstalled(Path toolPath) {
478

479
    if ((toolPath == null) || !Files.isDirectory(toolPath)) {
7!
480
      LOG.debug("Tool {} not installed in {}", this.tool, toolPath);
6✔
481
      return true;
2✔
482
    }
483
    return false;
2✔
484
  }
485

486
  @Override
487
  public void uninstall() {
488
    try {
489
      Path toolPath = getToolPath();
3✔
490
      if (!Files.exists(toolPath)) {
5!
491
        LOG.warn("An installed version of {} does not exist.", this.tool);
×
492
        return;
×
493
      }
494
      if (this.context.isForceMode() && !isIgnoreSoftwareRepo()) {
7!
495
        LOG.warn(
6✔
496
            "You triggered an uninstall of {} in version {} with force mode!\n"
497
                + "This will physically delete the currently installed version including its plugins from the machine.\n"
498
                + "This may cause issues with other projects, that use the same version of that tool."
499
            , this.tool, getInstalledVersion());
1✔
500
        uninstallPluginsOfTool();
2✔
501
        uninstallFromSoftwareRepository(toolPath);
3✔
502
      }
503
      performUninstall(toolPath);
3✔
504
      IdeLogLevel.SUCCESS.log(LOG, "Successfully uninstalled {}", this.tool);
11✔
505
    } catch (Exception e) {
×
506
      LOG.error("Failed to uninstall {}", this.tool, e);
×
507
    }
1✔
508
  }
1✔
509

510
  /**
511
   * Performs the actual uninstallation of this tool.
512
   *
513
   * @param toolPath the current {@link #getToolPath() tool path}.
514
   */
515
  protected void performUninstall(Path toolPath) {
516
    this.context.getFileAccess().delete(toolPath);
5✔
517
  }
1✔
518

519
  /**
520
   * Deletes the installed version of the tool from the shared software repository.
521
   */
522
  private void uninstallFromSoftwareRepository(Path toolPath) {
523
    Path repoPath = getInstalledSoftwareRepoPath(toolPath, true);
5✔
524
    if ((repoPath == null) || !Files.exists(repoPath)) {
7!
525
      LOG.warn("An installed version of {} does not exist in software repository.", this.tool);
×
526
      return;
×
527
    }
528
    LOG.info("Physically deleting {} as requested by the user via force mode.", repoPath);
4✔
529
    this.context.getFileAccess().delete(repoPath);
5✔
530
    IdeLogLevel.SUCCESS.log(LOG, "Successfully deleted {} from your computer.", repoPath);
10✔
531
  }
1✔
532

533
  /**
534
   * Deletes the installed plugins of the tool from the plugins path.
535
   */
536
  private void uninstallPluginsOfTool() {
537

538
    Path toolPluginsPath = this.context.getPluginsPath().resolve(this.tool);
7✔
539
    if (!Files.exists(toolPluginsPath)) {
5!
540
      LOG.info("There are no plugins of {} present to delete.", this.tool);
5✔
541
      return;
1✔
542
    }
543
    LOG.info("Physically deleting {} as requested by the user via force mode.", toolPluginsPath);
×
544
    this.context.getFileAccess().delete(toolPluginsPath);
×
545
    IdeLogLevel.SUCCESS.log(LOG, "Successfully deleted {} from your computer.", toolPluginsPath);
×
546
  }
×
547

548
  @Override
549
  protected Path getInstallationPath(String edition, VersionIdentifier resolvedVersion) {
550
    Path installationPath;
551
    if (isIgnoreSoftwareRepo()) {
3✔
552
      installationPath = getToolPath();
4✔
553
    } else {
554
      Path softwareRepositoryPath = this.context.getSoftwareRepositoryPath();
4✔
555
      if (softwareRepositoryPath == null) {
2!
556
        return null;
×
557
      }
558
      Path softwareRepoPath = softwareRepositoryPath.resolve(getToolRepository().getId()).resolve(this.tool).resolve(edition);
11✔
559
      installationPath = softwareRepoPath.resolve(resolvedVersion.toString());
5✔
560
    }
561
    return installationPath;
2✔
562
  }
563

564
  /**
565
   * @return {@link VersionIdentifier} with latest version of the tool}.
566
   */
567
  public VersionIdentifier getLatestToolVersion() {
568

569
    return this.context.getDefaultToolRepository().resolveVersion(this.tool, getConfiguredEdition(), VersionIdentifier.LATEST, this);
×
570
  }
571

572

573
  /**
574
   * Searches for a wrapper file in valid projects (containing a build file f.e. build.gradle or pom.xml) and returns its path.
575
   *
576
   * @param wrapperFileName the name of the wrapper file
577
   * @return Path of the wrapper file or {@code null} if none was found.
578
   */
579
  protected Path findWrapper(String wrapperFileName) {
580
    Path dir = this.context.getCwd();
4✔
581
    // traverse the cwd directory containing a build descriptor up till a wrapper file was found
582
    while ((dir != null) && (findBuildDescriptor(dir) != null)) {
6!
583
      Path wrapper = dir.resolve(wrapperFileName);
4✔
584
      if (Files.exists(wrapper)) {
5✔
585
        LOG.debug("Using wrapper: {}", wrapper);
4✔
586
        return wrapper;
2✔
587
      }
588
      dir = dir.getParent();
3✔
589
    }
1✔
590
    return null;
2✔
591
  }
592

593
  /**
594
   * @param directory the {@link Path} to the build directory.
595
   * @return the build configuration file for this tool or {@code null} if not found (or this is not a build tool).
596
   */
597
  public Path findBuildDescriptor(Path directory) {
598
    return null;
2✔
599
  }
600
}
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