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

devonfw / IDEasy / 19639057675

24 Nov 2025 03:08PM UTC coverage: 69.124% (+0.2%) from 68.924%
19639057675

Pull #1593

github

web-flow
Merge 5ce6499df into ffcb5d97f
Pull Request #1593: #1144: #1145: CVE warnings and suggestions

3598 of 5699 branches covered (63.13%)

Branch coverage included in aggregate %.

9358 of 13044 relevant lines covered (71.74%)

3.15 hits per line

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

80.87
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
import java.util.function.Predicate;
9

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.EnvironmentContext;
14
import com.devonfw.tools.ide.process.ProcessContext;
15
import com.devonfw.tools.ide.step.Step;
16
import com.devonfw.tools.ide.tool.repository.ToolRepository;
17
import com.devonfw.tools.ide.url.model.file.json.ToolDependency;
18
import com.devonfw.tools.ide.version.GenericVersionRange;
19
import com.devonfw.tools.ide.version.VersionIdentifier;
20
import com.devonfw.tools.ide.version.VersionRange;
21

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

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

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

39
  /**
40
   * @return the {@link Path} where the tool is located (installed).
41
   */
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
    Path binPath = this.context.getFileAccess().findFirst(toolPath, path -> path.getFileName().toString().equals("bin"), false);
14✔
56
    if ((binPath != null) && Files.isDirectory(binPath)) {
7!
57
      return binPath;
2✔
58
    }
59
    return toolPath;
2✔
60
  }
61

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

68
    return false;
×
69
  }
70

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

77
  }
1✔
78

79
  @Override
80
  public ToolInstallation install(boolean silent, VersionIdentifier configuredVersion, ProcessContext processContext, Step step) {
81

82
    installDependencies();
2✔
83
    // get installed version before installInRepo actually may install the software
84
    VersionIdentifier installedVersion = getInstalledVersion();
3✔
85
    if (step == null) {
2!
86
      return doInstallStep(configuredVersion, installedVersion, silent, processContext, step);
8✔
87
    } else {
88
      return step.call(() -> doInstallStep(configuredVersion, installedVersion, silent, processContext, step),
×
89
          () -> createExistingToolInstallation(getConfiguredEdition(), configuredVersion, EnvironmentContext.getEmpty(), false));
×
90
    }
91
  }
92

93
  private ToolInstallation doInstallStep(VersionIdentifier configuredVersion, VersionIdentifier installedVersion, boolean silent, ProcessContext processContext,
94
      Step step) {
95

96
    ToolEdition toolEdition = getToolWithEdition();
3✔
97
    String installedEdition = getInstalledEdition();
3✔
98
    // check if we should skip updates and the configured version + edition matches the existing installation
99
    if (toolEdition.edition().equals(installedEdition) // edition must match to keep installation
7✔
100
        && configuredVersion.matches(installedVersion) // version mut match to keep installation
3✔
101
        && (!configuredVersion.isPattern() // if we have a fixed version we can keep installation
4✔
102
        || context.isSkipUpdatesMode())) { // or if skip updates option was activated
2✔
103
      return toolAlreadyInstalled(silent, toolEdition, installedVersion, processContext, true);
8✔
104
    }
105

106
    // install configured version of our tool in the software repository if not already installed
107
    ToolInstallation installation = installTool(configuredVersion, processContext, toolEdition);
6✔
108

109
    // check if we already have this version installed (linked) locally in IDE_HOME/software
110
    VersionIdentifier resolvedVersion = installation.resolvedVersion();
3✔
111
    if (resolvedVersion.equals(installedVersion) && !installation.newInstallation()) {
7✔
112
      logToolAlreadyInstalled(silent, toolEdition, installedVersion);
5✔
113
      return installation;
2✔
114
    }
115
    FileAccess fileAccess = this.context.getFileAccess();
4✔
116
    boolean ignoreSoftwareRepo = isIgnoreSoftwareRepo();
3✔
117
    if (!ignoreSoftwareRepo) {
2✔
118
      Path toolPath = getToolPath();
3✔
119
      // we need to link the version or update the link.
120
      if (Files.exists(toolPath, LinkOption.NOFOLLOW_LINKS)) {
9✔
121
        fileAccess.backup(toolPath);
4✔
122
      }
123
      fileAccess.mkdirs(toolPath.getParent());
4✔
124
      fileAccess.symlink(installation.linkDir(), toolPath);
5✔
125
    }
126
    if (installation.binDir() != null) {
3!
127
      this.context.getPath().setPath(this.tool, installation.binDir());
8✔
128
    }
129
    postInstall(true, processContext);
4✔
130
    if (installedVersion == null) {
2✔
131
      asSuccess(step).log("Successfully installed {} in version {}", this.tool, resolvedVersion);
18✔
132
    } else {
133
      asSuccess(step).log("Successfully installed {} in version {} replacing previous version {}", this.tool, resolvedVersion, installedVersion);
21✔
134
    }
135
    return installation;
2✔
136
  }
