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

devonfw / IDEasy / 22241505980

20 Feb 2026 09:16PM UTC coverage: 70.656% (+0.2%) from 70.474%
22241505980

Pull #1710

github

web-flow
Merge 04e4bdacd into 379acdc9d
Pull Request #1710: #404: allow logging via SLF4J

4121 of 6440 branches covered (63.99%)

Branch coverage included in aggregate %.

10704 of 14542 relevant lines covered (73.61%)

3.13 hits per line

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

87.3
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
import org.slf4j.Marker;
8

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

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

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

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

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

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

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

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

48
  @Override
49
  public boolean isProcessableOutput() {
50

51
    return true;
2✔
52
  }
53

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

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

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

75
  @Override
76
  protected void doRun() {
77

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

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

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

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