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

devonfw / IDEasy / 20007338019

07 Dec 2025 04:50PM UTC coverage: 70.003% (-0.1%) from 70.101%
20007338019

push

github

web-flow
#39: pip commandlet (#1639)

Co-authored-by: Malte Brunnlieb <malte.brunnlieb@capgemini.com>
Co-authored-by: Malte Brunnlieb <maybeec@users.noreply.github.com>
Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>
Co-authored-by: jan-vcapgemini <jan-vincent.hoelzle@capgemini.com>

3909 of 6137 branches covered (63.7%)

Branch coverage included in aggregate %.

10030 of 13775 relevant lines covered (72.81%)

3.15 hits per line

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

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

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

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

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

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

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

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

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

69
    return false;
×
70
  }
71

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

78
  }
1✔
79

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

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

93
  private ToolInstallation doInstallStep(ToolInstallRequest request) {
94

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

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

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

145
    return false;
2✔
146
  }
147

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

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

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

174
    ProcessContext processContext = request.getProcessContext();
3✔
175
    boolean additionalInstallation = request.isAdditionalInstallation();
3✔
176
    boolean ignoreSoftwareRepo = isIgnoreSoftwareRepo();
3✔
177
    Path toolVersionFile = installationPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
178
    FileAccess fileAccess = this.context.getFileAccess();
4✔
179
    if (Files.isDirectory(installationPath)) {
5✔
180
      if (Files.exists(toolVersionFile)) {
5!
181
        if (!ignoreSoftwareRepo) {
2✔
182
          assert resolvedVersion.equals(getInstalledVersion(installationPath)) :
7!
183
              "Found version " + getInstalledVersion(installationPath) + " in " + toolVersionFile + " but expected " + resolvedVersion;
×
184
          this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, toolEdition, installationPath);
18✔
185
          return createToolInstallation(installationPath, resolvedVersion, false, processContext, additionalInstallation);
8✔
186
        }
187
      } else {
188
        // Makes sure that IDEasy will not delete itself
189
        if (this.tool.equals(IdeasyCommandlet.TOOL_NAME)) {
×
190
          this.context.warning("Your IDEasy installation is missing the version file at {}", toolVersionFile);
×
191
          return createToolInstallation(installationPath, resolvedVersion, false, processContext, additionalInstallation);
×
192
        } else if (!isIgnoreMissingSoftwareVersionFile()) {
×
193
          this.context.warning("Deleting corrupted installation at {}", installationPath);
×
194
          fileAccess.delete(installationPath);
×
195
        }
196
      }
197
    }
198
    performToolInstallation(request, installationPath);
4✔
199
    return createToolInstallation(installationPath, resolvedVersion, true, processContext, additionalInstallation);
8✔
200
  }
201

202
  /**
203
   * Performs the actual installation of the {@link #getName() tool} by downloading its binary, optionally extracting it, backing up any existing installation,
204
   * and writing the version file.
205
   * <p>
206
   * This method assumes that the version has already been resolved and dependencies installed. It handles the final steps of placing the tool into the
207
   * appropriate installation directory.
208
   *
209
   * @param request the {@link ToolInstallRequest}.
210
   * @param installationPath the target {@link Path} where the {@link #getName() tool} should be installed.
211
   */
