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

devonfw / IDEasy / 19789527581

29 Nov 2025 09:25PM UTC coverage: 69.431% (-0.06%) from 69.489%
19789527581

push

github

web-flow
#1615: prevent to ask CVE questions if tool already installed (#1618)

3696 of 5853 branches covered (63.15%)

Branch coverage included in aggregate %.

9618 of 13323 relevant lines covered (72.19%)

3.14 hits per line

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

80.83
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
import java.util.function.Predicate;
9

10
import com.devonfw.tools.ide.common.Tag;
11
import com.devonfw.tools.ide.context.IdeContext;
12
import com.devonfw.tools.ide.io.FileAccess;
13
import com.devonfw.tools.ide.process.ProcessContext;
14
import com.devonfw.tools.ide.step.Step;
15
import com.devonfw.tools.ide.tool.repository.ToolRepository;
16
import com.devonfw.tools.ide.url.model.file.json.ToolDependency;
17
import com.devonfw.tools.ide.version.GenericVersionRange;
18
import com.devonfw.tools.ide.version.VersionIdentifier;
19
import com.devonfw.tools.ide.version.VersionRange;
20

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

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

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

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

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

53
    Path toolPath = getToolPath();
3✔
54
    Path binPath = this.context.getFileAccess().findFirst(toolPath, path -> path.getFileName().toString().equals("bin"), false);
14✔
55
    if ((binPath != null) && Files.isDirectory(binPath)) {
7!
56
      return binPath;
2✔
57
    }
58
    return toolPath;
2✔
59
  }
60

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

67
    return false;
×
68
  }
69

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

76
  }
1✔
77

78
  @Override
79
  protected ToolInstallation doInstall(ToolInstallRequest request) {
80

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

91
  private ToolInstallation doInstallStep(ToolInstallRequest request) {
92

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

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

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

141
    return false;
2✔
142
  }
143

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

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

161
    // cveCheck might have changed resolvedVersion so let us re-check...
162
    if (request.isAlreadyInstalled()) {
3✔
163
      return toolAlreadyInstalled(request);
4✔
164
    }
165
    Path installationPath = getInstallationPath(edition, resolvedVersion);
5✔
166

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

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

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

228
  /**
229
   * @param edition the {@link #getConfiguredEdition() tool edition} to download.
230
   * @param resolvedVersion the resolved {@link VersionIdentifier version} to download.
231
   * @return the {@link Path} to the downloaded release file.
232
   */
233
  protected Path downloadTool(String edition, VersionIdentifier resolvedVersion) {
234
    return getToolRepository().download(this.tool, edition, resolvedVersion, this);
9✔
235
  }
236

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

270
  /**
271
   * Installs the tool dependencies for the current tool.
272
   *
273
   * @param request the {@link ToolInstallRequest}.
274
   */
275
  protected void installToolDependencies(ToolInstallRequest request) {
276

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

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

297
  }
1✔
298

299
  @Override
300
  public VersionIdentifier getInstalledVersion() {
301

302
    return getInstalledVersion(getToolPath());
5✔
303
  }
304

305
  /**
306
   * @param toolPath the installation {@link Path} where to find the version file.
307
   * @return the currently installed {@link VersionIdentifier version} of this tool or {@code null} if not installed.
308
   */
309
  protected VersionIdentifier getInstalledVersion(Path toolPath) {
310

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

328
  @Override
329
  public String getInstalledEdition() {
330

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

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

363
  private String getEdition(Path toolRepoFolder, Path toolInstallFolder) {
364

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

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

396
  Path getValidInstalledSoftwareRepoPath(Path installPath, Path softwareRepoPath) {
397
    int softwareRepoNameCount = softwareRepoPath.getNameCount();
3✔
398
    int toolInstallNameCount = installPath.getNameCount();
3✔
399
    int targetToolInstallNameCount = softwareRepoNameCount + 4;
4✔
400

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

428
  private boolean isToolNotInstalled(Path toolPath) {
429

430
    if ((toolPath == null) || !Files.isDirectory(toolPath)) {
7!
431
      this.context.debug("Tool {} not installed in {}", this.tool, toolPath);
15✔
432
      return true;
2✔
433
    }
434
    return false;
2✔
435
  }
436

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

460
  /**
461
   * Performs the actual uninstallation of this tool.
462
   *
463
   * @param toolPath the current {@link #getToolPath() tool path}.
464
   */
465
  protected void performUninstall(Path toolPath) {
466
    this.context.getFileAccess().delete(toolPath);
5✔
467
  }
1✔
468

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

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

499
  /**
500
   * @return {@link VersionIdentifier} with latest version of the tool}.
501
   */
502
  public VersionIdentifier getLatestToolVersion() {
503

504
    return this.context.getDefaultToolRepository().resolveVersion(this.tool, getConfiguredEdition(), VersionIdentifier.LATEST, this);
×
505
  }
506

507

508
  /**
509
   * Searches for a wrapper file in valid projects (containing a build file f.e. build.gradle or pom.xml) and returns its path.
510
   *
511
   * @param wrapperFileName the name of the wrapper file
512
   * @param filter the {@link Predicate} to match
513
   * @return Path of the wrapper file or {@code null} if none was found.
514
   */
515
  protected Path findWrapper(String wrapperFileName, Predicate<Path> filter) {
516
    Path dir = context.getCwd();
4✔
517
    // traverse the cwd directory containing a build file up till a wrapper file was found
518
    while ((dir != null) && filter.test(dir)) {
6!
519
      if (Files.exists(dir.resolve(wrapperFileName))) {
7✔
520
        context.debug("Using wrapper file at: {}", dir);
10✔
521
        return dir.resolve(wrapperFileName);
4✔
522
      }
523
      dir = dir.getParent();
4✔
524
    }
525
    return null;
2✔
526
  }
527

528

529
}
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