137

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

146
    return false;
2✔
147
  }
148

149
  /**
150
   * Performs the installation of the {@link #getName() tool} together with the environment context, managed by this
151
   * {@link com.devonfw.tools.ide.commandlet.Commandlet}.
152
   *
153
   * @param version the {@link GenericVersionRange} requested to be installed.
154
   * @param processContext the {@link ProcessContext} used to
155
   *     {@link #setEnvironment(EnvironmentContext, ToolInstallation, boolean) configure environment variables}.
156
   * @return the {@link ToolInstallation} matching the given {@code version}.
157
   */
158
  public ToolInstallation installTool(GenericVersionRange version, ProcessContext processContext) {
159

160
    return installTool(version, processContext, getToolWithEdition());
7✔
161
  }
162

163
  /**
164
   * Performs the installation of the {@link #getName() tool} together with the environment context  managed by this
165
   * {@link com.devonfw.tools.ide.commandlet.Commandlet}.
166
   *
167
   * @param version the {@link GenericVersionRange} requested to be installed.
168
   * @param processContext the {@link ProcessContext} used to
169
   *     {@link #setEnvironment(EnvironmentContext, ToolInstallation, boolean) configure environment variables}.
170
   * @param toolEdition the specific {@link ToolEdition} to install.
171
   * @return the {@link ToolInstallation} matching the given {@code version}.
172
   */
173
  public ToolInstallation installTool(GenericVersionRange version, ProcessContext processContext, ToolEdition toolEdition) {
174

175
    assert (toolEdition.tool().equals(this.tool)) : "Mismatch " + this.tool + " != " + toolEdition.tool();
7!
176
    // if version is a VersionRange, we are not called from install() but directly from installAsDependency() due to a version conflict of a dependency
177
    boolean extraInstallation = (version instanceof VersionRange);
3✔
178
    ToolRepository toolRepository = getToolRepository();
3✔
179
    String edition = toolEdition.edition();
3✔
180
    VersionIdentifier resolvedVersion = toolRepository.resolveVersion(this.tool, edition, version, this);
8✔
181
    GenericVersionRange allwedVersion = VersionIdentifier.LATEST;
2✔
182
    if (version.isPattern()) {
3✔
183
      // TODO this should be discussed...
184
      allwedVersion = version;
2✔
185
    }
186
    Path installationPath = getInstallationPath(edition, resolvedVersion);
5✔
187
    VersionIdentifier installedVersion = getInstalledVersion();
3✔
188
    String installedEdition = getInstalledEdition();
3✔
189
    if (resolvedVersion.equals(installedVersion) && edition.equals(installedEdition)) {
8✔
190
      this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, toolEdition, installationPath);
18✔
191
      return createToolInstallation(installationPath, resolvedVersion, false, processContext, extraInstallation);
8✔
192
    }
193
    resolvedVersion = cveCheck(toolEdition, resolvedVersion, allwedVersion, false);
7✔
194
    installToolDependencies(resolvedVersion, toolEdition, processContext);
5✔
195

196
    boolean ignoreSoftwareRepo = isIgnoreSoftwareRepo();
3✔
197
    Path toolVersionFile = installationPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
198
    FileAccess fileAccess = this.context.getFileAccess();
