• 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

61.64
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 com.devonfw.tools.ide.commandlet.ContextCommandlet;
7
import com.devonfw.tools.ide.context.AbstractIdeContext;
8
import com.devonfw.tools.ide.context.IdeContext;
9
import com.devonfw.tools.ide.context.IdeContextConsole;
10
import com.devonfw.tools.ide.context.IdeStartContextImpl;
11
import com.devonfw.tools.ide.log.IdeLogLevel;
12
import com.devonfw.tools.ide.property.FlagProperty;
13
import com.devonfw.tools.ide.property.Property;
14

15
/**
16
 * The main program of the CLI (command-line-interface).
17
 */
18
public final class Ideasy {
19

20
  private AbstractIdeContext context;
21

22
  /**
23
   * The default constructor.
24
   */
25
  public Ideasy() {
26
    super();
×
27
  }
×
28

29
  /**
30
   * The constructor.
31
   *
32
   * @param context the predefined {@link IdeContext} for testing.
33
   */
34
  Ideasy(AbstractIdeContext context) {
35

36
    super();
2✔
37
    this.context = context;
3✔
38
  }
1✔
39

40
  private IdeContext context() {
41

42
    if (this.context == null) {
3!
43
      // fallback in case of exception before initialization
44
      return new IdeContextConsole(IdeLogLevel.INFO, null, false);
×
45
    }
46
    return this.context;
3✔
47
  }
48

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

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

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

93
    CliArguments arguments = new CliArguments(args);
5✔
94
    initContext(arguments);
3✔
95
    return this.context.run(arguments);
5✔
96
  }
97

98
  private void initContext(CliArguments arguments) {
99

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

130
  /**
131
   * The actual main method of the CLI program.
132
   *
133
   * @param args the command-line arguments.
134
   */
135
  public static void main(String... args) {
136

137
    int exitStatus = new Ideasy().run(args);
×
138
    System.exit(exitStatus);
×
139
  }
×
140

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