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

devonfw / IDEasy / 22303886886

23 Feb 2026 11:19AM UTC coverage: 70.647% (+0.2%) from 70.474%
22303886886

Pull #1714

github

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

4069 of 6360 branches covered (63.98%)

Branch coverage included in aggregate %.

10644 of 14466 relevant lines covered (73.58%)

3.1 hits per line

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

61.43
cli/src/main/java/com/devonfw/tools/ide/cli/Ideasy.java
1
package com.devonfw.tools.ide.cli;
2

3
import java.net.URLEncoder;
4
import java.nio.charset.StandardCharsets;
5

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

9
import com.devonfw.tools.ide.commandlet.ContextCommandlet;
10
import com.devonfw.tools.ide.context.AbstractIdeContext;
11
import com.devonfw.tools.ide.context.IdeContext;
12
import com.devonfw.tools.ide.context.IdeContextConsole;
13
import com.devonfw.tools.ide.context.IdeStartContextImpl;
14
import com.devonfw.tools.ide.log.JulLogLevel;
15
import com.devonfw.tools.ide.property.FlagProperty;
16
import com.devonfw.tools.ide.property.Property;
17

18
/**
19
 * The main program of the CLI (command-line-interface).
20
 */
21
public final class Ideasy {
22

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

25
  private AbstractIdeContext context;
26

27
  /**
28
   * The default constructor.
29
   */
30
  public Ideasy() {
31
    super();
×
32
  }
×
33

34
  /**
35
   * The constructor.
36
   *
37
   * @param context the predefined {@link IdeContext} for testing.
38
   */
39
  Ideasy(AbstractIdeContext context) {
40

41
    super();
2✔
42
    this.context = context;
3✔
43
  }
1✔
44

45
  /**
46
   * Non-static variant of {@link #main(String...) main method} without invoking {@link System#exit(int)} so it can be tested.
47
   *
48
   * @param args the command-line arguments.
49
   * @return the exit code.
50
   */
51
  public int run(String... args) {
52

53
    int exitStatus;
54
    try {
55
      exitStatus = runOrThrow(args);
4✔
56
    } catch (CliException error) {
1✔
57
      exitStatus = error.getExitCode();
3✔
58
      String errorMessage = error.getMessage();
3✔
59
      if ((errorMessage != null) && !errorMessage.isBlank()) {
5!
60
        LOG.error(errorMessage);
3✔
61
      }
62
    } catch (Throwable error) {
×
63
      exitStatus = 255;
×
64
      String title = error.getMessage();
×
65
      if (title == null) {
×
66
        title = error.getClass().getName();
×
67
      } else {
68
        title = error.getClass().getSimpleName() + ": " + title;
×
69
      }
70
      String message = "An unexpected error occurred!\n" //
×
71
          + "We are sorry for the inconvenience.\n" //
72
          + "Please check the error below, resolve it and try again.\n" //
73
          + "If the error is not on your end (network connectivity, lack of permissions, etc.) please file a bug:\n" //
74
          + "https://github.com/devonfw/IDEasy/issues/new?template=bug_report.yml&title="
75
          + URLEncoder.encode(title, StandardCharsets.UTF_8);
×
76
      LOG.error(message, error);
×
77
    }
2✔
78
    return exitStatus;
2✔
79
  }
80

81
  /**
82
   * Like {@link #run(String...)} but does not catch {@link Throwable}s so you can handle them yourself.
83
   *
84
   * @param args the command-line arguments.
85
   * @return the exit code.
86
   */
87
  public int runOrThrow(String... args) {
88

89
    CliArguments arguments = new CliArguments(args);
5✔
90
    initContext(arguments);
3✔
91
    return this.context.run(arguments);
5✔
92
  }
93

94
  private void initContext(CliArguments arguments) {
95

96
    IdeStartContextImpl startContext = null;
2✔
97
    if (this.context != null) {
3!
98
      startContext = this.context.getStartContext();
4✔
99
    }
100
    ContextCommandlet contextCommandlet = new ContextCommandlet(startContext);
5✔
101
    while (arguments.hasNext()) {
3✔
102
      CliArgument current = arguments.next();
3✔
103
      String key = current.getKey();
3✔
104
      Property<?> property = contextCommandlet.getOption(key);
4✔
105
      if (property == null) {
2✔
106
        break;
1✔
107
      }
108
      String value = current.getValue();
3✔
109
      if (value == null) {
2!
110
        if (property instanceof FlagProperty) {
3!
111
          ((FlagProperty) property).setValue(Boolean.TRUE);
5✔
112
        } else {
113
          System.err.println("Missing value for option " + key);
×
114
        }
115
      } else {
116
        property.setValueAsString(value, this.context);
×
117
      }
118
    }
1✔
119
    contextCommandlet.run();
2✔
120
    if (this.context == null) {
3!
121
      startContext = contextCommandlet.getStartContext();
×
122
      this.context = new IdeContextConsole(startContext);
×
123
    }
124
  }
1✔
125

126
  /**
127
   * The actual main method of the CLI program.
128
   *
129
   * @param args the command-line arguments.
130
   */
131
  public static void main(String... args) {
132

133
    JulLogLevel.init();
×
134
    int exitStatus = new Ideasy().run(args);
×
135
    System.exit(exitStatus);
×
136
  }
×
137

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