• 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

79.17
cli/src/main/java/com/devonfw/tools/ide/tool/node/NodeBasedCommandlet.java
1
package com.devonfw.tools.ide.tool.node;
2

3
import java.nio.file.Files;
4
import java.nio.file.Path;
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.tool.LocalToolCommandlet;
10
import com.devonfw.tools.ide.tool.PackageManagerBasedLocalToolCommandlet;
11
import com.devonfw.tools.ide.tool.PackageManagerRequest;
12
import com.devonfw.tools.ide.tool.ToolCommandlet;
13

14
/**
15
 * {@link LocalToolCommandlet} for tools based on <a href="https://www.npmjs.com/">npm</a>.
16
 *
17
 * @param <P> type of the {@link ToolCommandlet} acting as {@link #getPackageManagerClass() package manager}.
18
 */
19
public abstract class NodeBasedCommandlet<P extends ToolCommandlet> extends PackageManagerBasedLocalToolCommandlet<P> {
20

21
  /** File name of the {@link #findBuildDescriptor(Path) build descriptor} . */
22
  public static final String PACKAGE_JSON = "package.json";
23

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

33
    super(context, tool, tags);
5✔
34
  }
1✔
35

36
  @Override
37
  protected Node getParentTool() {
38

39
    return this.context.getCommandletManager().getCommandlet(Node.class);
7✔
40
  }
41

42
  @Override
43
  public boolean isInstalled() {
44

45
    return hasNodeBinary(this.tool);
5✔
46
  }
47

48
  @Override
49
  public String getInstalledEdition() {
50

51
    if (getInstalledVersion() != null) {
3!
52
      return this.tool;
3✔
53
    }
54
    return null;
×
55
  }
56

57
  /**
58
   * Checks if a provided binary can be found within node.
59
   *
60
   * @param binary name of the binary.
61
   * @return {@code true} if a binary was found in the node installation, {@code false} if not.
62
   */
63
  protected boolean hasNodeBinary(String binary) {
64

65
    return Files.exists(getToolBinPath().resolve(binary));
8✔
66
  }
67

68
  @Override
69
  protected String completeRequestOption(PackageManagerRequest request) {
70

71
    return switch (request.getType()) {
10!
72
      case PackageManagerRequest.TYPE_INSTALL -> "-gf";
2✔
73
      case PackageManagerRequest.TYPE_UNINSTALL -> "-g";
2✔
74
      default -> null;
×
75
    };
76
  }
77

78
  @Override
79
  public String getToolHelpArguments() {
80

81
    return "--help";
×
82
  }
83

84
  @Override
85
  public Path findBuildDescriptor(Path directory) {
86

87
    Path buildDescriptor = directory.resolve(PACKAGE_JSON);
4✔
88
    if (Files.exists(buildDescriptor)) {
5✔
89
      return buildDescriptor;
2✔
90
    }
91
    return super.findBuildDescriptor(directory);
4✔
92
  }
93
}
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