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

devonfw / IDEasy / 17759244918

16 Sep 2025 08:12AM UTC coverage: 68.69% (+0.1%) from 68.56%
17759244918

push

github

web-flow
#1454: added NpmBasedCommandlet, refactored/simplified installation (#1488)

3420 of 5441 branches covered (62.86%)

Branch coverage included in aggregate %.

8905 of 12502 relevant lines covered (71.23%)

3.13 hits per line

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

86.59
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.log.IdeSubLogger;
16
import com.devonfw.tools.ide.process.EnvironmentContext;
17
import com.devonfw.tools.ide.process.ProcessContext;
18
import com.devonfw.tools.ide.step.Step;
19
import com.devonfw.tools.ide.tool.repository.ToolRepository;
20
import com.devonfw.tools.ide.url.model.file.json.ToolDependency;
21
import com.devonfw.tools.ide.version.GenericVersionRange;
22
import com.devonfw.tools.ide.version.VersionIdentifier;
23
import com.devonfw.tools.ide.version.VersionRange;
24

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

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

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

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

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

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

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

71
  }
1✔
72

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

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

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

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

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

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

131
    if (newlyInstalled) {
2✔
132
      postInstall();
2✔
133
    }
134
  }
1✔
135

136
  /**
137
   * This method is called after the tool has been newly installed or updated to a new version.
138
   */
139
  protected void postInstall() {
140

141
    // nothing to do by default
142
  }
1✔
143

144
  private boolean toolAlreadyInstalled(boolean silent, VersionIdentifier installedVersion, ProcessContext pc) {
145
    IdeSubLogger logger;
146
    if (silent) {
2✔
147
      logger = this.context.debug();
5✔
148
    } else {
149
      logger = this.context.info();
4✔
150
    }
151
    logger.log("Version {} of tool {} is already installed", installedVersion, getToolWithEdition());
15✔
152
    postInstall(false, pc);
4✔
153
    return false;
2✔
154
  }
155

156
  /**
157
   * Determines whether this tool should be installed directly in the software folder or in the software repository.
158
   *
159
   * @return {@code true} if the tool should be installed directly in the software folder, ignoring the central software repository; {@code false} if the tool
160
   *     should be installed in the central software repository (default behavior).
161
   */
162
  protected boolean isIgnoreSoftwareRepo() {
163

164
    return false;
2✔
165
  }
166

167
  /**
168
   * Performs the installation of the {@link #getName() tool} together with the environment context, managed by this
169
   * {@link com.devonfw.tools.ide.commandlet.Commandlet}.
170
   *
171
   * @param version the {@link GenericVersionRange} requested to be installed.
172
   * @param processContext the {@link ProcessContext} used to
173
   *     {@link #setEnvironment(EnvironmentContext, ToolInstallation, boolean) configure environment variables}.
174
   * @return the {@link ToolInstallation} matching the given {@code version}.
175
   */
176
  public ToolInstallation installTool(GenericVersionRange version, ProcessContext processContext) {
177

178
    return installTool(version, processContext, getConfiguredEdition());
7✔
179
  }
180

181
  /**
182
   * Performs the installation of the {@link #getName() tool} together with the environment context  managed by this
183
   * {@link com.devonfw.tools.ide.commandlet.Commandlet}.
184
   *
185
   * @param version the {@link GenericVersionRange} requested to be installed.
186
   * @param processContext the {@link ProcessContext} used to
187
   *     {@link #setEnvironment(EnvironmentContext, ToolInstallation, boolean) configure environment variables}.
188
   * @param edition the specific {@link #getConfiguredEdition() edition} to install.
189
   * @return the {@link ToolInstallation} matching the given {@code version}.
190
   */
