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

devonfw / IDEasy / 21014707628

15 Jan 2026 12:16AM UTC coverage: 70.399% (+0.04%) from 70.355%
21014707628

Pull #1671

github

web-flow
Merge 646e693c2 into 0c7f3d0ec
Pull Request #1671: #1602: Being offline can block ide startup

4023 of 6300 branches covered (63.86%)

Branch coverage included in aggregate %.

10451 of 14260 relevant lines covered (73.29%)

3.18 hits per line

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

80.76
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 com.devonfw.tools.ide.cli.CliOfflineException;
10
import com.devonfw.tools.ide.common.Tag;
11
import com.devonfw.tools.ide.context.IdeContext;
12
import com.devonfw.tools.ide.io.FileAccess;
13
import com.devonfw.tools.ide.process.ProcessContext;
14
import com.devonfw.tools.ide.step.Step;
15
import com.devonfw.tools.ide.tool.repository.ToolRepository;
16
import com.devonfw.tools.ide.url.model.file.json.ToolDependency;
17
import com.devonfw.tools.ide.version.GenericVersionRange;
18
import com.devonfw.tools.ide.version.VersionIdentifier;
19
import com.devonfw.tools.ide.version.VersionRange;
20

21
/**
22
 * {@link ToolCommandlet} that is installed locally into the IDEasy.
23
 */
24
public abstract class LocalToolCommandlet extends ToolCommandlet {
1✔
25

26
  /**
27
   * The constructor.
28
   *
29
   * @param context the {@link IdeContext}.
30
   * @param tool the {@link #getName() tool name}.
31
   * @param tags the {@link #getTags() tags} classifying the tool. Should be created via {@link Set#of(Object) Set.of} method.
32
   */
33
  public LocalToolCommandlet(IdeContext context, String tool, Set<Tag> tags) {
34

35
    super(context, tool, tags);
5✔
36
  }
1✔
37

38
  /**
39
   * @return the {@link Path} where the tool is located (installed).
40
   */
41
  @Override
42
  public Path getToolPath() {
43
    if (this.context.getSoftwarePath() == null) {
4!
44
      return null;
×
45
    }
46
    return this.context.getSoftwarePath().resolve(getName());
7✔
47
  }
48

49
  /**
50
   * @return the {@link Path} where the executables of the tool can be found. Typically, a "bin" folder inside {@link #getToolPath() tool path}.
51
   */
52
  public Path getToolBinPath() {
53

54
    Path toolPath = getToolPath();
3✔
55
    if (toolPath == null) {
2!
56
      return null;
×
57
    }
58
    Path binPath = toolPath.resolve(IdeContext.FOLDER_BIN);
4✔
59
    if (Files.isDirectory(binPath)) {
5✔
60
      return binPath;
2✔
61
    }
62
    return toolPath;
2✔
63
  }
64

65
  /**
66
   * @return {@code true} to ignore a missing {@link IdeContext#FILE_SOFTWARE_VERSION software version file} in an installation, {@code false} delete the broken
67
   *     installation (default).
68
   */
69
  protected boolean isIgnoreMissingSoftwareVersionFile() {
70

71
    return false;
×
72
  }
73

74
  /**
75
   * @deprecated will be removed once all "dependencies.json" are created in ide-urls.
76
   */
77
  @Deprecated
78
  protected void installDependencies() {
79

80
  }
1✔
81

82
  @Override
83
  protected ToolInstallation doInstall(ToolInstallRequest request) {
84

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

95
  private ToolInstallation doInstallStep(ToolInstallRequest request) {
96

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

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

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

147
    return false;
2✔
148
  }
149

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

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

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

179
    ProcessContext processContext = request.getProcessContext();
3✔
180
    boolean additionalInstallation = request.isAdditionalInstallation();
3✔
181
    boolean ignoreSoftwareRepo = isIgnoreSoftwareRepo();
3✔
182
    Path toolVersionFile = installationPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
183
    FileAccess fileAccess = this.context.getFileAccess();
4✔
184
    if (Files.isDirectory(installationPath)) {
5✔
185
      if (Files.exists(toolVersionFile)) {
5!
186
        if (!ignoreSoftwareRepo) {
2✔
187
          assert resolvedVersion.equals(getInstalledVersion(installationPath)) :
7!
188
              "Found version " + getInstalledVersion(installationPath) + " in " + toolVersionFile + " but expected " + resolvedVersion;
×
189
          this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, toolEdition, installationPath);
18✔
190
          return createToolInstallation(installationPath, resolvedVersion, false, processContext, additionalInstallation);
8✔
191
        }
192
      } else {
193
        // Makes sure that IDEasy will not delete itself
194
        if (this.tool.equals(IdeasyCommandlet.TOOL_NAME)) {
×
195
          this.context.warning("Your IDEasy installation is missing the version file at {}", toolVersionFile);
×
196
          return createToolInstallation(installationPath, resolvedVersion, false, processContext, additionalInstallation);
×
197
        } else if (!isIgnoreMissingSoftwareVersionFile()) {
×
198
          this.context.warning("Deleting corrupted installation at {}", installationPath);
×
199
          fileAccess.delete(installationPath);
×
200
        }
201
      }
202
    }
203
    VersionIdentifier actualInstalledVersion = performToolInstallation(request, installationPath, resolvedVersion);
6✔
204
    // If offline and could not download, actualInstalledVersion will be the old version, not resolvedVersion
205
    // In that case, we need to recalculate the installation path for the actually installed version
206
    if (!actualInstalledVersion.equals(resolvedVersion)) {
4✔
207
      installationPath = getInstallationPath(edition, actualInstalledVersion);
5✔
208
    }
209
    return createToolInstallation(installationPath, actualInstalledVersion, true, processContext, additionalInstallation);
8✔
210
  }
