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

devonfw / IDEasy / 20815527833

08 Jan 2026 11:38AM UTC coverage: 69.937% (+0.04%) from 69.902%
20815527833

Pull #1671

github

web-flow
Merge 279ae0013 into b9e7b47d8
Pull Request #1671: #1602: Being offline can block ide startup

3989 of 6280 branches covered (63.52%)

Branch coverage included in aggregate %.

10202 of 14011 relevant lines covered (72.81%)

3.15 hits per line

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

80.65
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
  public Path getToolPath() {
42
    if (this.context.getSoftwarePath() == null) {
4!
43
      return null;
×
44
    }
45
    return this.context.getSoftwarePath().resolve(getName());
7✔
46
  }
47

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

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

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

70
    return false;
×
71
  }
72

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

79
  }
1✔
80

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

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

94
  private ToolInstallation doInstallStep(ToolInstallRequest request) {
95

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

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

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

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

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

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

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

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

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

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

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

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

331
  }
1✔
332

333
  @Override
334
  public VersionIdentifier getInstalledVersion() {
335

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

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

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

362
  @Override
363
  public String getInstalledEdition() {
364

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

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

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

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

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

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

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

462
  private boolean isToolNotInstalled(Path toolPath) {
463

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

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

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

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

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

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

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

541

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

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