191
  public ToolInstallation installTool(GenericVersionRange version, ProcessContext processContext, String edition) {
192

193
    // if version is a VersionRange, we are not called from install() but directly from installAsDependency() due to a version conflict of a dependency
194
    boolean extraInstallation = (version instanceof VersionRange);
3✔
195
    ToolRepository toolRepository = getToolRepository();
3✔
196
    VersionIdentifier resolvedVersion = toolRepository.resolveVersion(this.tool, edition, version, this);
8✔
197
    installToolDependencies(resolvedVersion, edition, processContext);
5✔
198

199
    Path installationPath;
200
    boolean ignoreSoftwareRepo = isIgnoreSoftwareRepo();
3✔
201
    if (ignoreSoftwareRepo) {
2✔
202
      installationPath = getToolPath();
4✔
203
    } else {
204
      Path softwareRepoPath = this.context.getSoftwareRepositoryPath().resolve(toolRepository.getId()).resolve(this.tool).resolve(edition);
12✔
205
      installationPath = softwareRepoPath.resolve(resolvedVersion.toString());
5✔
206
    }
207
    VersionIdentifier installedVersion = getInstalledVersion();
3✔
208
    String installedEdition = getInstalledEdition();
3✔
209
    if (resolvedVersion.equals(installedVersion) && edition.equals(installedEdition)) {
8✔
210
      this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, getToolWithEdition(this.tool, edition), installationPath);
21✔
211
      return createToolInstallation(installationPath, resolvedVersion, false, processContext, extraInstallation);
8✔
212
    }
213
    performToolInstallation(toolRepository, resolvedVersion, installationPath, edition, processContext);
7✔
214
    return createToolInstallation(installationPath, resolvedVersion, true, processContext, extraInstallation);
8✔
215
  }
216

217
  /**
218
   * Performs the actual installation of the {@link #getName() tool} by downloading its binary, optionally extracting it, backing up any existing installation,
219
   * and writing the version file.
220
   * <p>
221
   * This method assumes that the version has already been resolved and dependencies installed. It handles the final steps of placing the tool into the
222
   * appropriate installation directory.
223
   *
224
   * @param toolRepository the {@link ToolRepository} used to locate and download the tool.
225
   * @param resolvedVersion the resolved {@link VersionIdentifier} of the {@link #getName() tool} to install.
226
   * @param installationPath the target {@link Path} where the {@link #getName() tool} should be installed.
227
   * @param edition the specific edition of the tool to install.
228
   * @param processContext the {@link ProcessContext} used to manage the installation process.
229
   */
230
  protected void performToolInstallation(ToolRepository toolRepository, VersionIdentifier resolvedVersion, Path installationPath,
231
      String edition, ProcessContext processContext) {
232

233
    FileAccess fileAccess = this.context.getFileAccess();
4✔
234
    Path downloadedToolFile = downloadTool(edition, toolRepository, resolvedVersion);
6✔
235
    boolean extract = isExtract();
3✔
236
    if (!extract) {
2✔
237
      this.context.trace("Extraction is disabled for '{}' hence just moving the downloaded file {}.", this.tool, downloadedToolFile);
15✔
238
    }
239
    if (Files.isDirectory(installationPath)) {
5✔
240
      if (this.tool.equals(IdeasyCommandlet.TOOL_NAME)) {
5!
241
        this.context.warning("Your IDEasy installation is missing the version file.");
×
242
      } else {
243
        fileAccess.backup(installationPath);
4✔
244
      }
245
    }
246
    fileAccess.mkdirs(installationPath.getParent());
4✔
247
    fileAccess.extract(downloadedToolFile, installationPath, this::postExtract, extract);
7✔
248
    this.context.writeVersionFile(resolvedVersion, installationPath);
5✔
249
    this.context.debug("Installed {} in version {} at {}", this.tool, resolvedVersion, installationPath);
19✔
250
  }
1✔
251

252
  /**
253
   * @param edition the {@link #getConfiguredEdition() tool edition} to download.
254
   * @param toolRepository the {@link ToolRepository} to use.
255
   * @param resolvedVersion the resolved {@link VersionIdentifier version} to download.
256
   * @return the {@link Path} to the downloaded release file.
257
   */
258
  protected Path downloadTool(String edition, ToolRepository toolRepository, VersionIdentifier resolvedVersion) {
259
    return toolRepository.download(this.tool, edition, resolvedVersion, this);
8✔
260
  }
261

262
  /**
263
   * Install this tool as dependency of another tool.
264
   *
265
   * @param version the required {@link VersionRange}. See {@link ToolDependency#versionRange()}.
266
   * @param processContext the {@link ProcessContext}.
267
   * @param toolParent the parent tool name needing the dependency
268
   * @return {@code true} if the tool was newly installed, {@code false} otherwise (installation was already present).
269
   */