211

212
  /**
213
   * Performs the actual installation of the {@link #getName() tool} by downloading its binary, optionally extracting it, backing up any existing installation,
214
   * and writing the version file.
215
   * <p>
216
   * This method assumes that the version has already been resolved and dependencies installed. It handles the final steps of placing the tool into the
217
   * appropriate installation directory.
218
   *
219
   * @param request the {@link ToolInstallRequest}.
220
   * @param installationPath the target {@link Path} where the {@link #getName() tool} should be installed.
221
   * @param resolvedVersion the {@link VersionIdentifier} that should be installed.
222
   * @return the {@link VersionIdentifier} of the version that was actually installed. In offline scenarios where download fails, this may be different from
223
   *     {@code resolvedVersion} (returning the existing installed version instead).
224
   */
225
  protected VersionIdentifier performToolInstallation(ToolInstallRequest request, Path installationPath, VersionIdentifier resolvedVersion) {
226

227
    FileAccess fileAccess = this.context.getFileAccess();
4✔
228
    ToolEditionAndVersion requested = request.getRequested();
3✔
229
    Path downloadedToolFile;
230
    try {
231
      downloadedToolFile = downloadTool(requested.getEdition().edition(), resolvedVersion);
7✔
232
    } catch (CliOfflineException e) {
1✔
233
      // If we are offline and cannot download, check if we can continue with an existing installation
234
      ToolEditionAndVersion installed = request.getInstalled();
3✔
235
      if ((installed != null) && (installed.getResolvedVersion() != null)) {
5!
236
        this.context.warning("Cannot download {} in version {} because we are offline. Continuing with already installed version {}.",
18✔
237
            this.tool, resolvedVersion, installed.getResolvedVersion());
2✔
238
        // Return the existing installed version to indicate fallback
239
        return installed.getResolvedVersion();
3✔
240
      }
241
      // No existing installation available, re-throw the exception
242
      throw e;
2✔
243
    }
1✔
244
    boolean extract = isExtract();
3✔
245
    if (!extract) {
2✔
246
      this.context.trace("Extraction is disabled for '{}' hence just moving the downloaded file {}.", this.tool, downloadedToolFile);
15✔
247
    }
248
    if (Files.isDirectory(installationPath)) {
5!
249
      if (this.tool.equals(IdeasyCommandlet.TOOL_NAME)) {
×
250
        this.context.warning("Your IDEasy installation is missing the version file.");
×
251
      } else {
252
        fileAccess.backup(installationPath);
×
253
      }
254
    }
255
    fileAccess.mkdirs(installationPath.getParent());
4✔
256
    fileAccess.extract(downloadedToolFile, installationPath, this::postExtract, extract);
7✔
257
    this.context.writeVersionFile(resolvedVersion, installationPath);
5✔
258
    this.context.debug("Installed {} in version {} at {}", this.tool, resolvedVersion, installationPath);
19✔
259
    return resolvedVersion;
2✔
260
  }
