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

devonfw / IDEasy / 20003978026

07 Dec 2025 12:09PM UTC coverage: 70.101% (+0.2%) from 69.903%
20003978026

push

github

web-flow
#39: refactoring to extract package-manager logic out of node/npm (#1638)

3892 of 6090 branches covered (63.91%)

Branch coverage included in aggregate %.

9955 of 13663 relevant lines covered (72.86%)

3.15 hits per line

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

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

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

143
    return false;
2✔
144
  }
145

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

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

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

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

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

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

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

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

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

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

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

302
  }
1✔
303

304
  @Override
305
  public VersionIdentifier getInstalledVersion() {
306

307
    return getInstalledVersion(getToolPath());
5✔
308
  }
309

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

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

333
  @Override
334
  public String getInstalledEdition() {
335

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

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

368
  private String getEdition(Path toolRepoFolder, Path toolInstallFolder) {
369

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

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

401
  Path getValidInstalledSoftwareRepoPath(Path installPath, Path softwareRepoPath) {
402
    int softwareRepoNameCount = softwareRepoPath.getNameCount();
3✔
403
    int toolInstallNameCount = installPath.getNameCount();
3✔
404
    int targetToolInstallNameCount = softwareRepoNameCount + 4;
4✔
405

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

433
  private boolean isToolNotInstalled(Path toolPath) {
434

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

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

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

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

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

504
  /**
505
   * @return {@link VersionIdentifier} with latest version of the tool}.
506
   */
507
  public VersionIdentifier getLatestToolVersion() {
508

509
    return this.context.getDefaultToolRepository().resolveVersion(this.tool, getConfiguredEdition(), VersionIdentifier.LATEST, this);
×
510
  }
511

512

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

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