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

devonfw / IDEasy / 26284300524

22 May 2026 11:08AM UTC coverage: 71.01% (-0.05%) from 71.062%
26284300524

Pull #1913

github

web-flow
Merge fa59dfda0 into 22c5b141e
Pull Request #1913: 1719: Rust Integration

4472 of 6978 branches covered (64.09%)

Branch coverage included in aggregate %.

11584 of 15633 relevant lines covered (74.1%)

3.13 hits per line

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

80.51
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
  @Override
82
  protected ToolInstallation doInstall(ToolInstallRequest request) {
83

84
    Step step = request.getStep();
3✔
85
    if (step == null) {
2!
86
      return doInstallStep(request);
4✔
87
    } else {
88
      return step.call(() -> doInstallStep(request),
×
89
          () -> createExistingToolInstallation(request));
×
90
    }
91
  }
92

93
  private ToolInstallation doInstallStep(ToolInstallRequest request) {
94

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

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

140
  /**
141
   * Determines whether this tool should be installed directly in the software folder or in the software repository.
142
   *
143
   * @return {@code true} if the tool should be installed directly in the software folder, ignoring the central software repository; {@code false} if the tool
144
   *     should be installed in the central software repository (default behavior).
145
   */
146
  protected boolean isIgnoreSoftwareRepo() {
147

148
    return false;
2✔
149
  }
150

151
  /**
152
   * Performs the installation of the {@link #getName() tool} together with the environment context  managed by this
153
   * {@link com.devonfw.tools.ide.commandlet.Commandlet}.
154
   *
155
   * @param request the {@link ToolInstallRequest}.
156
   * @return the resulting {@link ToolInstallation}.
157
   */
158
  public ToolInstallation installTool(ToolInstallRequest request) {
159

160
    completeRequest(request); // most likely already done, but if installTool was called directly and not from install
3✔
161
    if (request.isInstallLoop()) {
3!
162
      return toolAlreadyInstalled(request);
×
163
    }
164
    ToolEditionAndVersion requested = request.getRequested();
3✔
165
    ToolEdition toolEdition = requested.getEdition();
3✔
166
    assert (toolEdition.tool().equals(this.tool)) : "Mismatch " + this.tool + " != " + toolEdition.tool();
7!
167
    String edition = toolEdition.edition();
3✔
168
    VersionIdentifier resolvedVersion = cveCheck(request);
4✔
169
    installToolDependencies(request);
3✔
170

171
    // cveCheck might have changed resolvedVersion so let us re-check...
172
    if (request.isAlreadyInstalled()) {
3✔
173
      return toolAlreadyInstalled(request);
4✔
174
    } else {
175
      ToolEditionAndVersion installed = request.getInstalled();
3✔
176
      LOG.debug("Installation from {} to {}.", installed, requested);
5✔
177
    }
178
    Path installationPath = getInstallationPath(edition, resolvedVersion);
5✔
179

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

225
  /**
226
   * Performs the installation of the {@link #getName() tool} by using {@link #onInstall(ToolInstallRequest, Path, Path)}
227
   * for tool-specific logic, backing up any existing installation, and writing the version file.
228
   * <p>
229
   * This method assumes that the version has already been resolved and dependencies installed. It handles the final steps of placing the tool into the
230
   * appropriate installation directory.
231
   *
232
   * @param request the {@link ToolInstallRequest}.
233
   * @param installationPath the target {@link Path} where the {@link #getName() tool} should be installed.
234
   */
235
  protected void performToolInstallation(ToolInstallRequest request, Path installationPath) {
236

237
    FileAccess fileAccess = this.context.getFileAccess();
4✔
238
    ToolEditionAndVersion requested = request.getRequested();
3✔
239
    VersionIdentifier resolvedVersion = requested.getResolvedVersion();
3✔
240
    Path downloadedToolFile = getDownloadedToolFile(request);
4✔
241

242
    if (Files.isDirectory(installationPath)) {
5!
243
      if (this.tool.equals(IdeasyCommandlet.TOOL_NAME)) {
×
244
        LOG.warn("Your IDEasy installation is missing the version file.");
×
245
      } else {
246
        fileAccess.backup(installationPath);
×
247
      }
248
    }
249
    fileAccess.mkdirs(installationPath.getParent());
4✔
250

251
    onInstall(request, installationPath, downloadedToolFile);
5✔
252

253
    this.context.writeVersionFile(resolvedVersion, installationPath);
5✔
254
    // fix macOS Gatekeeper blocking - must run after version file is written but before any executables are launched
255
    getMacOsHelper().removeQuarantineAttribute(installationPath);
4✔
256
    LOG.debug("Installed {} in version {} at {}", this.tool, resolvedVersion, installationPath);
18✔
257
  }
1✔
258

259
  /**
260
   * Performs the actual installation of the tool bits.
261
   *
262
   * @param request the {@link ToolInstallRequest}.
263
   * @param installationPath the target {@link Path} where the tool should be installed.
264
   * @param downloadedToolFile the {@link Path} to the downloaded tool file.
265
   */
266
  protected void onInstall(ToolInstallRequest request, Path installationPath, Path downloadedToolFile) {
267

268
    boolean extract = isExtract();
3✔
269
    if (!extract) {
2✔
270
      LOG.trace("Extraction is disabled for '{}' hence just moving the downloaded file {}.", this.tool, downloadedToolFile);
6✔
271
    }
272
    this.context.getFileAccess().extract(downloadedToolFile, installationPath, this::postExtract, extract);
9✔
273
  }
1✔
274

275
  /**
276
   * @param request the {@link ToolInstallRequest}.
277
   * @return the {@link Path} to the downloaded tool file.
278
   */
279
  protected Path getDownloadedToolFile(ToolInstallRequest request) {
280

281
    ToolEditionAndVersion requested = request.getRequested();
3✔
282
    VersionIdentifier resolvedVersion = requested.getResolvedVersion();
3✔
283
    return downloadTool(requested.getEdition().edition(), resolvedVersion);
7✔
284
  }
285

286
  /**
287
   * @param edition the {@link #getConfiguredEdition() tool edition} to download.
288
   * @param resolvedVersion the resolved {@link VersionIdentifier version} to download.
289
   * @return the {@link Path} to the downloaded release file.
290
   */
291
  protected Path downloadTool(String edition, VersionIdentifier resolvedVersion) {
292
    return getToolRepository().download(this.tool, edition, resolvedVersion, this);
9✔
293
  }
294

295
  /**
296
   * Install this tool as dependency of another tool.
297
   *
298
   * @param versionRange the required {@link VersionRange}. See {@link ToolDependency#versionRange()}.
299
   * @param parentRequest the {@link ToolInstallRequest} of the tool causing this dependency.
300
   * @return the corresponding {@link ToolInstallation}.
301
   */
302
  public ToolInstallation installAsDependency(VersionRange versionRange, ToolInstallRequest parentRequest) {
303
    ToolInstallRequest request = new ToolInstallRequest(parentRequest);
5✔
304
    ToolEditionAndVersion requested = new ToolEditionAndVersion(getToolWithConfiguredEdition());
6✔
305
    request.setRequested(requested);
3✔
306
    VersionIdentifier configuredVersion = getConfiguredVersion();
3✔
307
    if (versionRange.contains(configuredVersion)) {
4✔
308
      // prefer configured version if contained in version range
309
      requested.setVersion(configuredVersion);
3✔
310
      // return install(true, configuredVersion, processContext, null);
311
      return install(request);
4✔
312
    } else {
313
      if (isIgnoreSoftwareRepo()) {
3!
314
        throw new IllegalStateException(
×
315
            "Cannot satisfy dependency to " + this.tool + " in version " + versionRange + " for " + parentRequest.getRequested()
×
316
                + " since it is conflicting with configured version "
317
                + configuredVersion
318
                + " and this tool does not support the software repository.");
319
      }
320
      LOG.info(
8✔
321
          "The tool {} requires {} in the version range {}, but your project uses version {}, which does not match."
322
              + " Therefore, we install a compatible version in that range.",
323
          parentRequest.getRequested().getEdition(), this.tool, versionRange, configuredVersion);
16✔
324
      requested.setVersion(versionRange);
3✔
325
      return installTool(request);
4✔
326
    }
327
  }
328

329
  /**
330
   * Installs the tool dependencies for the current tool.
331
   *
332
   * @param request the {@link ToolInstallRequest}.
333
   */
334
  protected void installToolDependencies(ToolInstallRequest request) {
335

336
    ToolEditionAndVersion requested = request.getRequested();
3✔
337
    VersionIdentifier version = requested.getResolvedVersion();
3✔
338
    ToolEdition toolEdition = requested.getEdition();
3✔
339
    Collection<ToolDependency> dependencies = getToolRepository().findDependencies(this.tool, toolEdition.edition(), version);
9✔
340
    int size = dependencies.size();
3✔
341
    LOG.debug("Tool {} has {} other tool(s) as dependency", toolEdition, size);
6✔
342
    for (ToolDependency dependency : dependencies) {
10✔
343
      LOG.trace("Ensuring dependency {} for tool {}", dependency.tool(), toolEdition);
6✔
344
      LocalToolCommandlet dependencyTool = this.context.getCommandletManager().getRequiredLocalToolCommandlet(dependency.tool());
7✔
345
      dependencyTool.installAsDependency(dependency.versionRange(), request);
6✔
346
    }
1✔
347
  }
1✔
348

349
  /**
350
   * Post-extraction hook that can be overridden to add custom processing after unpacking and before moving to the final destination folder.
351
   *
352
   * @param extractedDir the {@link Path} to the folder with the unpacked tool.
353
   */
354
  protected void postExtract(Path extractedDir) {
355

356
  }
1✔
357

358
  @Override
359
  public VersionIdentifier getInstalledVersion() {
360

361
    return getInstalledVersion(getToolPath());
5✔
362
  }
363

364
  /**
365
   * @param toolPath the installation {@link Path} where to find the version file.
366
   * @return the currently installed {@link VersionIdentifier version} of this tool or {@code null} if not installed.
367
   */
368
  protected VersionIdentifier getInstalledVersion(Path toolPath) {
369

370
    if (isToolNotInstalled(toolPath)) {
4✔
371
      return null;
2✔
372
    }
373
    Path versionLookupPath = getInstalledSoftwareRepoPath(toolPath, false);
5✔
374
    if (versionLookupPath == null) {
2✔
375
      versionLookupPath = toolPath;
2✔
376
    }
377
    Path toolVersionFile = versionLookupPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
378
    if (!Files.exists(toolVersionFile)) {
5✔
379
      Path legacyToolVersionFile = versionLookupPath.resolve(IdeContext.FILE_LEGACY_SOFTWARE_VERSION);
4✔
380
      if (Files.exists(legacyToolVersionFile)) {
5!
381
        toolVersionFile = legacyToolVersionFile;
3✔
382
      } else {
383
        LOG.warn("Tool {} is missing version file in {}", getName(), toolVersionFile);
×
384
        return null;
×
385
      }
386
    }
387
    String version = this.context.getFileAccess().readFileContent(toolVersionFile).trim();
7✔
388
    return VersionIdentifier.of(version);
3✔
389
  }
390

391
  @Override
392
  public String getInstalledEdition() {
393

394
    return getInstalledEdition(getToolPath());
5✔
395
  }
396

397
  /**
398
   * @param toolPath the installation {@link Path} where to find currently installed tool. The name of the parent directory of the real path corresponding
399
   *     to the passed {@link Path path} must be the name of the edition.
400
   * @return the installed edition of this tool or {@code null} if not installed.
401
   */
402
  protected String getInstalledEdition(Path toolPath) {
403
    if (isToolNotInstalled(toolPath)) {
4✔
404
      return null;
2✔
405
    }
406
    Path realPath = this.context.getFileAccess().toRealPath(toolPath);
6✔
407
    // if the realPath changed, a link has been resolved
408
    if (realPath.equals(toolPath)) {
4✔
409
      if (!isIgnoreSoftwareRepo()) {
3✔
410
        LOG.warn("Tool {} is not installed via software repository (maybe from devonfw-ide). Please consider reinstalling it.", this.tool);
5✔
411
      }
412
      // 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
413
      return getConfiguredEdition();
3✔
414
    }
415
    Path toolRepoFolder = context.getSoftwareRepositoryPath().resolve(ToolRepository.ID_DEFAULT).resolve(this.tool);
9✔
416
    String edition = getEdition(toolRepoFolder, realPath);
5✔
417
    if (edition == null) {
2!
418
      edition = this.tool;
×
419
    }
420
    if (!getToolRepository().getSortedEditions(this.tool).contains(edition)) {
8✔
421
      LOG.warn("Undefined edition {} of tool {}", edition, this.tool);
6✔
422
    }
423
    return edition;
2✔
424
  }
425

426
  private String getEdition(Path toolRepoFolder, Path toolInstallFolder) {
427

428
    int toolRepoNameCount = toolRepoFolder.getNameCount();
3✔
429
    int toolInstallNameCount = toolInstallFolder.getNameCount();
3✔
430
    if (toolRepoNameCount < toolInstallNameCount) {
3!
431
      // ensure toolInstallFolder starts with $IDE_ROOT/_ide/software/default/«tool»
432
      for (int i = 0; i < toolRepoNameCount; i++) {
7✔
433
        if (!toolRepoFolder.getName(i).toString().equals(toolInstallFolder.getName(i).toString())) {
10!
434
          return null;
×
435
        }
436
      }
437
      return toolInstallFolder.getName(toolRepoNameCount).toString();
5✔
438
    }
439
    return null;
×
440
  }
441

442
  private Path getInstalledSoftwareRepoPath(Path toolPath) {
443
    return getInstalledSoftwareRepoPath(toolPath, false);
×
444
  }
445

446
  private Path getInstalledSoftwareRepoPath(Path toolPath, boolean logIfNotSoftwareRepo) {
447
    if (isToolNotInstalled(toolPath)) {
4!
448
      return null;
×
449
    }
450
    Path installPath = this.context.getFileAccess().toRealPath(toolPath);
6✔
451
    // if the installPath changed, a link has been resolved
452
    if (installPath.equals(toolPath)) {
4✔
453
      if (logIfNotSoftwareRepo && !isIgnoreSoftwareRepo()) {
2!
454
        LOG.warn("Tool {} is not installed via software repository (maybe from devonfw-ide). Please consider reinstalling it.", this.tool);
×
455
      }
456
      // 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
457
      return null;
2✔
458
    }
459
    installPath = getValidInstalledSoftwareRepoPath(installPath, context.getSoftwareRepositoryPath());
7✔
460
    return installPath;
2✔
461
  }
462

463
  Path getValidInstalledSoftwareRepoPath(Path installPath, Path softwareRepoPath) {
464
    int softwareRepoNameCount = softwareRepoPath.getNameCount();
3✔
465
    int toolInstallNameCount = installPath.getNameCount();
3✔
466
    int targetToolInstallNameCount = softwareRepoNameCount + 4;
4✔
467

468
    // installPath can't be shorter than softwareRepoPath
469
    if (toolInstallNameCount < softwareRepoNameCount) {
3!
470
      LOG.warn("The installation path is not located within the software repository {}.", installPath);
×
471
      return null;
×
472
    }
473
    // ensure installPath starts with $IDE_ROOT/_ide/software/
474
    for (int i = 0; i < softwareRepoNameCount; i++) {
7✔
475
      if (!softwareRepoPath.getName(i).toString().equals(installPath.getName(i).toString())) {
10✔
476
        LOG.warn("The installation path is not located within the software repository {}.", installPath);
4✔
477
        return null;
2✔
478
      }
479
    }
480
    // return $IDE_ROOT/_ide/software/«id»/«tool»/«edition»/«version»
481
    if (toolInstallNameCount == targetToolInstallNameCount) {
3✔
482
      return installPath;
2✔
483
    } else if (toolInstallNameCount > targetToolInstallNameCount) {
3✔
484
      Path validInstallPath = installPath;
2✔
485
      for (int i = 0; i < toolInstallNameCount - targetToolInstallNameCount; i++) {
9✔
486
        validInstallPath = validInstallPath.getParent();
3✔
487
      }
488
      return validInstallPath;
2✔
489
    } else {
490
      LOG.warn("The installation path is faulty {}.", installPath);
4✔
491
      return null;
2✔
492
    }
493
  }
494

495
  private boolean isToolNotInstalled(Path toolPath) {
496

497
    if ((toolPath == null) || !Files.isDirectory(toolPath)) {
7!
498
      LOG.debug("Tool {} not installed in {}", this.tool, toolPath);
6✔
499
      return true;
2✔
500
    }
501
    return false;
2✔
502
  }
503

504
  @Override
505
  public void uninstall() {
506
    try {
507
      Path toolPath = getToolPath();
3✔
508
      if (!Files.exists(toolPath)) {
5!
509
        LOG.warn("An installed version of {} does not exist.", this.tool);
×
510
        return;
×
511
      }
512
      if (this.context.isForceMode() && !isIgnoreSoftwareRepo()) {
7!
513
        LOG.warn(
6✔
514
            "You triggered an uninstall of {} in version {} with force mode!\n"
515
                + "This will physically delete the currently installed version including its plugins from the machine.\n"
516
                + "This may cause issues with other projects, that use the same version of that tool."
517
            , this.tool, getInstalledVersion());
1✔
518
        uninstallPluginsOfTool();
2✔
519
        uninstallFromSoftwareRepository(toolPath);
3✔
520
      }
521
      performUninstall(toolPath);
3✔
522
      IdeLogLevel.SUCCESS.log(LOG, "Successfully uninstalled {}", this.tool);
11✔
523
    } catch (Exception e) {
×
524
      LOG.error("Failed to uninstall {}", this.tool, e);
×
525
    }
1✔
526
  }
1✔
527

528
  /**
529
   * Performs the actual uninstallation of this tool.
530
   *
531
   * @param toolPath the current {@link #getToolPath() tool path}.
532
   */
533
  protected void performUninstall(Path toolPath) {
534
    this.context.getFileAccess().delete(toolPath);
5✔
535
  }
1✔
536

537
  /**
538
   * Deletes the installed version of the tool from the shared software repository.
539
   */
540
  private void uninstallFromSoftwareRepository(Path toolPath) {
541
    Path repoPath = getInstalledSoftwareRepoPath(toolPath, true);
5✔
542
    if ((repoPath == null) || !Files.exists(repoPath)) {
7!
543
      LOG.warn("An installed version of {} does not exist in software repository.", this.tool);
×
544
      return;
×
545
    }
546
    LOG.info("Physically deleting {} as requested by the user via force mode.", repoPath);
4✔
547
    this.context.getFileAccess().delete(repoPath);
5✔
548
    IdeLogLevel.SUCCESS.log(LOG, "Successfully deleted {} from your computer.", repoPath);
10✔
549
  }
1✔
550

551
  /**
552
   * Deletes the installed plugins of the tool from the plugins path.
553
   */
554
  private void uninstallPluginsOfTool() {
555

556
    Path toolPluginsPath = this.context.getPluginsPath().resolve(this.tool);
7✔
557
    if (!Files.exists(toolPluginsPath)) {
5!
558
      LOG.info("There are no plugins of {} present to delete.", this.tool);
5✔
559
      return;
1✔
560
    }
561
    LOG.info("Physically deleting {} as requested by the user via force mode.", toolPluginsPath);
×
562
    this.context.getFileAccess().delete(toolPluginsPath);
×
563
    IdeLogLevel.SUCCESS.log(LOG, "Successfully deleted {} from your computer.", toolPluginsPath);
×
564
  }
×
565

566
  @Override
567
  protected Path getInstallationPath(String edition, VersionIdentifier resolvedVersion) {
568
    Path installationPath;
569
    if (isIgnoreSoftwareRepo()) {
3✔
570
      installationPath = getToolPath();
4✔
571
    } else {
572
      Path softwareRepositoryPath = this.context.getSoftwareRepositoryPath();
4✔
573
      if (softwareRepositoryPath == null) {
2!
574
        return null;
×
575
      }
576
      Path softwareRepoPath = softwareRepositoryPath.resolve(getToolRepository().getId()).resolve(this.tool).resolve(edition);
11✔
577
      installationPath = softwareRepoPath.resolve(resolvedVersion.toString());
5✔
578
    }
579
    return installationPath;
2✔
580
  }
581

582
  /**
583
   * @return {@link VersionIdentifier} with latest version of the tool}.
584
   */
585
  public VersionIdentifier getLatestToolVersion() {
586

587
    return this.context.getDefaultToolRepository().resolveVersion(this.tool, getConfiguredEdition(), VersionIdentifier.LATEST, this);
×
588
  }
589

590

591
  /**
592
   * Searches for a wrapper file in valid projects (containing a build file f.e. build.gradle or pom.xml) and returns its path.
593
   *
594
   * @param wrapperFileName the name of the wrapper file
595
   * @return Path of the wrapper file or {@code null} if none was found.
596
   */
597
  protected Path findWrapper(String wrapperFileName) {
598
    Path dir = this.context.getCwd();
4✔
599
    // traverse the cwd directory containing a build descriptor up till a wrapper file was found
600
    while ((dir != null) && (findBuildDescriptor(dir) != null)) {
6!
601
      Path wrapper = dir.resolve(wrapperFileName);
4✔
602
      if (Files.exists(wrapper)) {
5✔
603
        LOG.debug("Using wrapper: {}", wrapper);
4✔
604
        return wrapper;
2✔
605
      }
606
      dir = dir.getParent();
3✔
607
    }
1✔
608
    return null;
2✔
609
  }
610

611
  /**
612
   * @param directory the {@link Path} to the build directory.
613
   * @return the build configuration file for this tool or {@code null} if not found (or this is not a build tool).
614
   */
615
  public Path findBuildDescriptor(Path directory) {
616
    return null;
2✔
617
  }
618
}
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