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

devonfw / IDEasy / 20271179405

16 Dec 2025 02:21PM UTC coverage: 70.061% (-0.08%) from 70.142%
20271179405

push

github

web-flow
#1660: status robustness #1475: fix tests to work offline (#1661)

3965 of 6233 branches covered (63.61%)

Branch coverage included in aggregate %.

10162 of 13931 relevant lines covered (72.95%)

3.15 hits per line

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

80.11
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
    if (request.isInstallLoop(this.context)) {
5!
159
      return toolAlreadyInstalled(request);
×
160
    }
161
    ToolEditionAndVersion requested = request.getRequested();
3✔
162
    ToolEdition toolEdition = requested.getEdition();
3✔
163
    assert (toolEdition.tool().equals(this.tool)) : "Mismatch " + this.tool + " != " + toolEdition.tool();
7!
164
    String edition = toolEdition.edition();
3✔
165
    VersionIdentifier resolvedVersion = cveCheck(request);
4✔
166
    installToolDependencies(request);
3✔
167

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

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

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

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

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

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

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

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

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

308
  }
1✔
309

310
  @Override
311
  public VersionIdentifier getInstalledVersion() {
312

313
    return getInstalledVersion(getToolPath());
5✔
314
  }
315

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

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

339
  @Override
340
  public String getInstalledEdition() {
341

342
    return getInstalledEdition(getToolPath());
5✔
343
  }
344

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

374
  private String getEdition(Path toolRepoFolder, Path toolInstallFolder) {
375

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

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

407
  Path getValidInstalledSoftwareRepoPath(Path installPath, Path softwareRepoPath) {
408
    int softwareRepoNameCount = softwareRepoPath.getNameCount();
3✔
409
    int toolInstallNameCount = installPath.getNameCount();
3✔
410
    int targetToolInstallNameCount = softwareRepoNameCount + 4;
4✔
411

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

439
  private boolean isToolNotInstalled(Path toolPath) {
440

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

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

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

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

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

510
  /**
511
   * @return {@link VersionIdentifier} with latest version of the tool}.
512
   */
513
  public VersionIdentifier getLatestToolVersion() {
514

515
    return this.context.getDefaultToolRepository().resolveVersion(this.tool, getConfiguredEdition(), VersionIdentifier.LATEST, this);
×
516
  }
517

518

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

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

© 2025 Coveralls, Inc