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

devonfw / IDEasy / 15905732892

26 Jun 2025 03:14PM UTC coverage: 67.757% (-0.01%) from 67.767%
15905732892

push

github

web-flow
#1372: Add gradle wrapper support (#1388)

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

3187 of 5112 branches covered (62.34%)

Branch coverage included in aggregate %.

8169 of 11648 relevant lines covered (70.13%)

3.08 hits per line

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

82.82
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.environment.EnvironmentVariables;
13
import com.devonfw.tools.ide.io.FileAccess;
14
import com.devonfw.tools.ide.io.FileCopyMode;
15
import com.devonfw.tools.ide.process.EnvironmentContext;
16
import com.devonfw.tools.ide.process.ProcessContext;
17
import com.devonfw.tools.ide.step.Step;
18
import com.devonfw.tools.ide.tool.repository.ToolRepository;
19
import com.devonfw.tools.ide.url.model.file.json.ToolDependency;
20
import com.devonfw.tools.ide.version.GenericVersionRange;
21
import com.devonfw.tools.ide.version.VersionIdentifier;
22
import com.devonfw.tools.ide.version.VersionRange;
23

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

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

38
    super(context, tool, tags);
5✔
39
  }
1✔
40

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

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

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

64
  /**
65
   * @deprecated will be removed once all "dependencies.json" are created in ide-urls.
66
   */
67
  @Deprecated
68
  protected void installDependencies() {
69

70
  }
1✔
71

72
  @Override
73
  public boolean install(boolean silent, ProcessContext processContext, Step step) {
74

75
    installDependencies();
2✔
76
    VersionIdentifier configuredVersion = getConfiguredVersion();
3✔
77
    // get installed version before installInRepo actually may install the software
78
    VersionIdentifier installedVersion = getInstalledVersion();
3✔
79
    if (step == null) {
2!
80
      return doInstallStep(configuredVersion, installedVersion, silent, processContext, step);
8✔
81
    } else {
82
      return step.call(() -> doInstallStep(configuredVersion, installedVersion, silent, processContext, step), Boolean.FALSE);
×
83
    }
84
  }
85

86
  private boolean doInstallStep(VersionIdentifier configuredVersion, VersionIdentifier installedVersion, boolean silent, ProcessContext processContext,
87
      Step step) {
88

89
    // install configured version of our tool in the software repository if not already installed
90
    ToolInstallation installation = installTool(configuredVersion, processContext);
5✔
91

92
    // check if we already have this version installed (linked) locally in IDE_HOME/software
93
    VersionIdentifier resolvedVersion = installation.resolvedVersion();
3✔
94
    if ((resolvedVersion.equals(installedVersion) && !installation.newInstallation())
9✔
95
        || (configuredVersion.matches(installedVersion) && context.isSkipUpdatesMode())) {
6!
96
      return toolAlreadyInstalled(silent, installedVersion, processContext);
6✔
97
    }
98
    if (!isIgnoreSoftwareRepo()) {
3✔
99
      // we need to link the version or update the link.
100
      Path toolPath = getToolPath();
3✔
101
      FileAccess fileAccess = this.context.getFileAccess();
4✔
102
      if (Files.exists(toolPath, LinkOption.NOFOLLOW_LINKS)) {
9✔
103
        fileAccess.backup(toolPath);
4✔
104
      }
105
      fileAccess.mkdirs(toolPath.getParent());
4✔
106
      fileAccess.symlink(installation.linkDir(), toolPath);
5✔
107
    }
108
    this.context.getPath().setPath(this.tool, installation.binDir());
8✔
109
    postInstall(true, processContext);
4✔
110
    if (installedVersion == null) {
2✔
111
      asSuccess(step).log("Successfully installed {} in version {}", this.tool, resolvedVersion);
18✔
112
    } else {
113
      asSuccess(step).log("Successfully installed {} in version {} replacing previous version {}", this.tool, resolvedVersion, installedVersion);
21✔
114
    }
115
    return true;
2✔
116
  }
117

