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

devonfw / IDEasy / 22315552991

23 Feb 2026 04:40PM UTC coverage: 70.563% (+0.09%) from 70.474%
22315552991

Pull #1714

github

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

4081 of 6382 branches covered (63.95%)

Branch coverage included in aggregate %.

10644 of 14486 relevant lines covered (73.48%)

3.09 hits per line

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

85.71
cli/src/main/java/com/devonfw/tools/ide/commandlet/AbstractVersionOrEditionGetCommandlet.java
1
package com.devonfw.tools.ide.commandlet;
2

3
import java.util.Objects;
4

5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
7

8
import com.devonfw.tools.ide.cli.CliException;
9
import com.devonfw.tools.ide.context.IdeContext;
10
import com.devonfw.tools.ide.log.IdeLogLevel;
11
import com.devonfw.tools.ide.property.FlagProperty;
12
import com.devonfw.tools.ide.property.ToolProperty;
13
import com.devonfw.tools.ide.tool.ToolCommandlet;
14

15
/**
16
 * An internal {@link Commandlet} to get the installed version for a tool.
17
 *
18
 * @see ToolCommandlet#getInstalledVersion()
19
 */
20
public abstract class AbstractVersionOrEditionGetCommandlet extends Commandlet {
21

22
  private static final Logger LOG = LoggerFactory.getLogger(AbstractVersionOrEditionGetCommandlet.class);
4✔
23

24
  /** The tool to get the version of. */
25
  public final ToolProperty tool;
26

27
  /** Flag to get the configured version. */
28
  public final FlagProperty configured;
29

30
  /** Flag to get the installed version. */
31
  public final FlagProperty installed;
32

33
  /**
34
   * The constructor.
35
   *
36
   * @param context the {@link IdeContext}.
37
   */
38
  public AbstractVersionOrEditionGetCommandlet(IdeContext context) {
39

40
    super(context);
3✔
41
    addKeyword(getName());
4✔
42
    this.tool = add(new ToolProperty("", true, "tool"));
11✔
43
    this.configured = add(new FlagProperty("--configured"));
9✔
44
    this.installed = add(new FlagProperty("--installed"));
9✔
45
  }
1✔
46

47
  @Override
48
  public boolean isProcessableOutput() {
49

50
    return true;
×
51
  }
52

53
  /**
54
   * @return the property to get (e.g. "version" or "edition").
55
   */
56
  protected abstract String getPropertyToGet();
57

58
  /**
59
   * @param commandlet the {@link ToolCommandlet} to get the value from.
60
   * @return the configured value.
61
   * @see ToolCommandlet#getConfiguredVersion()
62
   * @see ToolCommandlet#getConfiguredEdition()
63
   */
64
  protected abstract Object getConfiguredValue(ToolCommandlet commandlet);
65

66
  /**
67
   * @param commandlet the {@link ToolCommandlet} to get the value from.
68
   * @return the installed value or {@code null} if the tool is not installed.
69
   * @see ToolCommandlet#getInstalledVersion()
70
   * @see ToolCommandlet#getInstalledEdition()
71
   */
72
  protected abstract Object getInstalledValue(ToolCommandlet commandlet);
73

74
  @Override
75
  protected void doRun() {
76

77
    ToolCommandlet commandlet = this.tool.getValue();
5✔
78
    IdeLogLevel level = IdeLogLevel.PROCESSABLE;
2✔
79
    Object configuredValue = getConfiguredValue(commandlet);
4✔
80
    Object installedValue = getInstalledValue(commandlet);
4✔
81
    boolean getInstalledValue = this.installed.isTrue();
4✔
82
    boolean getConfiguredValue = this.configured.isTrue();
4✔
83
    if (installedValue == null && getInstalledValue && !getConfiguredValue) {
6✔
84
      throw new CliException("Tool " + commandlet.getName() + " is not installed.", 1);
8✔
85
    }
86
    if (getInstalledValue == getConfiguredValue) {
3✔
87
      if (getInstalledValue) { // both --configured and --installed
2✔
88
        logToolInfo(commandlet, configuredValue, installedValue);
6✔
89
      } else if (LOG.isDebugEnabled()) {
3!
90
        logToolInfo(commandlet, configuredValue, installedValue);
6✔
91
      } else {
92
        if (installedValue == null) {
×
93
          level.log(LOG, configuredValue.toString());
×
94
        } else {
95
          level.log(LOG, installedValue.toString());
×
96
        }
97
      }
98
    } else {
99
      if (getInstalledValue) {
2✔
100
        if (installedValue == null) {
2!
101
          logToolInfo(commandlet, configuredValue, null);
×
102
        } else {
103
          level.log(LOG, installedValue.toString());
6✔
104
        }
105
      } else {
106
        level.log(LOG, configuredValue.toString());
5✔
107
      }
108
    }
109
  }
1✔
110

111
  private void logToolInfo(ToolCommandlet commandlet, Object configuredValue, Object installedValue) {
112

113
    String property = getPropertyToGet();
3✔
114
    String toolName = commandlet.getName();
3✔
115
    IdeLogLevel level = IdeLogLevel.PROCESSABLE;
2✔
116
    if (installedValue == null) {
2✔
117
      level.log(LOG, "No installation of tool {} was found.", toolName);
11✔
118
    } else {
119
      level.log(LOG, "The installed {} for tool {} is {}", property, toolName, installedValue);
18✔
120
    }
121
    level.log(LOG, "The configured {} for tool {} is {}", property, toolName, configuredValue);
18✔
122
    if (!Objects.equals(configuredValue, installedValue)) {
4✔
123
      level.log(LOG, "To install the configured {} call the following command:", property);
10✔
124
      level.log(LOG, "ide install {}", toolName);
10✔
125
    }
126
  }
1✔
127

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