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

devonfw / IDEasy / 9907372175

12 Jul 2024 11:49AM UTC coverage: 61.142% (-0.02%) from 61.162%
9907372175

push

github

hohwille
fixed tests

1997 of 3595 branches covered (55.55%)

Branch coverage included in aggregate %.

5296 of 8333 relevant lines covered (63.55%)

2.8 hits per line

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

0.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.log.IdeLogLevel;
11
import com.devonfw.tools.ide.property.FlagProperty;
12
import com.devonfw.tools.ide.property.Property;
13

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

19
  private AbstractIdeContext context;
20

21
  /**
22
   * The actual main method of the CLI program.
23
   *
24
   * @param args the command-line arguments.
25
   */
26
  public static void main(String... args) {
27

28
    int exitStatus = new Ideasy().run(args);
×
29
    System.exit(exitStatus);
×
30
  }
×
31

32
  private IdeContext context() {
33

34
    if (this.context == null) {
×
35
      // fallback in case of exception before initialization
36
      this.context = new IdeContextConsole(IdeLogLevel.INFO, null, false);
×
37
    }
38
    return this.context;
×
39
  }
40

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

49
    int exitStatus;
50
    try {
51
      exitStatus = runOrThrow(args);
×
52
    } catch (CliException error) {
×
53
      exitStatus = error.getExitCode();
×
54
      if (context().level(IdeLogLevel.DEBUG).isEnabled()) {
×
55
        context().error(error, error.getMessage());
×
56
      } else {
57
        context().error(error.getMessage());
×
58
      }
59
    } catch (Throwable error) {
×
60
      exitStatus = 255;
×
61
      String title = error.getMessage();
×
62
      if (title == null) {
×
63
        title = error.getClass().getName();
×
64
      } else {
65
        title = error.getClass().getSimpleName() + ": " + title;
×
66
      }
67
      String message = "An unexpected error occurred!\n" //
×
68
          + "We are sorry for the inconvenience.\n" //
69
          + "Please check the error below, resolve it and try again.\n" //
70
          + "If the error is not on your end (network connectivity, lack of permissions, etc.) please file a bug:\n" //
71
          + "https://github.com/devonfw/ide/issues/new?assignees=&labels=bug&projects=&template=bug.md&title="
72
          + URLEncoder.encode(title, StandardCharsets.UTF_8);
×
73
      context().error(error, message);
×
74
    }
×
75
    return exitStatus;
×
76
  }
77

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

86
    CliArguments arguments = new CliArguments(args);
×
87
    this.context = initContext(arguments);
×
88
    return this.context.run(arguments);
×
89
  }
90

91
  private AbstractIdeContext initContext(CliArguments arguments) {
92

93
    ContextCommandlet contextCommandlet = new ContextCommandlet();
×
94
    while (arguments.hasNext()) {
×
95
      CliArgument current = arguments.next();
×
96
      String key = current.getKey();
×
97
      Property<?> property = contextCommandlet.getOption(key);
×
98
      if (property == null) {
×
99
        break;
×
100
      }
101
      String value = current.getValue();
×
102
      if (value == null) {
×
103
        if (property instanceof FlagProperty) {
×
104
          ((FlagProperty) property).setValue(Boolean.TRUE);
×
105
        } else {
106
          System.err.println("Missing value for option " + key);
×
107
        }
108
      } else {
109
        property.setValueAsString(value, this.context);
×
110
      }
111
    }
×
112
    contextCommandlet.run();
×
113
    return contextCommandlet.getIdeContext();
×
114
  }
115

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