118
  /**
119
   * This method is called after a tool was requested to be installed or updated.
120
   *
121
   * @param newlyInstalled {@code true} if the tool was installed or updated (at least link to software folder was created/updated), {@code false} otherwise
122
   *     (configured version was already installed and nothing changed).
123
   * @param pc the {@link ProcessContext} to use.
124
   */
125
  protected void postInstall(boolean newlyInstalled, ProcessContext pc) {
126

127
    if (newlyInstalled) {
2✔
128
      postInstall();
2✔
129
    }
130
  }
1✔
131

132
  /**
133
   * This method is called after the tool has been newly installed or updated to a new version.
134
   */
135
  protected void postInstall() {
136

137
    // nothing to do by default
138
  }
1✔
139

140
  private boolean toolAlreadyInstalled(boolean silent, VersionIdentifier installedVersion, ProcessContext pc) {
141
    if (!silent) {
2✔
142
      this.context.info("Version {} of tool {} is already installed", installedVersion, getToolWithEdition());
15✔
143
    }
144
    postInstall(false, pc);
4✔
145
    return false;
2✔
146
  }
147

148
  /**
149
   * Determines whether this tool should be installed directly in the software folder or in the software repository.
150
   *
151
   * @return {@code true} if the tool should be installed directly in the software folder, ignoring the central software repository; {@code false} if the tool
152
   *     should be installed in the central software repository (default behavior).
153
   */
154
  protected boolean isIgnoreSoftwareRepo() {
155

156
    return false;
2✔
157
  }
158

159
  /**
160
   * Performs the installation of the {@link #getName() tool} together with the environment context, managed by this
161
   * {@link com.devonfw.tools.ide.commandlet.Commandlet}.
162
   *
163
   * @param version the {@link GenericVersionRange} requested to be installed.
164
   * @param processContext the {@link ProcessContext} used to
165
   *     {@link #setEnvironment(EnvironmentContext, ToolInstallation, boolean) configure environment variables}.
166
   * @return the {@link ToolInstallation} matching the given {@code version}.
167
   */
168
  public ToolInstallation installTool(GenericVersionRange version, ProcessContext processContext) {
169

170
    return installTool(version, processContext, getConfiguredEdition());
7✔
171
  }
172

173
  /**
174
   * Performs the installation of the {@link #getName() tool} together with the environment context  managed by this
175
   * {@link com.devonfw.tools.ide.commandlet.Commandlet}.
176
   *
177
   * @param version the {@link GenericVersionRange} requested to be installed.
178
   * @param processContext the {@link ProcessContext} used to
179
   *     {@link #setEnvironment(EnvironmentContext, ToolInstallation, boolean) configure environment variables}.
180
   * @param edition the specific {@link #getConfiguredEdition() edition} to install.
181
   * @return the {@link ToolInstallation} matching the given {@code version}.
182
   */
183
  public ToolInstallation installTool(GenericVersionRange version, ProcessContext processContext, String edition) {
184

185
    // if version is a VersionRange, we are not called from install() but directly from installAsDependency() due to a version conflict of a dependency
186
    boolean extraInstallation = (version instanceof VersionRange);
3✔
187
    ToolRepository toolRepository = getToolRepository();
3✔
188
    VersionIdentifier resolvedVersion = toolRepository.resolveVersion(this.tool, edition, version, this);
8✔
189
    installToolDependencies(resolvedVersion, edition, processContext);
5✔
190

191
    Path installationPath;
192
    boolean ignoreSoftwareRepo = isIgnoreSoftwareRepo();
3✔
193
    if (ignoreSoftwareRepo) {
2✔
194
      installationPath = getToolPath();
4✔
195
    } else {
196
      Path softwareRepoPath = this.context.getSoftwareRepositoryPath().resolve(toolRepository.getId()).resolve(this.tool).resolve(edition);
12✔
197
      installationPath = softwareRepoPath.resolve(resolvedVersion.toString());
5✔
198
    }
199
    Path toolVersionFile = installationPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
200
    FileAccess fileAccess = this.context.getFileAccess();
4✔
201
    if (Files.isDirectory(installationPath)) {
5✔
202
      if (Files.exists(toolVersionFile)) {
5!
203
        if (!ignoreSoftwareRepo || resolvedVersion.equals(getInstalledVersion())) {
2!
204
          this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, getToolWithEdition(this.tool, edition), installationPath);
21✔
205
          return createToolInstallation(installationPath, resolvedVersion, toolVersionFile, false, processContext, extraInstallation);
9✔
206
        }
207
      } else {
208
        // Makes sure that IDEasy will not delete itself
209
        if (this.tool.equals(IdeasyCommandlet.TOOL_NAME)) {
×
210
          this.context.warning("Your IDEasy installation is missing the version file at {}", toolVersionFile);
×
211
        } else {
212
          this.context.warning("Deleting corrupted installation at {}", installationPath);
×
213
          fileAccess.delete(installationPath);
×
214
        }
215
      }
216
    }
