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

devonfw / IDEasy / 11963246771

21 Nov 2024 11:10PM UTC coverage: 67.428% (+0.2%) from 67.239%
11963246771

push

github

web-flow
#754: bullet proof solution for processable output and logging (#777)

2487 of 4028 branches covered (61.74%)

Branch coverage included in aggregate %.

6454 of 9232 relevant lines covered (69.91%)

3.09 hits per line

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

88.64
cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionGetCommandlet.java
1
package com.devonfw.tools.ide.commandlet;
2

3
import com.devonfw.tools.ide.context.IdeContext;
4
import com.devonfw.tools.ide.log.IdeLogLevel;
5
import com.devonfw.tools.ide.log.IdeSubLogger;
6
import com.devonfw.tools.ide.property.FlagProperty;
7
import com.devonfw.tools.ide.property.ToolProperty;
8
import com.devonfw.tools.ide.tool.ToolCommandlet;
9
import com.devonfw.tools.ide.version.VersionIdentifier;
10

11
/**
12
 * An internal {@link Commandlet} to get the installed version for a tool.
13
 *
14
 * @see ToolCommandlet#getInstalledVersion()
15
 */
16
public class VersionGetCommandlet extends Commandlet {
17

18
  /** The tool to get the version of. */
19
  public final ToolProperty tool;
20

21
  /** Flag to get the configured version. */
22
  public final FlagProperty configured;
23

24
  /** Flag to get the installed version. */
25
  public final FlagProperty installed;
26

27
  /**
28
   * The constructor.
29
   *
30
   * @param context the {@link IdeContext}.
31
   */
32
  public VersionGetCommandlet(IdeContext context) {
33

34
    super(context);
3✔
35
    addKeyword(getName());
4✔
36
    this.tool = add(new ToolProperty("", true, "tool"));
11✔
37
    this.configured = add(new FlagProperty("--configured"));
9✔
38
    this.installed = add(new FlagProperty("--installed"));
9✔
39
  }
1✔
40

41
  @Override
42
  public String getName() {
43

44
    return "get-version";
2✔
45
  }
46

47
  @Override
48
  public boolean isProcessableOutput() {
49

50
    return true;
×
51
  }
52

53
  @Override
54
  public void run() {
55

56
    ToolCommandlet commandlet = this.tool.getValue();
5✔
57
    VersionIdentifier configuredVersion = commandlet.getConfiguredVersion();
3✔
58
    IdeSubLogger logger = this.context.level(IdeLogLevel.PROCESSABLE);
5✔
59
    if (this.installed.isTrue() && !this.configured.isTrue()) {// get installed version
8!
60
      VersionIdentifier installedVersion = commandlet.getInstalledVersion();
3✔
61
      if (installedVersion == null) {
2✔
62
        toolInstallInfo(commandlet.getName(), configuredVersion, null, commandlet);
8✔
63
      } else {
64
        logger.log(installedVersion.toString());
4✔
65
      }
66
    } else if (!this.installed.isTrue() && this.configured.isTrue()) {// get configured version
9!
67
      logger.log(configuredVersion.toString());
5✔
68
    } else { // get both configured and installed version
69
      VersionIdentifier installedVersion = commandlet.getInstalledVersion();
3✔
70
      if (configuredVersion.matches(installedVersion)) {
4✔
71
        logger.log(installedVersion.toString());
5✔
72
      } else {
73
        toolInstallInfo(commandlet.getName(), configuredVersion, installedVersion, commandlet);
7✔
74
      }
75
    }
76
  }
1✔
77

78
  private void toolInstallInfo(String toolName, VersionIdentifier configuredVersion, VersionIdentifier installedVersion, ToolCommandlet commandlet) {
79

80
    if (installedVersion == null) {
2!
81
      this.context.info("No installation of tool {} was found.", commandlet.getName());
12✔
82
    } else {
83
      this.context.info("The installed version for tool {} is {}", commandlet.getName(), installedVersion);
×
84
    }
85
    this.context.info("The configured version for tool {} is {}", toolName, configuredVersion);
14✔
86
    this.context.info("To install that version call the following command:");
4✔
87
    this.context.info("ide install {}", toolName);
10✔
88

89
  }
1✔
90

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

© 2025 Coveralls, Inc