270
  public boolean installAsDependency(VersionRange version, ProcessContext processContext, String toolParent) {
271

272
    VersionIdentifier configuredVersion = getConfiguredVersion();
3✔
273
    if (version.contains(configuredVersion)) {
4✔
274
      // prefer configured version if contained in version range
275
      return install(true, processContext, null);
6✔
276
    } else {
277
      if (isIgnoreSoftwareRepo()) {
3!
278
        throw new IllegalStateException(
×
279
            "Cannot satisfy dependency to " + this.tool + " in version " + version + " since it is conflicting with configured version " + configuredVersion
280
                + " and this tool does not support the software repository.");
281
      }
282
      this.context.info(
23✔
283
          "The tool {} requires {} in the version range {}, but your project uses version {}, which does not match."
284
              + " Therefore, we install a compatible version in that range.",
285
          toolParent, this.tool, version, configuredVersion);
286
    }
287
    ToolInstallation toolInstallation = installTool(version, processContext);
5✔
288
    return toolInstallation.newInstallation();
3✔
289
  }
290

291
  /**
292
   * Installs the tool dependencies for the current tool.
293
   *
294
   * @param version the {@link VersionIdentifier} to use.
295
   * @param edition the edition to use.
296
   * @param processContext the {@link ProcessContext} to use.
297
   */
298
  protected void installToolDependencies(VersionIdentifier version, String edition, ProcessContext processContext) {
299
    Collection<ToolDependency> dependencies = getToolRepository().findDependencies(this.tool, edition, version);
8✔
300
    String toolWithEdition = getToolWithEdition(this.tool, edition);
5✔
301
    int size = dependencies.size();
3✔
302
    this.context.debug("Tool {} has {} other tool(s) as dependency", toolWithEdition, size);
15✔
303
    for (ToolDependency dependency : dependencies) {
10✔
304
      this.context.trace("Ensuring dependency {} for tool {}", dependency.tool(), toolWithEdition);
15✔
305
      LocalToolCommandlet dependencyTool = this.context.getCommandletManager().getRequiredLocalToolCommandlet(dependency.tool());
7✔
306
      dependencyTool.installAsDependency(dependency.versionRange(), processContext, toolWithEdition);
7✔
307
    }
1✔
308
  }
1✔
309

310
  /**
311
   * Post-extraction hook that can be overridden to add custom processing after unpacking and before moving to the final destination folder.
312
   *
313
   * @param extractedDir the {@link Path} to the folder with the unpacked tool.
314
   */
315
  protected void postExtract(Path extractedDir) {
316

317
  }
1✔
318

319
  @Override
320
  public VersionIdentifier getInstalledVersion() {
321

322
    return getInstalledVersion(this.context.getSoftwarePath().resolve(getName()));
9✔
323
  }
324

325
  /**
326
   * @param toolPath the installation {@link Path} where to find the version file.
327
   * @return the currently installed {@link VersionIdentifier version} of this tool or {@code null} if not installed.
328
   */
329
  protected VersionIdentifier getInstalledVersion(Path toolPath) {
330

331
    if (!Files.isDirectory(toolPath)) {
5✔
332
      this.context.debug("Tool {} not installed in {}", getName(), toolPath);
15✔
333
      return null;
2✔
334
    }
335
    Path toolVersionFile = toolPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
336
    if (!Files.exists(toolVersionFile)) {
5✔
337
      Path legacyToolVersionFile = toolPath.resolve(IdeContext.FILE_LEGACY_SOFTWARE_VERSION);
4✔
338
      if (Files.exists(legacyToolVersionFile)) {
5✔
339
        toolVersionFile = legacyToolVersionFile;
3✔
340
      } else {
341
        this.context.warning("Tool {} is missing version file in {}", getName(), toolVersionFile);
15✔
342
        return null;
2✔
343
      }
344
    }
345
    String version = this.context.getFileAccess().readFileContent(toolVersionFile).trim();
7✔
346
    return VersionIdentifier.of(version);
3✔
347
  }
348

349
  @Override
350
  public String getInstalledEdition() {
351

352
    if (this.context.getSoftwarePath() == null) {
4!
353
      return "";
×
354
    }
355
    return getInstalledEdition(this.context.getSoftwarePath().resolve(this.tool));
9✔
356
  }
357