4✔
199
    if (Files.isDirectory(installationPath)) {
5✔
200
      if (Files.exists(toolVersionFile)) {
5!
201
        if (!ignoreSoftwareRepo) {
2✔
202
          assert resolvedVersion.equals(getInstalledVersion(installationPath)) :
7!
203
              "Found version " + getInstalledVersion(installationPath) + " in " + toolVersionFile + " but expected " + resolvedVersion;
×
204
          this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, toolEdition, installationPath);
18✔
205
          return createToolInstallation(installationPath, resolvedVersion, false, processContext, extraInstallation);
8✔
206
        }
207
      } else {
208
        // Makes sure that IDEasy will not delete itself
209
        if (this.tool.equals(IdeasyCommandlet.TOOL_NAME)) {
×
210
          this.context.warning("Your IDEasy installation is missing the version file at {}", toolVersionFile);
×
211
          return createToolInstallation(installationPath, resolvedVersion, false, processContext, extraInstallation);
×
212
        } else if (!isIgnoreMissingSoftwareVersionFile()) {
×
213
          this.context.warning("Deleting corrupted installation at {}", installationPath);
×
214
          fileAccess.delete(installationPath);
×
215
        }
216
      }
217
    }
218
    performToolInstallation(toolRepository, resolvedVersion, installationPath, edition, processContext);
7✔
219
    return createToolInstallation(installationPath, resolvedVersion, true, processContext, extraInstallation);
8✔
220
  }
221

222
  /**
223
   * Performs the actual installation of the {@link #getName() tool} by downloading its binary, optionally extracting it, backing up any existing installation,
224
   * and writing the version file.
225
   * <p>
226
   * This method assumes that the version has already been resolved and dependencies installed. It handles the final steps of placing the tool into the
227
   * appropriate installation directory.
228
   *
229
   * @param toolRepository the {@link ToolRepository} used to locate and download the tool.
230
   * @param resolvedVersion the resolved {@link VersionIdentifier} of the {@link #getName() tool} to install.
231
   * @param installationPath the target {@link Path} where the {@link #getName() tool} should be installed.
232
   * @param edition the specific edition of the tool to install.
233
   * @param processContext the {@link ProcessContext} used to manage the installation process.
234
   */
235
  protected void performToolInstallation(ToolRepository toolRepository, VersionIdentifier resolvedVersion, Path installationPath,
236
      String edition, ProcessContext processContext) {
237

238
    FileAccess fileAccess = this.context.getFileAccess();
4✔
239
    Path downloadedToolFile = downloadTool(edition, toolRepository, resolvedVersion);
6✔
240
    boolean extract = isExtract();
3✔
241
    if (!extract) {
2✔
242
      this.context.trace("Extraction is disabled for '{}' hence just moving the downloaded file {}.", this.tool, downloadedToolFile);
15✔
243
    }
244
    if (Files.isDirectory(installationPath)) {
5!
245
      if (this.tool.equals(IdeasyCommandlet.TOOL_NAME)) {
×
246
        this.context.warning("Your IDEasy installation is missing the version file.");
×
247
      } else {
248
        fileAccess.backup(installationPath);
×
249
      }
250
    }
251
    fileAccess.mkdirs(installationPath.getParent());
4✔
252
    fileAccess.extract(downloadedToolFile, installationPath, this::postExtract, extract);
7✔
253
    this.context.writeVersionFile(resolvedVersion, installationPath);
5✔
254
    this.context.debug("Installed {} in version {} at {}", this.tool, resolvedVersion, installationPath);
19✔
255
  }
1✔
256

257
  /**
258
   * @param edition the {@link #getConfiguredEdition() tool edition} to download.
259
   * @param toolRepository the {@link ToolRepository} to use.
260
   * @param resolvedVersion the resolved {@link VersionIdentifier version} to download.
261
   * @return the {@link Path} to the downloaded release file.
262
   */
263
  protected Path downloadTool(String edition, ToolRepository toolRepository, VersionIdentifier resolvedVersion) {
264
    return toolRepository.download(this.tool, edition, resolvedVersion, this);
8✔
265
  }
266

267
  /**
268
   * Install this tool as dependency of another tool.
269
   *
270
   * @param versionRange the required {@link VersionRange}. See {@link ToolDependency#versionRange()}.
271
   * @param processContext the {@link ProcessContext}.
272
   * @param toolParent the parent {@link ToolEdition} needing the dependency
273
   * @return {@code true} if the tool was newly installed, {@code false} otherwise (installation was already present).
274
   */
