• 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/EditionGetCommandlet.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

10
/**
11
 * An internal {@link Commandlet} to get the installed edition for a tool.
12
 *
13
 * @see ToolCommandlet#getInstalledEdition()
14
 */
15
public class EditionGetCommandlet extends Commandlet {
16

17
  /** The tool to get the edition of. */
18
  public final ToolProperty tool;
19

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

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

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

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

40
  @Override
41
  public String getName() {
42

43
    return "get-edition";
2✔
44
  }
45

46
  @Override
47
  public boolean isProcessableOutput() {
48

49
    return true;
×
50
  }
51

52
  @Override
53
  public void run() {
54

55
    ToolCommandlet commandlet = this.tool.getValue();
5✔
56
    String configuredEdition = commandlet.getConfiguredEdition();
3✔
57
    IdeSubLogger logger = this.context.level(IdeLogLevel.PROCESSABLE);
5✔
58

59
    if (this.installed.isTrue() && !this.configured.isTrue()) { // get installed edition
8!
60
      String installedEdition = commandlet.getInstalledEdition();
3✔
61
      if (commandlet.getInstalledVersion() == null) {
3✔
62
        // note: getInstalledEdition() will fallback to configured edition and not return null, therefore we use getInstalledVersion()
63
        toolInstallInfo(commandlet.getName(), configuredEdition, null, commandlet);
8✔
64
      } else {
65
        logger.log(installedEdition);
3✔
66
      }
67
    } else if (!this.installed.isTrue() && this.configured.isTrue()) { // get configured edition
9!
68
      logger.log(configuredEdition);
4✔
69
    } else { // get both configured and installed edition
70
      String installedEdition = commandlet.getInstalledEdition();
3✔
71
      if (configuredEdition.equals(installedEdition)) {
4✔
72
        logger.log(installedEdition);
4✔
73
      } else {
74
        toolInstallInfo(commandlet.getName(), configuredEdition, installedEdition, commandlet);
7✔
75
      }
76
    }
77
  }
1✔
78

79
  private void toolInstallInfo(String toolName, String configuredEdition, String installedEdition, ToolCommandlet commandlet) {
80

81
    if (installedEdition == null) {
2!
82
      this.context.warning("No installation of tool {} was found.", commandlet.getName());
12✔
83
    } else {
84
      this.context.info("The installed edition for tool {} is {}", commandlet.getName(), installedEdition);
×
85
    }
86
    this.context.info("The configured edition for tool {} is {}", toolName, configuredEdition);
14✔
87
    this.context.info("To install that edition call the following command:");
4✔
88
    this.context.info("ide install {}", toolName);
10✔
89
  }
1✔
90
}
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