217
    Path downloadedToolFile = downloadTool(edition, toolRepository, resolvedVersion);
6✔
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.exists(installationPath)) {
5!
223
      fileAccess.backup(installationPath);
×
224
    }
225
    fileAccess.mkdirs(installationPath.getParent());
4✔
226
    fileAccess.extract(downloadedToolFile, installationPath, this::postExtract, extract);
7✔
227
    this.context.writeVersionFile(resolvedVersion, installationPath);
5✔
228
    this.context.debug("Installed {} in version {} at {}", this.tool, resolvedVersion, installationPath);
19✔
229
    return createToolInstallation(installationPath, resolvedVersion, toolVersionFile, true, processContext, extraInstallation);
9✔
230
  }
231

232
  /**
233
   * @param edition the {@link #getConfiguredEdition() tool edition} to download.
234
   * @param toolRepository the {@link ToolRepository} to use.
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, ToolRepository toolRepository, VersionIdentifier resolvedVersion) {
239
    return toolRepository.download(this.tool, edition, resolvedVersion, this);
8✔
240
  }
241

242
  /**
243
   * Install this tool as dependency of another tool.
244
   *
245
   * @param version the required {@link VersionRange}. See {@link ToolDependency#versionRange()}.
246
   * @param processContext the {@link ProcessContext}.
247
   * @param toolParent the parent tool name needing the dependency
248
   * @return {@code true} if the tool was newly installed, {@code false} otherwise (installation was already present).
249
   */
250
  public boolean installAsDependency(VersionRange version, ProcessContext processContext, String toolParent) {
251

252
    VersionIdentifier configuredVersion = getConfiguredVersion();
3✔
253
    if (version.contains(configuredVersion)) {
4✔
254
      // prefer configured version if contained in version range
255
      return install(false, processContext, null);
6✔
256
    } else {
257
      if (isIgnoreSoftwareRepo()) {
3!
258
        throw new IllegalStateException(
×
259
            "Cannot satisfy dependency to " + this.tool + " in version " + version + " since it is conflicting with configured version " + configuredVersion
260
                + " and this tool does not support the software repository.");
261
      }
262
      this.context.info(
23✔
263
          "The tool {} requires {} in the version range {}, but your project uses version {}, which does not match."
264
              + " Therefore, we install a compatible version in that range.",
265
          toolParent, this.tool, version, configuredVersion);
266
    }
267
    ToolInstallation toolInstallation = installTool(version, processContext);
5✔
268
    return toolInstallation.newInstallation();
3✔
269
  }
270

271
  private void installToolDependencies(VersionIdentifier version, String edition, ProcessContext processContext) {
272
    Collection<ToolDependency> dependencies = getToolRepository().findDependencies(this.tool, edition, version);
8✔
273
    String toolWithEdition = getToolWithEdition(this.tool, edition);
5✔
274
    int size = dependencies.size();
3✔
275
    this.context.debug("Tool {} has {} other tool(s) as dependency", toolWithEdition, size);
15✔
276
    for (ToolDependency dependency : dependencies) {
10✔
277
      this.context.trace("Ensuring dependency {} for tool {}", dependency.tool(), toolWithEdition);
15✔
278
      LocalToolCommandlet dependencyTool = this.context.getCommandletManager().getRequiredLocalToolCommandlet(dependency.tool());
7✔
279
      dependencyTool.installAsDependency(dependency.versionRange(), processContext, toolWithEdition);
7✔
280
    }
1✔
281
  }
