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

devonfw / IDEasy / 20003978026

07 Dec 2025 12:09PM UTC coverage: 70.101% (+0.2%) from 69.903%
20003978026

push

github

web-flow
#39: refactoring to extract package-manager logic out of node/npm (#1638)

3892 of 6090 branches covered (63.91%)

Branch coverage included in aggregate %.

9955 of 13663 relevant lines covered (72.86%)

3.15 hits per line

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

26.47
cli/src/main/java/com/devonfw/tools/ide/tool/npm/NpmBasedCommandlet.java
1
package com.devonfw.tools.ide.tool.npm;
2

3
import java.nio.file.Files;
4
import java.util.List;
5
import java.util.Set;
6

7
import com.devonfw.tools.ide.common.Tag;
8
import com.devonfw.tools.ide.context.IdeContext;
9
import com.devonfw.tools.ide.process.ProcessMode;
10
import com.devonfw.tools.ide.process.ProcessResult;
11
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
12
import com.devonfw.tools.ide.tool.PackageManagerRequest;
13
import com.devonfw.tools.ide.tool.node.NodeBasedCommandlet;
14
import com.devonfw.tools.ide.tool.repository.ToolRepository;
15
import com.devonfw.tools.ide.version.VersionIdentifier;
16

17
/**
18
 * {@link LocalToolCommandlet} for tools based on <a href="https://www.npmjs.com/">npm</a>.
19
 */
20
public abstract class NpmBasedCommandlet extends NodeBasedCommandlet<Npm> {
21

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

31
    super(context, tool, tags);
5✔
32
  }
1✔
33

34
  @Override
35
  protected Class<Npm> getPackageManagerClass() {
36

37
    return Npm.class;
2✔
38
  }
39

40
  @Override
41
  public ToolRepository getToolRepository() {
42

43
    return this.context.getNpmRepository();
4✔
44
  }
45

46
  @Override
47
  protected VersionIdentifier computeInstalledVersion() {
48
    return runPackageManagerGetInstalledVersion(getPackageName());
5✔
49
  }
50

51
  private VersionIdentifier runPackageManagerGetInstalledVersion(String npmPackage) {
52
    if (!Files.isDirectory(this.context.getSoftwarePath().resolve("node"))) {
9!
53
      this.context.trace("Since node is not installed, also package {} for tool {} cannot be installed.", npmPackage, this.tool);
15✔
54
      return null;
2✔
55
    }
56
    PackageManagerRequest request = new PackageManagerRequest("list", npmPackage).addArg("-g").addArg(npmPackage).addArg("--depth=0")
×
57
        .setProcessMode(ProcessMode.DEFAULT_CAPTURE);
×
58
    ProcessResult result = runPackageManager(request);
×
59
    if (result.isSuccessful()) {
×
60
      List<String> versions = result.getOut();
×
61
      String parsedVersion = null;
×
62
      for (String version : versions) {
×
63
        if (version.contains(npmPackage)) {
×
64
          parsedVersion = version.replaceAll(".*" + npmPackage + "@", "");
×
65
          break;
×
66
        }
67
      }
×
68
      if (parsedVersion != null) {
×
69
        return VersionIdentifier.of(parsedVersion);
×
70
      }
71
    } else {
×
72
      this.context.debug("The npm package {} for tool {} is not installed.", npmPackage, this.tool);
×
73
    }
74
    return null;
×
75
  }
76

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