358
  /**
359
   * @param toolPath the installation {@link Path} where to find currently installed tool. The name of the parent directory of the real path corresponding
360
   *     to the passed {@link Path path} must be the name of the edition.
361
   * @return the installed edition of this tool or {@code null} if not installed.
362
   */
363
  private String getInstalledEdition(Path toolPath) {
364
    if (!Files.isDirectory(toolPath)) {
5✔
365
      this.context.debug("Tool {} not installed in {}", this.tool, toolPath);
15✔
366
      return null;
2✔
367
    }
368
    Path realPath = this.context.getFileAccess().toRealPath(toolPath);
6✔
369
    // if the realPath changed, a link has been resolved
370
    if (realPath.equals(toolPath)) {
4✔
371
      if (!isIgnoreSoftwareRepo()) {
3!
372
        this.context.warning("Tool {} is not installed via software repository (maybe from devonfw-ide). Please consider reinstalling it.", this.tool);
11✔
373
      }
374
      // 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
375
      return getConfiguredEdition();
3✔
376
    }
377
    Path toolRepoFolder = context.getSoftwareRepositoryPath().resolve(ToolRepository.ID_DEFAULT).resolve(this.tool);
9✔
378
    String edition = getEdition(toolRepoFolder, realPath);
5✔
379
    if (!getToolRepository().getSortedEditions(this.tool).contains(edition)) {
8✔
380
      this.context.warning("Undefined edition {} of tool {}", edition, this.tool);
15✔
381
    }
382
    return edition;
2✔
383
  }
384

385
  private String getEdition(Path toolRepoFolder, Path toolInstallFolder) {
386

387
    int toolRepoNameCount = toolRepoFolder.getNameCount();
3✔
388
    int toolInstallNameCount = toolInstallFolder.getNameCount();
3✔
389
    if (toolRepoNameCount < toolInstallNameCount) {
3!
390
      // ensure toolInstallFolder starts with $IDE_ROOT/_ide/software/default/«tool»
391
      for (int i = 0; i < toolRepoNameCount; i++) {
7✔
392
        if (!toolRepoFolder.getName(i).toString().equals(toolInstallFolder.getName(i).toString())) {
10!
393
          return null;
×
394
        }
395
      }
396
      return toolInstallFolder.getName(toolRepoNameCount).toString();
5✔
397
    }
398
    return null;
×
399
  }
400

401
  private Path getInstalledSoftwareRepoPath(Path toolPath) {
402
    if (!Files.isDirectory(toolPath)) {
5!
403
      this.context.debug("Tool {} not installed in {}", this.tool, toolPath);
×
404
      return null;
×
405
    }
406
    Path installPath = this.context.getFileAccess().toRealPath(toolPath);
6✔
407
    // if the installPath changed, a link has been resolved
408
    if (installPath.equals(toolPath)) {
4!
409
      if (!isIgnoreSoftwareRepo()) {
×
410
        this.context.warning("Tool {} is not installed via software repository (maybe from devonfw-ide). Please consider reinstalling it.", this.tool);
×
411
      }
412
      // 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
413
      return null;
×
414
    }
415
    installPath = getValidInstalledSoftwareRepoPath(installPath, context.getSoftwareRepositoryPath());
7✔
416
    return installPath;
2✔
417
  }
418

419
  Path getValidInstalledSoftwareRepoPath(Path installPath, Path softwareRepoPath) {
420
    int softwareRepoNameCount = softwareRepoPath.getNameCount();
3✔
421
    int toolInstallNameCount = installPath.getNameCount();
3✔
422
    int targetToolInstallNameCount = softwareRepoNameCount + 4;
4✔
423

424
    // installPath can't be shorter than softwareRepoPath
425
    if (toolInstallNameCount < softwareRepoNameCount) {
3!
426
      this.context.warning("The installation path is not located within the software repository {}.", installPath);
×
427
      return null;
×
428
    }
429
    // ensure installPath starts with $IDE_ROOT/_ide/software/
430
    for (int i = 0; i < softwareRepoNameCount; i++) {
7✔
431
      if (!softwareRepoPath.getName(i).toString().equals(installPath.getName(i).toString())) {
10✔
432
        this.context.warning("The installation path is not located within the software repository {}.", installPath);
10✔
433
        return null;
2✔
434
      }
435
    }
436
    // return $IDE_ROOT/_ide/software/«id»/«tool»/«edition»/«version»
437
    if (toolInstallNameCount == targetToolInstallNameCount) {
3✔
438
      return installPath;
2✔
439
    } else if (toolInstallNameCount > targetToolInstallNameCount) {
3✔
440
      Path validInstallPath = installPath;
2✔
441
      for (int i = 0; i < toolInstallNameCount - targetToolInstallNameCount; i++) {
9✔
442
        validInstallPath = validInstallPath.getParent();
3✔
443
      }
444
      return validInstallPath;
2✔
445
    } else {
446
      this.context.warning("The installation path is faulty {}.", installPath);
10✔
447
      return null;
2✔
448
    }
449
  }