1✔
282

283
  /**
284
   * Post-extraction hook that can be overridden to add custom processing after unpacking and before moving to the final destination folder.
285
   *
286
   * @param extractedDir the {@link Path} to the folder with the unpacked tool.
287
   */
288
  protected void postExtract(Path extractedDir) {
289

290
  }
1✔
291

292
  @Override
293
  public VersionIdentifier getInstalledVersion() {
294

295
    return getInstalledVersion(this.context.getSoftwarePath().resolve(getName()));
9✔
296
  }
297

298
  /**
299
   * @param toolPath the installation {@link Path} where to find the version file.
300
   * @return the currently installed {@link VersionIdentifier version} of this tool or {@code null} if not installed.
301
   */
302
  protected VersionIdentifier getInstalledVersion(Path toolPath) {
303

304
    if (!Files.isDirectory(toolPath)) {
5✔
305
      this.context.debug("Tool {} not installed in {}", getName(), toolPath);
15✔
306
      return null;
2✔
307
    }
308
    Path toolVersionFile = toolPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
309
    if (!Files.exists(toolVersionFile)) {
5✔
310
      Path legacyToolVersionFile = toolPath.resolve(IdeContext.FILE_LEGACY_SOFTWARE_VERSION);
4✔
311
      if (Files.exists(legacyToolVersionFile)) {
5✔
312
        toolVersionFile = legacyToolVersionFile;
3✔
313
      } else {
314
        this.context.warning("Tool {} is missing version file in {}", getName(), toolVersionFile);
15✔
315
        return null;
2✔
316
      }
317
    }
318
    String version = this.context.getFileAccess().readFileContent(toolVersionFile).trim();
7✔
319
    return VersionIdentifier.of(version);
3✔
320
  }
321

322
  @Override
323
  public String getInstalledEdition() {
324

325
    if (this.context.getSoftwarePath() == null) {
4!
326
      return "";
×
327
    }
328
    return getInstalledEdition(this.context.getSoftwarePath().resolve(this.tool));
9✔
329
  }
330

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