275
  public ToolInstallation installAsDependency(VersionRange versionRange, ProcessContext processContext, ToolEdition toolParent) {
276
    VersionIdentifier configuredVersion = getConfiguredVersion();
3✔
277
    if (versionRange.contains(configuredVersion)) {
4✔
278
      // prefer configured version if contained in version range
279
      return install(true, configuredVersion, processContext, null);
7✔
280
    } else {
281
      if (isIgnoreSoftwareRepo()) {
3!
282
        throw new IllegalStateException(
×
283
            "Cannot satisfy dependency to " + this.tool + " in version " + versionRange + " since it is conflicting with configured version "
284
                + configuredVersion
285
                + " and this tool does not support the software repository.");
286
      }
287
      this.context.info(
23✔
288
          "The tool {} requires {} in the version range {}, but your project uses version {}, which does not match."
289
              + " Therefore, we install a compatible version in that range.",
290
          toolParent, this.tool, versionRange, configuredVersion);
291
    }
292
    ToolInstallation toolInstallation = installTool(versionRange, processContext);
5✔
293
    return toolInstallation;
2✔
294
  }
295

296
  /**
297
   * Installs the tool dependencies for the current tool.
298
   *
299
   * @param version the {@link VersionIdentifier} to use.
300
   * @param toolEdition the {@link ToolEdition} to use.
301
   * @param processContext the {@link ProcessContext} to use.
302
   */
303
  protected void installToolDependencies(VersionIdentifier version, ToolEdition toolEdition, ProcessContext processContext) {
304
    Collection<ToolDependency> dependencies = getToolRepository().findDependencies(this.tool, toolEdition.edition(), version);
9✔
305
    int size = dependencies.size();
3✔
306
    this.context.debug("Tool {} has {} other tool(s) as dependency", toolEdition, size);
15✔
307
    for (ToolDependency dependency : dependencies) {
10✔
308
      this.context.trace("Ensuring dependency {} for tool {}", dependency.tool(), toolEdition);
15✔
309
      LocalToolCommandlet dependencyTool = this.context.getCommandletManager().getRequiredLocalToolCommandlet(dependency.tool());
7✔
310
      dependencyTool.installAsDependency(dependency.versionRange(), processContext, toolEdition);
7✔
311
    }
1✔
312
  }
1✔
313

314
  /**
315
   * Post-extraction hook that can be overridden to add custom processing after unpacking and before moving to the final destination folder.
316
   *
317
   * @param extractedDir the {@link Path} to the folder with the unpacked tool.
318
   */
319
  protected void postExtract(Path extractedDir) {
320

321
  }
1✔
322

323
  @Override
324
  public VersionIdentifier getInstalledVersion() {
325

326
    return getInstalledVersion(this.context.getSoftwarePath().resolve(getName()));
9✔
327
  }
328

329
  /**
330
   * @param toolPath the installation {@link Path} where to find the version file.
331
   * @return the currently installed {@link VersionIdentifier version} of this tool or {@code null} if not installed.
332
   */
333
  protected VersionIdentifier getInstalledVersion(Path toolPath) {
334

335
    if (!Files.isDirectory(toolPath)) {
5✔
336
      this.context.debug("Tool {} not installed in {}", getName(), toolPath);
15✔
337
      return null;
2✔
338
    }
339
    Path toolVersionFile = toolPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
340
    if (!Files.exists(toolVersionFile)) {
5✔
341
      Path legacyToolVersionFile = toolPath.resolve(IdeContext.FILE_LEGACY_SOFTWARE_VERSION);
4✔
342
      if (Files.exists(legacyToolVersionFile)) {
5!
343
        toolVersionFile = legacyToolVersionFile;
3✔
344
      } else {
345
        this.context.warning("Tool {} is missing version file in {}", getName(), toolVersionFile);
×
346
        return null;
×
347
      }
348
    }
349
    String version = this.context.getFileAccess().readFileContent(toolVersionFile).trim();
7✔
350
    return VersionIdentifier.of(version);
3✔
351
  }
352

353
  @Override
354
  public String getInstalledEdition() {
355

356
    if (this.context.getSoftwarePath() == null) {
4!
357
      return "";
×
358
    }
359
    return getInstalledEdition(this.context.getSoftwarePath().resolve(this.tool));
9✔
360
  }
361

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