212
  protected void performToolInstallation(ToolInstallRequest request, Path installationPath) {
213

214
    FileAccess fileAccess = this.context.getFileAccess();
4✔
215
    ToolEditionAndVersion requested = request.getRequested();
3✔
216
    VersionIdentifier resolvedVersion = requested.getResolvedVersion();
3✔
217
    Path downloadedToolFile = downloadTool(requested.getEdition().edition(), resolvedVersion);
7✔
218
    boolean extract = isExtract();
3✔
219
    if (!extract) {
2✔
220
      this.context.trace("Extraction is disabled for '{}' hence just moving the downloaded file {}.", this.tool, downloadedToolFile);
15✔
221
    }
222
    if (Files.isDirectory(installationPath)) {
5!
223
      if (this.tool.equals(IdeasyCommandlet.TOOL_NAME)) {
×
224
        this.context.warning("Your IDEasy installation is missing the version file.");
×
225
      } else {
226
        fileAccess.backup(installationPath);
×
227
      }
228
    }
229
    fileAccess.mkdirs(installationPath.getParent());
4✔
230
    fileAccess.extract(downloadedToolFile, installationPath, this::postExtract, extract);
7✔
231
    this.context.writeVersionFile(resolvedVersion, installationPath);
5✔
232
    this.context.debug("Installed {} in version {} at {}", this.tool, resolvedVersion, installationPath);
19✔
233
  }
1✔
234

235
  /**
236
   * @param edition the {@link #getConfiguredEdition() tool edition} to download.
237
   * @param resolvedVersion the resolved {@link VersionIdentifier version} to download.
238
   * @return the {@link Path} to the downloaded release file.
239
   */
240
  protected Path downloadTool(String edition, VersionIdentifier resolvedVersion) {
241
    return getToolRepository().download(this.tool, edition, resolvedVersion, this);
9✔
242
  }
243

244
  /**
245
   * Install this tool as dependency of another tool.
246
   *
247
   * @param versionRange the required {@link VersionRange}. See {@link ToolDependency#versionRange()}.
248
   * @param parentRequest the {@link ToolInstallRequest} of the tool causing this dependency.
249
   * @return the corresponding {@link ToolInstallation}.
250
   */
251
  public ToolInstallation installAsDependency(VersionRange versionRange, ToolInstallRequest parentRequest) {
252
    ToolInstallRequest request = new ToolInstallRequest(parentRequest);
5✔
253
    ToolEditionAndVersion requested = new ToolEditionAndVersion(getToolWithConfiguredEdition());
6✔
254
    request.setRequested(requested);
3✔
255
    VersionIdentifier configuredVersion = getConfiguredVersion();
3✔
256
    if (versionRange.contains(configuredVersion)) {
4✔
257
      // prefer configured version if contained in version range
258
      requested.setVersion(configuredVersion);
3✔
259
      // return install(true, configuredVersion, processContext, null);
260
      return install(request);
4✔
261
    } else {
262
      if (isIgnoreSoftwareRepo()) {
3!
263
        throw new IllegalStateException(
×
264
            "Cannot satisfy dependency to " + this.tool + " in version " + versionRange + " for " + parentRequest.getRequested()
×
265
                + " since it is conflicting with configured version "
266
                + configuredVersion
267
                + " and this tool does not support the software repository.");
268
      }
269
      this.context.info(
9✔
270
          "The tool {} requires {} in the version range {}, but your project uses version {}, which does not match."
271
              + " Therefore, we install a compatible version in that range.",
272
          parentRequest.getRequested().getEdition(), this.tool, versionRange, configuredVersion);
16✔
273
      requested.setVersion(versionRange);
3✔
274
      return installTool(request);
4✔
275
    }
276
  }
277

278
  /**
279
   * Installs the tool dependencies for the current tool.
280
   *
281
   * @param request the {@link ToolInstallRequest}.
282
   */
283
  protected void installToolDependencies(ToolInstallRequest request) {
284

285
    ToolEditionAndVersion requested = request.getRequested();
3✔
286
    VersionIdentifier version = requested.getResolvedVersion();
3✔
287
    ToolEdition toolEdition = requested.getEdition();
3✔
288
    Collection<ToolDependency> dependencies = getToolRepository().findDependencies(this.tool, toolEdition.edition(), version);
9✔
289
    int size = dependencies.size();
3✔
290
    this.context.debug("Tool {} has {} other tool(s) as dependency", toolEdition, size);
15✔
291
    for (ToolDependency dependency : dependencies) {
10✔
292
      this.context.trace("Ensuring dependency {} for tool {}", dependency.tool(), toolEdition);
15✔
293
      LocalToolCommandlet dependencyTool = this.context.getCommandletManager().getRequiredLocalToolCommandlet(dependency.tool());
7✔
294
      dependencyTool.installAsDependency(dependency.versionRange(), request);
6✔
295
    }
1✔
296
  }