358
  private String getEdition(Path toolRepoFolder, Path toolInstallFolder) {
359

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

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

392
  Path getValidInstalledSoftwareRepoPath(Path installPath, Path softwareRepoPath) {
393
    int softwareRepoNameCount = softwareRepoPath.getNameCount();
3✔
394
    int toolInstallNameCount = installPath.getNameCount();
3✔
395
    int targetToolInstallNameCount = softwareRepoNameCount + 4;
4✔
396

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

424
  @Override
425
  public void uninstall() {
426
    try {
427
      Path toolPath = getToolPath();
3✔
428
      if (!Files.exists(toolPath)) {
5!
429
        this.context.warning("An installed version of " + this.tool + " does not exist.");
×
430
        return;
×
431
      }
432
      if (this.context.isForceMode()) {
4✔
433
        this.context.warning(
10✔
434
            "Sub-command uninstall via force mode will physically delete the currently installed version of " + this.tool + " from the machine.\n"
435
                + "This may cause issues with other projects, that use the same version of " + this.tool + ".\n"
436
                + "Deleting " + this.tool + " version " + getInstalledVersion() + " from your machine.");
3✔
437
        uninstallFromSoftwareRepository(toolPath);
3✔
438
      }
439
      try {
440
        this.context.getFileAccess().delete(toolPath);
5✔
441
        this.context.success("Successfully uninstalled " + this.tool);
6✔
442
      } catch (Exception e) {
×
443
        this.context.error("Couldn't uninstall " + this.tool + ". ", e);
×
444
      }
1✔
445
    } catch (Exception e) {
×
446
      this.context.error(e.getMessage(), e);
×
447
    }
1✔
448
  }
1✔
449

450
  /**
451
   * Deletes the installed version of the tool from the shared software repository.
452
   */
453
  private void uninstallFromSoftwareRepository(Path toolPath) {
454
    try {
455
      Path repoPath = getInstalledSoftwareRepoPath(toolPath);
4✔
456
      if (!Files.exists(repoPath)) {
5!
457
        this.context.warning("An installed version of " + this.tool + " does not exist.");
×
458
        return;
×
459
      }
460
      this.context.info("Physically deleting " + repoPath + " as requested by the user via force mode.");
6✔
461
      try {
462
        this.context.getFileAccess().delete(repoPath);
5✔
463
        this.context.success("Successfully deleted " + repoPath + " from your computer.");
6✔
464
      } catch (Exception e) {
×
465
        this.context.error("Couldn't delete " + this.tool + " from your computer.", e);
×
466
      }
1✔
467
    } catch (Exception e) {
×
468
      throw new IllegalStateException(
×
469
          " Couldn't uninstall " + this.tool + ". Couldn't determine the software repository path for " + this.tool + ".", e);
470
    }
1✔
471
  }
1✔
472

473

474
  private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier resolvedVersion, Path toolVersionFile,
475
      boolean newInstallation, EnvironmentContext environmentContext, boolean extraInstallation) {
476

477
    Path linkDir = getMacOsHelper().findLinkDir(rootDir, getBinaryName());
7✔
478
    Path binDir = linkDir;
2✔
479
    Path binFolder = binDir.resolve(IdeContext.FOLDER_BIN);
4✔
480
    if (Files.isDirectory(binFolder)) {
5✔
481
      binDir = binFolder;
2✔
482
    }
483
    if (linkDir != rootDir) {
3✔
484
      assert (!linkDir.equals(rootDir));
5!
485
      this.context.getFileAccess().copy(toolVersionFile, linkDir, FileCopyMode.COPY_FILE_OVERRIDE);
7✔
486
    }
487
    ToolInstallation toolInstallation = new ToolInstallation(rootDir, linkDir, binDir, resolvedVersion, newInstallation);
9✔
488
    setEnvironment(environmentContext, toolInstallation, extraInstallation);
5✔
489
    return toolInstallation;
2✔
490
  }
491

492
  /**
493
   * Method to set environment variables for the process context.
494
   *
495
   * @param environmentContext the {@link EnvironmentContext} where to {@link EnvironmentContext#withEnvVar(String, String) set environment variables} for
496
   *     this tool.
497
   * @param toolInstallation the {@link ToolInstallation}.
498
   * @param extraInstallation {@code true} if the {@link ToolInstallation} is an additional installation to the
499
   *     {@link #getConfiguredVersion() configured version} due to a conflicting version of a {@link ToolDependency}, {@code false} otherwise.
500
   */
501
  public void setEnvironment(EnvironmentContext environmentContext, ToolInstallation toolInstallation, boolean extraInstallation) {
502

503
    String pathVariable = EnvironmentVariables.getToolVariablePrefix(this.tool) + "_HOME";
5✔
504
    environmentContext.withEnvVar(pathVariable, toolInstallation.linkDir().toString());
7✔
505
    if (extraInstallation) {
2✔
506
      environmentContext.withPathEntry(toolInstallation.binDir());
5✔
507
    }
508
  }
1✔
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
   * @param filter the {@link Predicate} to match
524
   * @return Path of the wrapper file or {@code null} if none was found.
525
   */
526
  protected Path findWrapper(String wrapperFileName, Predicate<Path> filter) {
527
    Path dir = context.getCwd();
4✔
528
    // traverse the cwd directory containing a build file up till a wrapper file was found
529
    while ((dir != null) && filter.test(dir)) {
6!
530
      if (Files.exists(dir.resolve(wrapperFileName))) {
7✔
531
        context.debug("Using wrapper file at: {}", dir);
10✔
532
        return dir.resolve(wrapperFileName);
4✔
533
      }
534
      dir = dir.getParent();
4✔
535
    }
536
    return null;
2✔
537
  }
538

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