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

devonfw / IDEasy / 18877824558

28 Oct 2025 02:15PM UTC coverage: 68.54% (-0.004%) from 68.544%
18877824558

Pull #1550

github

web-flow
Merge bb39b9180 into 51056a748
Pull Request #1550: #1549: Adjusted download exception type

3469 of 5545 branches covered (62.56%)

Branch coverage included in aggregate %.

9069 of 12748 relevant lines covered (71.14%)

3.13 hits per line

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

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

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

97
    CliArguments arguments = new CliArguments(args);
5✔
98
    initContext(arguments);
3✔
99
    return this.context.run(arguments);
×
100
  }
101

102
  private void initContext(CliArguments arguments) {
103

104
    ContextCommandlet contextCommandlet = new ContextCommandlet();
4✔
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
      IdeStartContextImpl 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