1✔
297

298
  /**
299
   * Post-extraction hook that can be overridden to add custom processing after unpacking and before moving to the final destination folder.
300
   *
301
   * @param extractedDir the {@link Path} to the folder with the unpacked tool.
302
   */
303
  protected void postExtract(Path extractedDir) {
304

305
  }
1✔
306

307
  @Override
308
  public VersionIdentifier getInstalledVersion() {
309

310
    return getInstalledVersion(getToolPath());
5✔
311
  }
312

313
  /**
314
   * @param toolPath the installation {@link Path} where to find the version file.
315
   * @return the currently installed {@link VersionIdentifier version} of this tool or {@code null} if not installed.
316
   */
317
  protected VersionIdentifier getInstalledVersion(Path toolPath) {
318

319
    if (isToolNotInstalled(toolPath)) {
4✔
320
      return null;
2✔
321
    }
322
    Path toolVersionFile = toolPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
323
    if (!Files.exists(toolVersionFile)) {
5✔
324
      Path legacyToolVersionFile = toolPath.resolve(IdeContext.FILE_LEGACY_SOFTWARE_VERSION);
4✔
325
      if (Files.exists(legacyToolVersionFile)) {
5!
326
        toolVersionFile = legacyToolVersionFile;
3✔
327
      } else {
328
        this.context.warning("Tool {} is missing version file in {}", getName(), toolVersionFile);
×
329
        return null;
×
330
      }
331
    }
332
    String version = this.context.getFileAccess().readFileContent(toolVersionFile).trim();
7✔
333
    return VersionIdentifier.of(version);
3✔
334
  }
335

336
  @Override
337
  public String getInstalledEdition() {
338

339
    return getInstalledEdition(getToolPath());
5✔
340
  }
341

342
  /**
343
   * @param toolPath the installation {@link Path} where to find currently installed tool. The name of the parent directory of the real path corresponding
344
   *     to the passed {@link Path path} must be the name of the edition.
345
   * @return the installed edition of this tool or {@code null} if not installed.
346
   */
347
  private String getInstalledEdition(Path toolPath) {
348
    if (isToolNotInstalled(toolPath)) {
4✔
349
      return null;
2✔
350
    }
351
    Path realPath = this.context.getFileAccess().toRealPath(toolPath);
6✔
352
    // if the realPath changed, a link has been resolved
353
    if (realPath.equals(toolPath)) {
4✔
354
      if (!isIgnoreSoftwareRepo()) {
3✔
355
        this.context.warning("Tool {} is not installed via software repository (maybe from devonfw-ide). Please consider reinstalling it.", this.tool);
11✔
356
      }
357
      // 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
358
      return getConfiguredEdition();
3✔
359
    }
360
    Path toolRepoFolder = context.getSoftwareRepositoryPath().resolve(ToolRepository.ID_DEFAULT).resolve(this.tool);
9✔
361
    String edition = getEdition(toolRepoFolder, realPath);
5✔
362
    if (edition == null) {
2!
363
      edition = this.tool;
×
364
    }
365
    if (!getToolRepository().getSortedEditions(this.tool).contains(edition)) {
8✔
366
      this.context.warning("Undefined edition {} of tool {}", edition, this.tool);
15✔
367
    }
368
    return edition;
2✔
369
  }
370