261

262
  /**
263
   * @param edition the {@link #getConfiguredEdition() tool edition} to download.
264
   * @param resolvedVersion the resolved {@link VersionIdentifier version} to download.
265
   * @return the {@link Path} to the downloaded release file.
266
   */
267
  protected Path downloadTool(String edition, VersionIdentifier resolvedVersion) {
268
    return getToolRepository().download(this.tool, edition, resolvedVersion, this);
9✔
269
  }
270

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

305
  /**
306
   * Installs the tool dependencies for the current tool.
307
   *
308
   * @param request the {@link ToolInstallRequest}.
309
   */
310
  protected void installToolDependencies(ToolInstallRequest request) {
311

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

325
  /**
326
   * Post-extraction hook that can be overridden to add custom processing after unpacking and before moving to the final destination folder.
327
   *
328
   * @param extractedDir the {@link Path} to the folder with the unpacked tool.
329
   */
330
  protected void postExtract(Path extractedDir) {
331

332
  }
1✔
333

334
  @Override
335
  public VersionIdentifier getInstalledVersion() {
336

337
    return getInstalledVersion(getToolPath());
5✔
338
  }
339

340
  /**
341
   * @param toolPath the installation {@link Path} where to find the version file.
342
   * @return the currently installed {@link VersionIdentifier version} of this tool or {@code null} if not installed.
343
   */
344
  protected VersionIdentifier getInstalledVersion(Path toolPath) {
345

346
    if (isToolNotInstalled(toolPath)) {
4✔
347
      return null;
2✔
348
    }
349
    Path toolVersionFile = toolPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
350
    if (!Files.exists(toolVersionFile)) {
5✔
351
      Path legacyToolVersionFile = toolPath.resolve(IdeContext.FILE_LEGACY_SOFTWARE_VERSION);
4✔
352
      if (Files.exists(legacyToolVersionFile)) {
5!
353
        toolVersionFile = legacyToolVersionFile;
3✔
354
      } else {
355
        this.context.warning("Tool {} is missing version file in {}", getName(), toolVersionFile);
×
356
        return null;
×
357
      }
358
    }
359
    String version = this.context.getFileAccess().readFileContent(toolVersionFile).trim();
7✔
360
    return VersionIdentifier.of(version);
3✔
361
  }
362

363
  @Override
364
  public String getInstalledEdition() {
365

366
    return getInstalledEdition(getToolPath());
5✔
367
  }
368

369
  /**
370
   * @param toolPath the installation {@link Path} where to find currently installed tool. The name of the parent directory of the real path corresponding
371
   *     to the passed {@link Path path} must be the name of the edition.
372
   * @return the installed edition of this tool or {@code null} if not installed.
373
   */
374
  protected String getInstalledEdition(Path toolPath) {
375
    if (isToolNotInstalled(toolPath)) {
4✔
376
      return null;
2✔
377
    }
378
    Path realPath = this.context.getFileAccess().toRealPath(toolPath);
6✔
379
    // if the realPath changed, a link has been resolved
380
    if (realPath.equals(toolPath)) {
4✔
381
      if (!isIgnoreSoftwareRepo()) {
3✔
382
        this.context.warning("Tool {} is not installed via software repository (maybe from devonfw-ide). Please consider reinstalling it.", this.tool);
11✔
383
      }
384
      // 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
385
      return getConfiguredEdition();
3✔
386
    }
387
    Path toolRepoFolder = context.getSoftwareRepositoryPath().resolve(ToolRepository.ID_DEFAULT).resolve(this.tool);
9✔
388
    String edition = getEdition(toolRepoFolder, realPath);
5✔
389
    if (edition == null) {
2!
390
      edition = this.tool;
×
391
    }
392
    if (!getToolRepository().getSortedEditions(this.tool).contains(edition)) {
8✔
393
      this.context.warning("Undefined edition {} of tool {}", edition, this.tool);
15✔
394
    }
395
    return edition;
2✔
396
  }
397

398
  private String getEdition(Path toolRepoFolder, Path toolInstallFolder) {
399

400
    int toolRepoNameCount = toolRepoFolder.getNameCount();
3✔
401
    int toolInstallNameCount = toolInstallFolder.getNameCount();
3✔
402
    if (toolRepoNameCount < toolInstallNameCount) {
3!
403
      // ensure toolInstallFolder starts with $IDE_ROOT/_ide/software/default/«tool»
404
      for (int i = 0; i < toolRepoNameCount; i++) {
7✔
405
        if (!toolRepoFolder.getName(i).toString().equals(toolInstallFolder.getName(i).toString())) {
10!
406
          return null;
×
407
        }
408
      }
409
      return toolInstallFolder.getName(toolRepoNameCount).toString();
5✔
410
    }
411
    return null;
×
412
  }
413

414
  private Path getInstalledSoftwareRepoPath(Path toolPath) {
415
    if (isToolNotInstalled(toolPath)) {
4!
416
      return null;
×
417
    }
418
    Path installPath = this.context.getFileAccess().toRealPath(toolPath);
6✔
419
    // if the installPath changed, a link has been resolved
420
    if (installPath.equals(toolPath)) {
4!
421
      if (!isIgnoreSoftwareRepo()) {
×
422
        this.context.warning("Tool {} is not installed via software repository (maybe from devonfw-ide). Please consider reinstalling it.", this.tool);
×
423
      }
424
      // 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
425
      return null;
×
426
    }
427
    installPath = getValidInstalledSoftwareRepoPath(installPath, context.getSoftwareRepositoryPath());
7✔
428
    return installPath;
2✔
429
  }
430

431
  Path getValidInstalledSoftwareRepoPath(Path installPath, Path softwareRepoPath) {
432
    int softwareRepoNameCount = softwareRepoPath.getNameCount();
3✔
433
    int toolInstallNameCount = installPath.getNameCount();
3✔
434
    int targetToolInstallNameCount = softwareRepoNameCount + 4;
4✔
435

436
    // installPath can't be shorter than softwareRepoPath
437
    if (toolInstallNameCount < softwareRepoNameCount) {
3!
438
      this.context.warning("The installation path is not located within the software repository {}.", installPath);
×
439
      return null;
×
440
    }
441
    // ensure installPath starts with $IDE_ROOT/_ide/software/
442
    for (int i = 0; i < softwareRepoNameCount; i++) {
7✔
443
      if (!softwareRepoPath.getName(i).toString().equals(installPath.getName(i).toString())) {
10✔
444
        this.context.warning("The installation path is not located within the software repository {}.", installPath);
10✔
445
        return null;
2✔
446
      }
447
    }
448
    // return $IDE_ROOT/_ide/software/«id»/«tool»/«edition»/«version»
449
    if (toolInstallNameCount == targetToolInstallNameCount) {
3✔
450
      return installPath;
2✔
451
    } else if (toolInstallNameCount > targetToolInstallNameCount) {
3✔
452
      Path validInstallPath = installPath;
2✔
453
      for (int i = 0; i < toolInstallNameCount - targetToolInstallNameCount; i++) {
9✔
454
        validInstallPath = validInstallPath.getParent();
3✔
455
      }
456
      return validInstallPath;
2✔
457
    } else {
458
      this.context.warning("The installation path is faulty {}.", installPath);
10✔
459
      return null;
2✔
460
    }
461
  }
462

463
  private boolean isToolNotInstalled(Path toolPath) {
464

465
    if ((toolPath == null) || !Files.isDirectory(toolPath)) {
7!
466
      this.context.debug("Tool {} not installed in {}", this.tool, toolPath);
15✔
467
      return true;
2✔
468
    }
469
    return false;
2✔
470
  }
471

472
  @Override
473
  public void uninstall() {
474
    try {
475
      Path toolPath = getToolPath();
3✔
476
      if (!Files.exists(toolPath)) {
5!
477
        this.context.warning("An installed version of {} does not exist.", this.tool);
×
478
        return;
×
479
      }
480
      if (this.context.isForceMode() && !isIgnoreSoftwareRepo()) {
7!
481
        this.context.warning(
14✔
482
            "You triggered an uninstall of {} in version {} with force mode!\n"
483
                + "This will physically delete the currently installed version from the machine.\n"
484
                + "This may cause issues with other projects, that use the same version of that tool."
485
            , this.tool, getInstalledVersion());
2✔
486
        uninstallFromSoftwareRepository(toolPath);
3✔
487
      }
488
      performUninstall(toolPath);
3✔
489
      this.context.success("Successfully uninstalled {}", this.tool);
11✔
490
    } catch (Exception e) {
×
491
      this.context.error(e, "Failed to uninstall {}", this.tool);
×
492
    }
1✔
493
  }
1✔
494

495
  /**
496
   * Performs the actual uninstallation of this tool.
497
   *
498
   * @param toolPath the current {@link #getToolPath() tool path}.
499
   */
500
  protected void performUninstall(Path toolPath) {
501
    this.context.getFileAccess().delete(toolPath);
5✔
502
  }
1✔
503

504
  /**
505
   * Deletes the installed version of the tool from the shared software repository.
506
   */
507
  private void uninstallFromSoftwareRepository(Path toolPath) {
508
    Path repoPath = getInstalledSoftwareRepoPath(toolPath);
4✔
509
    if ((repoPath == null) || !Files.exists(repoPath)) {
7!
510
      this.context.warning("An installed version of {} does not exist in software repository.", this.tool);
×
511
      return;
×
512
    }
513
    this.context.info("Physically deleting {} as requested by the user via force mode.", repoPath);
10✔
514
    this.context.getFileAccess().delete(repoPath);
5✔
515
    this.context.success("Successfully deleted {} from your computer.", repoPath);
10✔
516
  }
1✔
517

518
  @Override
519
  protected Path getInstallationPath(String edition, VersionIdentifier resolvedVersion) {
520
    Path installationPath;
521
    if (isIgnoreSoftwareRepo()) {
3✔
522
      installationPath = getToolPath();
4✔
523
    } else {
524
      Path softwareRepositoryPath = this.context.getSoftwareRepositoryPath();
4✔
525
      if (softwareRepositoryPath == null) {
2!
526
        return null;
×
527
      }
528
      Path softwareRepoPath = softwareRepositoryPath.resolve(getToolRepository().getId()).resolve(this.tool).resolve(edition);
11✔
529
      installationPath = softwareRepoPath.resolve(resolvedVersion.toString());
5✔
530
    }
531
    return installationPath;
2✔
532
  }
533

534
  /**
535
   * @return {@link VersionIdentifier} with latest version of the tool}.
536
   */
537
  public VersionIdentifier getLatestToolVersion() {
538

539
    return this.context.getDefaultToolRepository().resolveVersion(this.tool, getConfiguredEdition(), VersionIdentifier.LATEST, this);
×
540
  }
541

542

543
  /**
544
   * Searches for a wrapper file in valid projects (containing a build file f.e. build.gradle or pom.xml) and returns its path.
545
   *
546
   * @param wrapperFileName the name of the wrapper file
547
   * @return Path of the wrapper file or {@code null} if none was found.
548
   */
549
  protected Path findWrapper(String wrapperFileName) {
550
    Path dir = this.context.getCwd();
4✔
551
    // traverse the cwd directory containing a build descriptor up till a wrapper file was found
552
    while ((dir != null) && (findBuildDescriptor(dir) != null)) {
6!
553
      Path wrapper = dir.resolve(wrapperFileName);
4✔
554
      if (Files.exists(wrapper)) {
5✔
555
        context.debug("Using wrapper: {}", wrapper);
10✔
556
        return wrapper;
2✔
557
      }
558
      dir = dir.getParent();
3✔
559
    }
1✔
560
    return null;
2✔
561
  }
562

563
  /**
564
   * @param directory the {@link Path} to the build directory.
565
   * @return the build configuration file for this tool or {@code null} if not found (or this is not a build tool).
566
   */
567
  public Path findBuildDescriptor(Path directory) {
568
    return null;
2✔
569
  }
570
}
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