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

devonfw / IDEasy / 15143004567

20 May 2025 04:34PM UTC coverage: 67.719% (+0.02%) from 67.695%
15143004567

push

github

web-flow
#809: Enhance uninstall with --force to remove from the software repo (#1242)

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

3121 of 5016 branches covered (62.22%)

Branch coverage included in aggregate %.

8016 of 11430 relevant lines covered (70.13%)

3.07 hits per line

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

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

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

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

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

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

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

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

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

69
  }
1✔
70

71
  @Override
72
  public boolean install(boolean silent, ProcessContext processContext) {
73

74
    installDependencies();
2✔
75
    VersionIdentifier configuredVersion = getConfiguredVersion();
3✔
76
    // get installed version before installInRepo actually may install the software
77
    VersionIdentifier installedVersion = getInstalledVersion();
3✔
78
    Step step = this.context.newStep(silent, "Install " + this.tool, configuredVersion);
14✔
79
    try {
80
      // install configured version of our tool in the software repository if not already installed
81
      ToolInstallation installation = installTool(configuredVersion, processContext);
5✔
82

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

114
  }
115

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

125
    if (newlyInstalled) {
2✔
126
      postInstall();
2✔
127
    }
128
  }
1✔
129

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

135
    // nothing to do by default
136
  }
1✔
137

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

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

155
    return false;
2✔
156
  }
157

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

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

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

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

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

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

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

251
    VersionIdentifier configuredVersion = getConfiguredVersion();
3✔
252
    if (version.contains(configuredVersion)) {
4✔
253
      // prefer configured version if contained in version range
254
      return install(false, processContext);
5✔
255
    } else {
256
      if (isIgnoreSoftwareRepo()) {
3!
257
        throw new IllegalStateException(
×
258
            "Cannot satisfy dependency to " + this.tool + " in version " + version + " since it is conflicting with configured version " + configuredVersion
259
                + " and this tool does not support the software repository.");
260
      }
261
      this.context.info(
23✔
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
          toolParent, this.tool, version, configuredVersion);
265
    }
266
    ToolInstallation toolInstallation = installTool(version, processContext);
5✔
267
    return toolInstallation.newInstallation();
3✔
268
  }
269

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

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

289
  }
1✔
290

291
  @Override
292
  public VersionIdentifier getInstalledVersion() {
293

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

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

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

321
  @Override
322
  public String getInstalledEdition() {
323

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

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

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

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

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

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

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

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

472

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

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

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

502
    String pathVariable = EnvironmentVariables.getToolVariablePrefix(this.tool) + "_HOME";
5✔
503
    environmentContext.withEnvVar(pathVariable, toolInstallation.linkDir().toString());
7✔
504
    if (extraInstallation) {
2✔
505
      environmentContext.withPathEntry(toolInstallation.binDir());
5✔
506
    }
507
  }
1✔
508

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

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

517

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