371
  private String getEdition(Path toolRepoFolder, Path toolInstallFolder) {
372

373
    int toolRepoNameCount = toolRepoFolder.getNameCount();
3✔
374
    int toolInstallNameCount = toolInstallFolder.getNameCount();
3✔
375
    if (toolRepoNameCount < toolInstallNameCount) {
3!
376
      // ensure toolInstallFolder starts with $IDE_ROOT/_ide/software/default/«tool»
377
      for (int i = 0; i < toolRepoNameCount; i++) {
7✔
378
        if (!toolRepoFolder.getName(i).toString().equals(toolInstallFolder.getName(i).toString())) {
10!
379
          return null;
×
380
        }
381
      }
382
      return toolInstallFolder.getName(toolRepoNameCount).toString();
5✔
383
    }
384
    return null;
×
385
  }
386

387
  private Path getInstalledSoftwareRepoPath(Path toolPath) {
388
    if (isToolNotInstalled(toolPath)) {
4!
389
      return null;
×
390
    }
391
    Path installPath = this.context.getFileAccess().toRealPath(toolPath);
6✔
392
    // if the installPath changed, a link has been resolved
393
    if (installPath.equals(toolPath)) {
4!
394
      if (!isIgnoreSoftwareRepo()) {
×
395
        this.context.warning("Tool {} is not installed via software repository (maybe from devonfw-ide). Please consider reinstalling it.", this.tool);
×
396
      }
397
      // 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
398
      return null;
×
399
    }
400
    installPath = getValidInstalledSoftwareRepoPath(installPath, context.getSoftwareRepositoryPath());
7✔
401
    return installPath;
2✔
402
  }
403

404
  Path getValidInstalledSoftwareRepoPath(Path installPath, Path softwareRepoPath) {
405
    int softwareRepoNameCount = softwareRepoPath.getNameCount();
3✔
406
    int toolInstallNameCount = installPath.getNameCount();
3✔
407
    int targetToolInstallNameCount = softwareRepoNameCount + 4;
4✔
408

409
    // installPath can't be shorter than softwareRepoPath
410
    if (toolInstallNameCount < softwareRepoNameCount) {
3!
411
      this.context.warning("The installation path is not located within the software repository {}.", installPath);
×
412
      return null;
×
413
    }
414
    // ensure installPath starts with $IDE_ROOT/_ide/software/
415
    for (int i = 0; i < softwareRepoNameCount; i++) {
7✔
416
      if (!softwareRepoPath.getName(i).toString().equals(installPath.getName(i).toString())) {
10✔
417
        this.context.warning("The installation path is not located within the software repository {}.", installPath);
10✔
418
        return null;
2✔
419
      }
420
    }
421
    // return $IDE_ROOT/_ide/software/«id»/«tool»/«edition»/«version»
422
    if (toolInstallNameCount == targetToolInstallNameCount) {
3✔
423
      return installPath;
2✔
424
    } else if (toolInstallNameCount > targetToolInstallNameCount) {
3✔
425
      Path validInstallPath = installPath;
2✔
426
      for (int i = 0; i < toolInstallNameCount - targetToolInstallNameCount; i++) {
9✔
427
        validInstallPath = validInstallPath.getParent();
3✔
428
      }
429
      return validInstallPath;
2✔
430
    } else {
431
      this.context.warning("The installation path is faulty {}.", installPath);
10✔
432
      return null;
2✔
433
    }
434
  }
435

436
  private boolean isToolNotInstalled(Path toolPath) {
437

438
    if ((toolPath == null) || !Files.isDirectory(toolPath)) {
7!
439
      this.context.debug("Tool {} not installed in {}", this.tool, toolPath);
15✔
440
      return true;
2✔
441
    }
442
    return false;
2✔
443
  }
444

445
  @Override
