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

devonfw / IDEasy / 22300285724

23 Feb 2026 09:32AM UTC coverage: 70.754% (+0.3%) from 70.474%
22300285724

Pull #1714

github

web-flow
Merge caa980897 into 379acdc9d
Pull Request #1714: #404: #1713: advanced logging

4064 of 6348 branches covered (64.02%)

Branch coverage included in aggregate %.

10640 of 14434 relevant lines covered (73.71%)

3.1 hits per line

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

84.21
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 org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9

10
import com.devonfw.tools.ide.common.Tag;
11
import com.devonfw.tools.ide.context.IdeContext;
12
import com.devonfw.tools.ide.process.ProcessContext;
13
import com.devonfw.tools.ide.process.ProcessErrorHandling;
14
import com.devonfw.tools.ide.process.ProcessMode;
15
import com.devonfw.tools.ide.process.ProcessResult;
16
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
17
import com.devonfw.tools.ide.tool.PackageManagerRequest;
18
import com.devonfw.tools.ide.tool.node.NodeBasedCommandlet;
19
import com.devonfw.tools.ide.tool.repository.ToolRepository;
20
import com.devonfw.tools.ide.version.VersionIdentifier;
21

22
/**
23
 * {@link LocalToolCommandlet} for tools based on <a href="https://www.npmjs.com/">npm</a>.
24
 */
25
public abstract class NpmBasedCommandlet extends NodeBasedCommandlet<Npm> {
26

27
  private static final Logger LOG = LoggerFactory.getLogger(NpmBasedCommandlet.class);
4✔
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 NpmBasedCommandlet(IdeContext context, String tool, Set<Tag> tags) {
37

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

41
  @Override
42
  protected Class<Npm> getPackageManagerClass() {
43

44
    return Npm.class;
2✔
45
  }
46

47
  @Override
48
  public ToolRepository getToolRepository() {
49

50
    return this.context.getNpmRepository();
4✔
51
  }
52

53
  @Override
54
  protected VersionIdentifier computeInstalledVersion() {
55
    return runPackageManagerGetInstalledVersion(getPackageName());
5✔
56
  }
57

58
  private VersionIdentifier runPackageManagerGetInstalledVersion(String npmPackage) {
59
    if (!Files.isDirectory(this.context.getSoftwarePath().resolve("node"))) {
9✔
60
      LOG.trace("Since node is not installed, also package {} for tool {} cannot be installed.", npmPackage, this.tool);
6✔
61
      return null;
2✔
62
    }
63
    PackageManagerRequest request = new PackageManagerRequest("list", npmPackage).addArg("list").addArg("-g").addArg(npmPackage).addArg("--depth=0")
14✔
64
        .setProcessMode(ProcessMode.DEFAULT_CAPTURE);
2✔
65
    ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.THROW_CLI)
6✔
66
        .withExitCodeAcceptor(rc -> true); // if the tool is not installed npm list will end with exit code 1
4✔
67
    request.setProcessContext(pc);
4✔
68
    ProcessResult result = runPackageManager(request);
4✔
69
    if (result.isSuccessful()) {
3!
70
      List<String> versions = result.getOut();
3✔
71
      String parsedVersion = null;
2✔
72
      for (String version : versions) {
10!
73
        if (version.contains(npmPackage)) {
4✔
74
          parsedVersion = version.replaceAll(".*" + npmPackage + "@", "");
6✔
75
          break;
1✔
76
        }
77
      }
1✔
78
      if (parsedVersion != null) {
2!
79
        return VersionIdentifier.of(parsedVersion);
3✔
80
      }
81
    } else {
×
82
      LOG.debug("The npm package {} for tool {} is not installed.", npmPackage, this.tool);
×
83
    }
84
    return null;
×
85
  }
86

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