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

devonfw / IDEasy / 19651727463

24 Nov 2025 10:43PM UTC coverage: 69.156% (+0.1%) from 69.024%
19651727463

push

github

web-flow
#1144: #1145: CVE warnings and suggestions (#1593)

Co-authored-by: KianRolf <kian.loroff@capgemini.com>
Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>

3613 of 5721 branches covered (63.15%)

Branch coverage included in aggregate %.

9387 of 13077 relevant lines covered (71.78%)

3.15 hits per line

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

80.59
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

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

101
    // check if we already have this version installed (linked) locally in IDE_HOME/software
102
    VersionIdentifier resolvedVersion = installation.resolvedVersion();
3✔
103
    if (resolvedVersion.equals(installedVersion) && !installation.newInstallation()) {
7✔
104
      logToolAlreadyInstalled(silent, toolEdition, installedVersion);
5✔
105
      return installation;
2✔
106
    }
107
    FileAccess fileAccess = this.context.getFileAccess();
4✔
108
    boolean ignoreSoftwareRepo = isIgnoreSoftwareRepo();
3✔
109
    if (!ignoreSoftwareRepo) {
2✔
110
      Path toolPath = getToolPath();
3✔
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 (installation.binDir() != null) {
3!
119
      this.context.getPath().setPath(this.tool, installation.binDir());
8✔
120
    }
121
    postInstall(true, processContext);
4✔
122
    if (installedVersion == null) {
2✔
123
      asSuccess(step).log("Successfully installed {} in version {}", this.tool, resolvedVersion);
18✔
124
    } else {
125
      asSuccess(step).log("Successfully installed {} in version {} replacing previous version {}", this.tool, resolvedVersion, installedVersion);
21✔
126
    }
127
    return installation;
2✔
128
  }
129

130
  /**
131
   * Determines whether this tool should be installed directly in the software folder or in the software repository.
132
   *
133
   * @return {@code true} if the tool should be installed directly in the software folder, ignoring the central software repository; {@code false} if the tool
134
   *     should be installed in the central software repository (default behavior).
135
   */
136
  protected boolean isIgnoreSoftwareRepo() {
137

138
    return false;
2✔
139
  }
140

141
  /**
142
   * Performs the installation of the {@link #getName() tool} together with the environment context, managed by this
143
   * {@link com.devonfw.tools.ide.commandlet.Commandlet}.
144
   *
145
   * @param version the {@link GenericVersionRange} requested to be installed.
146
   * @param processContext the {@link ProcessContext} used to
147
   *     {@link #setEnvironment(EnvironmentContext, ToolInstallation, boolean) configure environment variables}.
148
   * @return the {@link ToolInstallation} matching the given {@code version}.
149
   */
150
  public ToolInstallation installTool(GenericVersionRange version, ProcessContext processContext) {
151

152
    return installTool(version, processContext, getToolWithEdition());
7✔
153
  }
154

155
  /**
156
   * Performs the installation of the {@link #getName() tool} together with the environment context  managed by this
157
   * {@link com.devonfw.tools.ide.commandlet.Commandlet}.
158
   *
159
   * @param version the {@link GenericVersionRange} requested to be installed.
160
   * @param processContext the {@link ProcessContext} used to
161
   *     {@link #setEnvironment(EnvironmentContext, ToolInstallation, boolean) configure environment variables}.
162
   * @param toolEdition the specific {@link ToolEdition} to install.
163
   * @return the {@link ToolInstallation} matching the given {@code version}.
164
   */
165
  public ToolInstallation installTool(GenericVersionRange version, ProcessContext processContext, ToolEdition toolEdition) {
166

167
    assert (toolEdition.tool().equals(this.tool)) : "Mismatch " + this.tool + " != " + toolEdition.tool();
7!
168
    // if version is a VersionRange, we are not called from install() but directly from installAsDependency() due to a version conflict of a dependency
169
    boolean extraInstallation = (version instanceof VersionRange);
3✔
170
    ToolRepository toolRepository = getToolRepository();
3✔
171
    String edition = toolEdition.edition();
3✔
172
    VersionIdentifier installedVersion = getInstalledVersion();
3✔
173
    String installedEdition = getInstalledEdition();
3✔
174
    boolean skipSuggestions = false;
2✔
175
    VersionIdentifier resolvedVersion;
176
    if (this.context.isSkipUpdatesMode() && toolEdition.edition().equals(installedEdition) && version.contains(installedVersion)) {
13✔
177
      resolvedVersion = installedVersion;
2✔
178
      skipSuggestions = true;
3✔
179
    } else {
180
      resolvedVersion = toolRepository.resolveVersion(this.tool, edition, version, this);
8✔
181
    }
182
    GenericVersionRange allowedVersion = VersionIdentifier.LATEST;
2✔
183
    if (version.isPattern()) {
3✔
184
      allowedVersion = version;
2✔
185
    }
186
    Path installationPath = getInstallationPath(edition, resolvedVersion);
5✔
187

188
    resolvedVersion = cveCheck(toolEdition, resolvedVersion, allowedVersion, skipSuggestions);
7✔
189
    installToolDependencies(resolvedVersion, toolEdition, processContext);
5✔
190

191
    if (resolvedVersion.equals(installedVersion) && edition.equals(installedEdition)) {
8✔
192
      this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, toolEdition, installationPath);
18✔
193
      return createToolInstallation(installationPath, resolvedVersion, false, processContext, extraInstallation);
8✔
194
    }
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
    return installTool(versionRange, processContext);
5✔
293
  }
294

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

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

320
  }
1✔
321

322
  @Override
323
  public VersionIdentifier getInstalledVersion() {
324

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

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

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

352
  @Override
353
  public String getInstalledEdition() {
354

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

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

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

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

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

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

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

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

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

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

503
  @Override
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