• 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

74.47
cli/src/main/java/com/devonfw/tools/ide/commandlet/ContextCommandlet.java
1
package com.devonfw.tools.ide.commandlet;
2

3
import com.devonfw.tools.ide.context.AbstractIdeContext;
4
import com.devonfw.tools.ide.context.IdeContext;
5
import com.devonfw.tools.ide.context.IdeStartContextImpl;
6
import com.devonfw.tools.ide.log.IdeLogLevel;
7
import com.devonfw.tools.ide.log.IdeLogListenerBuffer;
8
import com.devonfw.tools.ide.log.IdeSubLoggerOut;
9
import com.devonfw.tools.ide.property.FlagProperty;
10
import com.devonfw.tools.ide.property.LocaleProperty;
11

12
/**
13
 * An internal pseudo-commandlet to create the {@link IdeContext}. It shall not be registered in {@link CommandletManager}.
14
 */
15
public class ContextCommandlet extends Commandlet {
1✔
16

17
  private final FlagProperty batch;
18

19
  private final FlagProperty force;
20

21
  private final FlagProperty trace;
22

23
  private final FlagProperty debug;
24

25
  private final FlagProperty quiet;
26

27
  private final FlagProperty offline;
28

29
  private final LocaleProperty locale;
30

31
  private IdeStartContextImpl startContext;
32

33
  /**
34
   * The constructor.
35
   */
36
  public ContextCommandlet() {
37

38
    super(null);
3✔
39
    this.batch = add(new FlagProperty("--batch", false, "-b"));
11✔
40
    this.force = add(new FlagProperty("--force", false, "-f"));
11✔
41
    this.trace = add(new FlagProperty("--trace", false, "-t"));
11✔
42
    this.debug = add(new FlagProperty("--debug", false, "-d"));
11✔
43
    this.quiet = add(new FlagProperty("--quiet", false, "-q"));
11✔
44
    this.offline = add(new FlagProperty("--offline", false, "-o"));
11✔
45
    this.locale = add(new LocaleProperty("--locale", false, null));
11✔
46
  }
1✔
47

48
  @Override
49
  public String getName() {
50

51
    return "context";
2✔
52
  }
53

54
  @Override
55
  public boolean isIdeHomeRequired() {
56

57
    return false;
2✔
58
  }
59

60
  @Override
61
  public void run() {
62

63
    IdeLogLevel logLevel = determineLogLevel();
3✔
64
    if (this.startContext == null) {
3!
65
      final IdeLogListenerBuffer buffer = new IdeLogListenerBuffer();
4✔
66
      this.startContext = new IdeStartContextImpl(logLevel, level -> new IdeSubLoggerOut(level, null, true, logLevel, buffer));
18✔
67
    } else if (this.context != null) {
1!
68
      IdeStartContextImpl newStartContext = ((AbstractIdeContext) this.context).getStartContext();
×
69
      assert (this.startContext == newStartContext); // fast fail during development via assert
×
70
      this.startContext = newStartContext;
×
71
    }
72
    this.startContext.setBatchMode(this.batch.isTrue());
6✔
73
    this.startContext.setForceMode(this.force.isTrue());
6✔
74
    this.startContext.setQuietMode(this.quiet.isTrue());
6✔
75
    this.startContext.setOfflineMode(this.offline.isTrue());
6✔
76
    this.startContext.setLocale(this.locale.getValue());
7✔
77
  }
1✔
78

79
  private IdeLogLevel determineLogLevel() {
80
    IdeLogLevel logLevel = IdeLogLevel.INFO;
2✔
81
    if (this.trace.isTrue()) {
4!
82
      logLevel = IdeLogLevel.TRACE;
×
83
    } else if (this.debug.isTrue()) {
4!
84
      logLevel = IdeLogLevel.DEBUG;
×
85
    } else if (this.quiet.isTrue()) {
4✔
86
      logLevel = IdeLogLevel.WARNING;
2✔
87
    }
88
    return logLevel;
2✔
89
  }
90

91
  /**
92
   * @return the {@link IdeStartContextImpl} that has been created by {@link #run()}.
93
   */
94
  public IdeStartContextImpl getStartContext() {
95

96
    return this.startContext;
3✔
97
  }
98
}
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