450

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

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

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

497

498
  private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier resolvedVersion, boolean newInstallation,
499
      EnvironmentContext environmentContext, boolean extraInstallation) {
500

501
    Path linkDir = getMacOsHelper().findLinkDir(rootDir, getBinaryName());
7✔
502
    Path binDir = linkDir;
2✔
503
    Path binFolder = binDir.resolve(IdeContext.FOLDER_BIN);
4✔
504
    if (Files.isDirectory(binFolder)) {
5✔
505
      binDir = binFolder;
2✔
506
    }
507
    if (linkDir != rootDir) {
3✔
508
      assert (!linkDir.equals(rootDir));
5!
509
      Path toolVersionFile = rootDir.resolve(IdeContext.FILE_SOFTWARE_VERSION);
4✔
510
      if (Files.exists(toolVersionFile)) {
5!
511
        this.context.getFileAccess().copy(toolVersionFile, linkDir, FileCopyMode.COPY_FILE_OVERRIDE);
7✔
512
      }
513
    }
514
    ToolInstallation toolInstallation = new ToolInstallation(rootDir, linkDir, binDir, resolvedVersion, newInstallation);
9✔
515
    setEnvironment(environmentContext, toolInstallation, extraInstallation);
5✔
516
    return toolInstallation;
2✔
517
  }
518

519
  /**
520
   * Method to set environment variables for the process context.
521
   *
522
   * @param environmentContext the {@link EnvironmentContext} where to {@link EnvironmentContext#withEnvVar(String, String) set environment variables} for
523
   *     this tool.
524
   * @param toolInstallation the {@link ToolInstallation}.
525
   * @param extraInstallation {@code true} if the {@link ToolInstallation} is an additional installation to the
526
   *     {@link #getConfiguredVersion() configured version} due to a conflicting version of a {@link ToolDependency}, {@code false} otherwise.
527
   */
528
  public void setEnvironment(EnvironmentContext environmentContext, ToolInstallation toolInstallation, boolean extraInstallation) {
529

530
    String pathVariable = EnvironmentVariables.getToolVariablePrefix(this.tool) + "_HOME";
5✔
531
    environmentContext.withEnvVar(pathVariable, toolInstallation.linkDir().toString());
7✔
532
    if (extraInstallation) {
2✔
533
      environmentContext.withPathEntry(toolInstallation.binDir());
5✔
534
    }
535
  }
1✔
536

537
  /**
538
   * @return {@link VersionIdentifier} with latest version of the tool}.
539
   */
540
  public VersionIdentifier getLatestToolVersion() {
541

542
    return this.context.getDefaultToolRepository().resolveVersion(this.tool, getConfiguredEdition(), VersionIdentifier.LATEST, this);
×
543
  }
544

545

546
  /**
547
   * Searches for a wrapper file in valid projects (containing a build file f.e. build.gradle or pom.xml) and returns its path.
548
   *
549
   * @param wrapperFileName the name of the wrapper file
550
   * @param filter the {@link Predicate} to match
551
   * @return Path of the wrapper file or {@code null} if none was found.
552
   */
553
  protected Path findWrapper(String wrapperFileName, Predicate<Path> filter) {
554
    Path dir = context.getCwd();
4✔
555
    // traverse the cwd directory containing a build file up till a wrapper file was found
556
    while ((dir != null) && filter.test(dir)) {
6!
557
      if (Files.exists(dir.resolve(wrapperFileName))) {
7✔
558
        context.debug("Using wrapper file at: {}", dir);
10✔
559
        return dir.resolve(wrapperFileName);
4✔
560
      }
561
      dir = dir.getParent();
4✔
562
    }
563
    return null;
2✔
564
  }
565

566

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