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

devonfw / IDEasy / 21129357355

19 Jan 2026 07:47AM UTC coverage: 70.374% (+0.03%) from 70.349%
21129357355

push

github

web-flow
#1602: Being offline can block ide startup (#1671)

Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>

4022 of 6304 branches covered (63.8%)

Branch coverage included in aggregate %.

10456 of 14269 relevant lines covered (73.28%)

3.18 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
  @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 = resolvedVersion;
2✔
204
    try {
205
      performToolInstallation(request, installationPath);
4✔
206
    } catch (CliOfflineException e) {
1✔
207
      // If we are offline and cannot download, check if we can continue with an existing installation
208
      ToolEditionAndVersion installed = request.getInstalled();
3✔
209
      if ((installed != null) && (installed.getResolvedVersion() != null)) {
5!
210
        this.context.warning("Cannot download {} in version {} because we are offline. Continuing with already installed version {}.", this.tool, resolvedVersion, installed.getResolvedVersion());
20✔
211
        // If offline and could not download, actualInstalledVersion will be the old version, not resolvedVersion
212
        // In that case, we need to recalculate the installation path for the actually installed version
213
        actualInstalledVersion = installed.getResolvedVersion();
3✔
214
        installationPath = getInstallationPath(edition, actualInstalledVersion);
6✔
215
      } else {
216
        // No existing installation available, re-throw the exception
217
        throw e;
2✔
218
      }
219
    }
1✔
220
    return createToolInstallation(installationPath, actualInstalledVersion, true, processContext, additionalInstallation);
8✔
221
  }
222

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

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

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

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

299
  /**
300
   * Installs the tool dependencies for the current tool.
301
   *
302
   * @param request the {@link ToolInstallRequest}.
303
   */
304
  protected void installToolDependencies(ToolInstallRequest request) {
305

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

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

326
  }
1✔
327

328
  @Override
329
  public VersionIdentifier getInstalledVersion() {
330

331
    return getInstalledVersion(getToolPath());
5✔
332
  }
333

334
  /**
335
   * @param toolPath the installation {@link Path} where to find the version file.
336
   * @return the currently installed {@link VersionIdentifier version} of this tool or {@code null} if not installed.
337
   */
338
  protected VersionIdentifier getInstalledVersion(Path toolPath) {
339

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

357
  @Override
358
  public String getInstalledEdition() {
359

360
    return getInstalledEdition(getToolPath());
5✔
361
  }
362

363
  /**
364
   * @param toolPath the installation {@link Path} where to find currently installed tool. The name of the parent directory of the real path corresponding
365
   *     to the passed {@link Path path} must be the name of the edition.
366
   * @return the installed edition of this tool or {@code null} if not installed.
367
   */
368
  protected String getInstalledEdition(Path toolPath) {
369
    if (isToolNotInstalled(toolPath)) {
4✔
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 (isToolNotInstalled(toolPath)) {
4!
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
  private boolean isToolNotInstalled(Path toolPath) {
458

459
    if ((toolPath == null) || !Files.isDirectory(toolPath)) {
7!
460
      this.context.debug("Tool {} not installed in {}", this.tool, toolPath);
15✔
461
      return true;
2✔
462
    }
463
    return false;
2✔
464
  }
465

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

489
  /**
490
   * Performs the actual uninstallation of this tool.
491
   *
492
   * @param toolPath the current {@link #getToolPath() tool path}.
493
   */
494
  protected void performUninstall(Path toolPath) {
495
    this.context.getFileAccess().delete(toolPath);
5✔
496
  }
1✔
497

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

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

528
  /**
529
   * @return {@link VersionIdentifier} with latest version of the tool}.
530
   */
531
  public VersionIdentifier getLatestToolVersion() {
532

533
    return this.context.getDefaultToolRepository().resolveVersion(this.tool, getConfiguredEdition(), VersionIdentifier.LATEST, this);
×
534
  }
535

536

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

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