392
  private String getEdition(Path toolRepoFolder, Path toolInstallFolder) {
393

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

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

426
  Path getValidInstalledSoftwareRepoPath(Path installPath, Path softwareRepoPath) {
427
    int softwareRepoNameCount = softwareRepoPath.getNameCount();
3✔
428
    int toolInstallNameCount = installPath.getNameCount();
3✔
429
    int targetToolInstallNameCount = softwareRepoNameCount + 4;
4✔
430

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

458
  @Override
459
  public void uninstall() {
460
    try {
461
      Path toolPath = getToolPath();
3✔
462
      if (!Files.exists(toolPath)) {
5!
463
        this.context.warning("An installed version of {} does not exist.", this.tool);
×
464
        return;
×
465
      }
466
      if (this.context.isForceMode() && !isIgnoreSoftwareRepo()) {
7!
467
        this.context.warning(
14✔
468
            "You triggered an uninstall of {} in version {} with force mode!\n"
469
                + "This will physically delete the currently installed version from the machine.\n"
470
                + "This may cause issues with other projects, that use the same version of that tool."
471
            , this.tool, getInstalledVersion());
2✔
472
        uninstallFromSoftwareRepository(toolPath);
3✔
473
      }
474
      performUninstall(toolPath);
3✔
475
      this.context.success("Successfully uninstalled {}", this.tool);
11✔
476
    } catch (Exception e) {
×
477
      this.context.error(e, "Failed to uninstall {}", this.tool);
×
478
    }
1✔
479
  }
1✔
480

481
  /**
482
   * Performs the actual uninstallation of this tool.
483
   *
484
   * @param toolPath the current {@link #getToolPath() tool path}.
485
   */
486
  protected void performUninstall(Path toolPath) {
487
    this.context.getFileAccess().delete(toolPath);
5✔
488
  }
1✔
489

490
  /**
491
   * Deletes the installed version of the tool from the shared software repository.
492
   */
493
  private void uninstallFromSoftwareRepository(Path toolPath) {
494
    Path repoPath = getInstalledSoftwareRepoPath(toolPath);
4✔
495
    if ((repoPath == null) || !Files.exists(repoPath)) {
7!
496
      this.context.warning("An installed version of {} does not exist in software repository.", this.tool);
×
497
      return;
×
498
    }
499
    this.context.info("Physically deleting {} as requested by the user via force mode.", repoPath);
10✔
500
    this.context.getFileAccess().delete(repoPath);
5✔
501
    this.context.success("Successfully deleted {} from your computer.", repoPath);
10✔
502
  }
1✔
503

504
  protected Path getInstallationPath(String edition, VersionIdentifier resolvedVersion) {
505
    Path installationPath;
506
    if (isIgnoreSoftwareRepo()) {
3✔
507
      installationPath = getToolPath();
4✔
508
    } else {
509
      Path softwareRepositoryPath = this.context.getSoftwareRepositoryPath();
4✔
510
      if (softwareRepositoryPath == null) {
2✔
511
        return null;
2✔
512
      }
513
      Path softwareRepoPath = softwareRepositoryPath.resolve(getToolRepository().getId()).resolve(this.tool).resolve(edition);
11✔
514
      installationPath = softwareRepoPath.resolve(resolvedVersion.toString());
5✔
515
    }
516
    return installationPath;
2✔
517
  }
518

519
  /**
520
   * @return {@link VersionIdentifier} with latest version of the tool}.
521
   */
522
  public VersionIdentifier getLatestToolVersion() {
523

524
    return this.context.getDefaultToolRepository().resolveVersion(this.tool, getConfiguredEdition(), VersionIdentifier.LATEST, this);
×
525
  }
526

527

528
  /**
529
   * Searches for a wrapper file in valid projects (containing a build file f.e. build.gradle or pom.xml) and returns its path.
530
   *
531
   * @param wrapperFileName the name of the wrapper file
532
   * @param filter the {@link Predicate} to match
533
   * @return Path of the wrapper file or {@code null} if none was found.
534
   */
535
  protected Path findWrapper(String wrapperFileName, Predicate<Path> filter) {
536
    Path dir = context.getCwd();
4✔
537
    // traverse the cwd directory containing a build file up till a wrapper file was found
538
    while ((dir != null) && filter.test(dir)) {
6!
539
      if (Files.exists(dir.resolve(wrapperFileName))) {
7✔
540
        context.debug("Using wrapper file at: {}", dir);
10✔
541
        return dir.resolve(wrapperFileName);
4✔
542
      }
543
      dir = dir.getParent();
4✔
544
    }
545
    return null;
2✔
546
  }
547

548

549
}
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