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

devonfw / IDEasy / 42916857669

10 Nov 2026 10:41PM UTC coverage: 75.192% (-0.06%) from 75.25%
42916857669

push

github

web-flow
#2409: implemented advanced approach for expression functions (#2775)

6330 of 9333 branches covered (67.82%)

Branch coverage included in aggregate %.

16244 of 20689 relevant lines covered (78.52%)

3.38 hits per line

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

89.36
cli/src/main/java/com/devonfw/tools/ide/commandlet/AbstractCommandlet.java
1
package com.devonfw.tools.ide.commandlet;
2

3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.HashMap;
6
import java.util.List;
7
import java.util.Map;
8

9
import com.devonfw.tools.ide.context.AbstractIdeContext;
10
import com.devonfw.tools.ide.context.IdeContext;
11
import com.devonfw.tools.ide.function.AbstractParameterizedFunction;
12
import com.devonfw.tools.ide.nls.NlsBundle;
13
import com.devonfw.tools.ide.property.KeywordProperty;
14
import com.devonfw.tools.ide.property.Property;
15
import com.devonfw.tools.ide.tool.AbstractToolCommandlet;
16
import com.devonfw.tools.ide.version.VersionIdentifier;
17

18
/**
19
 * A {@link AbstractCommandlet} is a sub-command of the IDE CLI.
20
 */