446
  public void uninstall() {
447
    try {
448
      Path toolPath = getToolPath();
3✔
449
      if (!Files.exists(toolPath)) {
5!
450
        this.context.warning("An installed version of {} does not exist.", this.tool);
×
451
        return;
×
452
      }
453
      if (this.context.isForceMode() && !isIgnoreSoftwareRepo()) {
7!
454
        this.context.warning(
14✔
455
            "You triggered an uninstall of {} in version {} with force mode!\n"
456
                + "This will physically delete the currently installed version from the machine.\n"
457
                + "This may cause issues with other projects, that use the same version of that tool."
458
            , this.tool, getInstalledVersion());
2✔
459
        uninstallFromSoftwareRepository(toolPath);
3✔
460
      }
461
      performUninstall(toolPath);
3✔
462
      this.context.success("Successfully uninstalled {}", this.tool);
11✔
463
    } catch (Exception e) {
×
464
      this.context.error(e, "Failed to uninstall {}", this.tool);
×
465
    }
1✔
466
  }
1✔
467

468
  /**
469
   * Performs the actual uninstallation of this tool.
470
   *
471
   * @param toolPath the current {@link #getToolPath() tool path}.
472
   */
473
  protected void performUninstall(Path toolPath) {
474
    this.context.getFileAccess().delete(toolPath);
5✔
475
  }
1✔
476

477
  /**
478
   * Deletes the installed version of the tool from the shared software repository.
479
   */
480
  private void uninstallFromSoftwareRepository(Path toolPath) {
481
    Path repoPath = getInstalledSoftwareRepoPath(toolPath);
4✔
482
    if ((repoPath == null) || !Files.exists(repoPath)) {
7!
483
      this.context.warning("An installed version of {} does not exist in software repository.", this.tool);
×
484
      return;
×
485
    }
486
    this.context.info("Physically deleting {} as requested by the user via force mode.", repoPath);
10✔
487
    this.context.getFileAccess().delete(repoPath);
5✔
488
    this.context.success("Successfully deleted {} from your computer.", repoPath);
10✔
489
  }
1✔
490

491
  @Override
492
  protected Path getInstallationPath(String edition, VersionIdentifier resolvedVersion) {
493
    Path installationPath;
494
    if (isIgnoreSoftwareRepo()) {
3✔
495
      installationPath = getToolPath();
4✔
496
    } else {
497
      Path softwareRepositoryPath = this.context.getSoftwareRepositoryPath();
4✔
498
      if (softwareRepositoryPath == null) {
2✔
499
        return null;
2✔
500
      }
501
      Path softwareRepoPath = softwareRepositoryPath.resolve(getToolRepository().getId()).resolve(this.tool).resolve(edition);
11✔
502
      installationPath = softwareRepoPath.resolve(resolvedVersion.toString());
5✔
503
    }
504
    return installationPath;
2✔
505
  }
506

507
  /**
508
   * @return {@link VersionIdentifier} with latest version of the tool}.
509
   */
510
  public VersionIdentifier getLatestToolVersion() {
511

512
    return this.context.getDefaultToolRepository().resolveVersion(this.tool, getConfiguredEdition(), VersionIdentifier.LATEST, this);
×
513
  }
514

515

516
  /**
517
   * Searches for a wrapper file in valid projects (containing a build file f.e. build.gradle or pom.xml) and returns its path.
518
   *
519
   * @param wrapperFileName the name of the wrapper file
520
   * @return Path of the wrapper file or {@code null} if none was found.
521
   */
522
  protected Path findWrapper(String wrapperFileName) {
523
    Path dir = this.context.getCwd();
4✔
524
    // traverse the cwd directory containing a build descriptor up till a wrapper file was found
525
    while ((dir != null) && (findBuildDescriptor(dir) != null)) {
6!
526
      Path wrapper = dir.resolve(wrapperFileName);
4✔
527
      if (Files.exists(wrapper)) {
5✔
528
        context.debug("Using wrapper: {}", wrapper);
10✔
529
        return wrapper;
2✔
530
      }
531
      dir = dir.getParent();
3✔
532
    }
1✔
533
    return null;
2✔
534
  }
535

536
  /**
537
   * @param directory the {@link Path} to the build directory.
538
   * @return the build configuration file for this tool or {@code null} if not found (or this is not a build tool).
539
   */
540
  public Path findBuildDescriptor(Path directory) {
541
    return null;
2✔
542
  }
543
}
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