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

devonfw / IDEasy / 22283847745

22 Feb 2026 07:34PM UTC coverage: 70.75% (+0.3%) from 70.474%
22283847745

Pull #1714

github

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

4064 of 6348 branches covered (64.02%)

Branch coverage included in aggregate %.

10635 of 14428 relevant lines covered (73.71%)

3.1 hits per line

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

82.93
cli/src/main/java/com/devonfw/tools/ide/nls/NlsBundle.java
1
package com.devonfw.tools.ide.nls;
2

3
import java.util.Locale;
4
import java.util.ResourceBundle;
5

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

9
import com.devonfw.tools.ide.commandlet.Commandlet;
10
import com.devonfw.tools.ide.context.IdeContext;
11
import com.devonfw.tools.ide.property.Property;
12

13
/**
14
 * Wrapper for {@link ResourceBundle} to avoid {@link java.util.MissingResourceException}.
15
 */
16
public class NlsBundle {
17

18
  private static final Logger LOG = LoggerFactory.getLogger(NlsBundle.class);
4✔
19

20
  private final IdeContext context;
21

22
  private final String fqn;
23

24
  private final ResourceBundle bundle;
25

26
  /**
27
   * The constructor.
28
   *
29
   * @param context the {@link IdeContext}.
30
   * @param name the simple name of {@link ResourceBundle} (e.g. "Cli").
31
   */
32
  public NlsBundle(IdeContext context, String name) {
33

34
    this(context, name, Locale.getDefault());
×
35
  }
×
36

37
  /**
38
   * The constructor.
39
   *
40
   * @param context the {@link IdeContext}.
41
   * @param locale the explicit {@link Locale} to use.
42
   */
43
  public NlsBundle(IdeContext context, Locale locale) {
44

45
    this(context, "Help", locale);
5✔
46
  }
1✔
47

48
  /**
49
   * The constructor.
50
   *
51
   * @param context the {@link IdeContext}.
52
   * @param name the simple name of {@link ResourceBundle} (e.g. "Cli").
53
   * @param locale the explicit {@link Locale} to use.
54
   */
55
  public NlsBundle(IdeContext context, String name, Locale locale) {
56

57
    super();
2✔
58
    this.context = context;
3✔
59
    this.fqn = "nls." + name;
4✔
60
    this.bundle = ResourceBundle.getBundle(this.fqn, locale);
6✔
61
  }
1✔
62

63
  /**
64
   * @param key the NLS key.
65
   * @return the localized message (translated to the users language).
66
   */
67
  public String get(String key) {
68

69
    if (!this.bundle.containsKey(key)) {
5!
70
      LOG.warn("Cound not find key '{}' in ResourceBundle {}.properties", key, this.fqn);
×
71
      return "?" + key;
×
72
    }
73
    return this.bundle.getString(key);
5✔
74
  }
75

76
  /**
77
   * @param key the NLS key.
78
   * @return the localized message (translated to the users language) or {@code null} if undefined.
79
   */
80
  public String getOrNull(String key) {
81

82
    if (!this.bundle.containsKey(key)) {
5✔
83
      return null;
2✔
84
    }
85
    return this.bundle.getString(key);
5✔
86
  }
87

88
  /**
89
   * @param commandlet the {@link com.devonfw.tools.ide.commandlet.Commandlet} to get the help summary for.
90
   * @return the localized message (translated to the users language).
91
   */
92
  public String get(Commandlet commandlet) {
93

94
    return get("cmd." + commandlet.getName());
6✔
95
  }
96

97
  /**
98
   * @param commandlet the {@link com.devonfw.tools.ide.commandlet.Commandlet} to get the help detail for.
99
   * @return the localized message (translated to the users language).
100
   */
101
  public String getDetail(Commandlet commandlet) {
102

103
    return get("cmd." + commandlet.getName() + ".detail");
6✔
104
  }
105

106
  /**
107
   * @param commandlet the {@link Commandlet} {@link Commandlet#getProperties() owning} the given {@link Property}.
108
   * @param property the {@link Property} to the the description of.
109
   * @return the localized message describing the property.
110
   */
111
  public String get(Commandlet commandlet, Property<?> property) {
112

113
    String prefix = "opt.";
2✔
114
    if (property.isValue()) {
3✔
115
      prefix = "val.";
2✔
116
    }
117
    String key = prefix + property.getNameOrAlias();
5✔
118

119
    String qualifiedKey = "cmd." + commandlet.getName() + "." + key;
5✔
120
    String value = getOrNull(qualifiedKey);
4✔
121
    if (value == null) {
2✔
122
      value = getOrNull(key); // fallback to share messages across commandlets
4✔
123
      if (value == null) {
2!
124
        value = get(key); // will fail to resolve but we want to reuse the code
×
125
      }
126
    }
127
    return value;
2✔
128
  }
129

130
  /**
131
   * @param context the {@link IdeContext}.
132
   * @return the {@link NlsBundle} for "Cli".
133
   */
134
  public static NlsBundle of(IdeContext context) {
135

136
    return new NlsBundle(context, context.getLocale());
7✔
137
  }
138

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