21
public abstract class AbstractCommandlet extends AbstractParameterizedFunction implements Commandlet {
22

23
  /** The {@link IdeContext} instance. */
24
  protected final IdeContext context;
25

26
  private final List<Property<?>> valuesList;
27

28
  private final List<Property<?>> values;
29

30
  private final Map<String, Property<?>> optionMap;
31

32
  private KeywordProperty firstKeyword;
33

34
  /**
35
   * The constructor.
36
   *
37
   * @param context the {@link IdeContext}.
38
   */
39
  public AbstractCommandlet(IdeContext context) {
40

41
    super();
2 ✔
42
    this.context = context;
3 ✔
43
    this.valuesList = new ArrayList<>();
5 ✔
44
    this.values = Collections.unmodifiableList(this.valuesList);
5 ✔
45
    this.optionMap = new HashMap<>();
5 ✔
46
  }
1 ✔
47

48
  /**
49
   * @return the {@link List} of {@link Property properties} that are {@link Property#isValue() values}.
50
   */
51
  public List<Property<?>> getValues() {
52

53
    return this.values;
3 ✔
54
  }
55

56
  /**
57
   * @param nameOrAlias the potential {@link Property#getName() name} or {@link Property#getAlias() alias} of the requested {@link Property}.
58
   * @return the requested {@link Property property} or {@code null} if not found.
59
   */
60
  public Property<?> getOption(String nameOrAlias) {
61

62
    return this.optionMap.get(nameOrAlias);
6 ✔
63
  }
64

65
  @Override
66
  protected <P extends Property<?>> P add(P property) {
67

68
    super.add(property);
4 ✔
69
    if (property.isValue()) {
3 ✔
70
      this.valuesList.add(property);
5 ✔
71
    }
72
    return property;
2 ✔
73
  }
74

75
  @Override
76
  protected Property<?> registerOption(String name, Property<?> property) {
77

78
    return this.optionMap.put(name, property);
7 ✔
79
  }
80

81
  /**
82
   * @param keyword the {@link KeywordProperty keyword} to {@link #add(Property) add}.
83
   */
84
  protected void addKeyword(String keyword) {
85

86
    addKeyword(keyword, null);
4 ✔
87
  }
1 ✔
88

89
  /**
90
   * @param keyword the {@link KeywordProperty keyword} to {@link #add(Property) add}.
91
   * @param alias the optional {@link KeywordProperty#getAlias() alias}.
92
   */
93
  protected void addKeyword(String keyword, String alias) {
94

95
    KeywordProperty property = new KeywordProperty(keyword, true, alias);
7 ✔
96
    if (this.firstKeyword == null) {
3 ✔
97
      if (!getProperties().isEmpty()) {
4 !
98
        throw new IllegalStateException(property + " must be first property in " + getClass().getSimpleName());
×
99
      }
100
      this.firstKeyword = property;
3 ✔
101
    }
102
    add(property);
4 ✔
103
  }
1 ✔
104

105
  @Override
106
  public IdeContext getContext() {
107

108
    return this.context;
3 ✔
109
  }
110

111
  /**
112
   * @return the first keyword of this {@link AbstractCommandlet}. Typically, the same as {@link #getName() name} but may also differ (e.g. "set" vs.
113
   *     "set-version").
114
   */
115
  public KeywordProperty getFirstKeyword() {
116

117
    return this.firstKeyword;
3 ✔
118
  }
119

120
  /**
121
   * @param <C> type of the {@link AbstractCommandlet}.
122
   * @param commandletType the {@link Class} reflecting the requested {@link AbstractCommandlet}.
123
   * @return the requested {@link AbstractCommandlet}.
124
   * @see CommandletManager#getCommandlet(Class)
125
   */
126
  protected <C extends AbstractCommandlet> C getCommandlet(Class<C> commandletType) {
127

128
    return this.context.getCommandletManager().getCommandlet(commandletType);
6 ✔
129
  }
130

131
  /**
132
   * @return {@code true} if {@link IdeContext#getIdeHome() IDE_HOME} is required for this commandlet, {@code false} otherwise.
133
   */
134
  public boolean isIdeHomeRequired() {
135

136
    return isIdeRootRequired();
3 ✔
137
  }
138

139
  /**
140
   * @return {@code true} if {@link IdeContext#getIdeRoot() IDE_ROOT} is required for this commandlet, {@code false} otherwise.
141
   */
142
  public boolean isIdeRootRequired() {
143

144
    return true;
2 ✔
145
  }
146

147
  /**
148
   * @return {@code true} to suppress the {@link com.devonfw.tools.ide.step.StepImpl#logSummary(boolean) step summary success message}.
149
   */
150
  public boolean isSuppressStepSuccess() {
151

152
    return false;
2 ✔
153
  }
154

155
  /**
156
   * @return {@code true} if the output of this commandlet is (potentially) processed automatically from outside, {@code false} otherwise. For example
157
   *     {@link CompleteCommandlet} logs the suggestions for auto-completion to a bash script. Also, the {@link EnvironmentCommandlet} logs the environment
158
   *     variables for the {@code ide} wrapper script. In such scenarios these logs shall not be spammed with warnings like "IDE_ROOT is not set" that would
159
   *     break the processing of the output.
160
   */
161
  public boolean isProcessableOutput() {
162

163
    return false;
2 ✔
164
  }
165

166
  /**
167
   * @return {@code true} to write a logfile (unless disabled via {@link com.devonfw.tools.ide.variable.IdeVariables#IDE_WRITE_LOGFILE}), {@code false}
168
   *     otherwise.
169
   */
170
  public boolean isWriteLogFile() {
171
    return !isProcessableOutput();
×
172
  }
173

174
  /**
175
   * Runs this {@link AbstractCommandlet}.
176
   */
177
  public final void run() {
178

179
    if (this.context != null) { // for ContextCommandlet we do not have a context yet
3 ✔
180
      ((AbstractIdeContext) this.context).configureJavaUtilLogging(this);
5 ✔
181
    }
182
    doRun();
2 ✔
183
  }
1 ✔
184

185
  protected abstract void doRun();
186

187
  /**
188
   * Provide additional usage help of this {@link AbstractCommandlet} to the user.
189
   *
190
   * @param bundle the {@link NlsBundle} to get I18N messages from.
191
   */
192
  public void printHelp(NlsBundle bundle) {
193

194
  }
1 ✔
195

196
  @Override
197
  public String toString() {
198

199
    return getClass().getSimpleName() + "[" + getName() + "]";
7 ✔
200
  }
201

202
  /**
203
   * @return the {@link AbstractToolCommandlet} set in a {@link Property} of this commandlet used for auto-completion of a {@link VersionIdentifier} or
204
   *     {@link com.devonfw.tools.ide.tool.plugin.ToolPluginDescriptor}, otherwise {@code null} if not exists or not configured.
205
   */
206
  public AbstractToolCommandlet getToolForCompletion() {
207
    return null;
2 ✔
208
  }
209
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc