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

devonfw / IDEasy / 26884978447

03 Jun 2026 12:33PM UTC coverage: 71.028% (-0.02%) from 71.052%
26884978447

Pull #1913

github

web-flow
Merge 529b3ff70 into 8b8989cb3
Pull Request #1913: 1719: Rust Integration

4536 of 7078 branches covered (64.09%)

Branch coverage included in aggregate %.

11765 of 15872 relevant lines covered (74.12%)

3.14 hits per line

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

90.69
cli/src/main/java/com/devonfw/tools/ide/commandlet/CommandletManagerImpl.java
1
package com.devonfw.tools.ide.commandlet;
2

3
import java.util.Collection;
4
import java.util.Collections;
5
import java.util.HashMap;
6
import java.util.Iterator;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.NoSuchElementException;
10

11
import com.devonfw.tools.ide.tool.inso.Inso;
12

13
import org.slf4j.Logger;
14
import org.slf4j.LoggerFactory;
15

16
import com.devonfw.tools.ide.cli.CliArgument;
17
import com.devonfw.tools.ide.cli.CliArguments;
18
import com.devonfw.tools.ide.completion.CompletionCandidateCollector;
19
import com.devonfw.tools.ide.context.IdeContext;
20
import com.devonfw.tools.ide.git.repository.RepositoryCommandlet;
21
import com.devonfw.tools.ide.property.KeywordProperty;
22
import com.devonfw.tools.ide.property.Property;
23
import com.devonfw.tools.ide.tool.androidstudio.AndroidStudio;
24
import com.devonfw.tools.ide.tool.aws.Aws;
25
import com.devonfw.tools.ide.tool.az.Azure;
26
import com.devonfw.tools.ide.tool.cdk.Cdk;
27
import com.devonfw.tools.ide.tool.claude.Claude;
28
import com.devonfw.tools.ide.tool.copilot.Copilot;
29
import com.devonfw.tools.ide.tool.corepack.Corepack;
30
import com.devonfw.tools.ide.tool.docker.Docker;
31
import com.devonfw.tools.ide.tool.dotnet.DotNet;
32
import com.devonfw.tools.ide.tool.eclipse.Eclipse;
33
import com.devonfw.tools.ide.tool.gcviewer.GcViewer;
34
import com.devonfw.tools.ide.tool.gh.Gh;
35
import com.devonfw.tools.ide.tool.go.Go;
36
import com.devonfw.tools.ide.tool.graalvm.GraalVm;
37
import com.devonfw.tools.ide.tool.gradle.Gradle;
38
import com.devonfw.tools.ide.tool.gui.Gui;
39
import com.devonfw.tools.ide.tool.helm.Helm;
40
import com.devonfw.tools.ide.tool.intellij.Intellij;
41
import com.devonfw.tools.ide.tool.jasypt.Jasypt;
42
import com.devonfw.tools.ide.tool.java.Java;
43
import com.devonfw.tools.ide.tool.jmc.Jmc;
44
import com.devonfw.tools.ide.tool.kotlinc.Kotlinc;
45
import com.devonfw.tools.ide.tool.kotlinc.KotlincNative;
46
import com.devonfw.tools.ide.tool.kubectl.KubeCtl;
47
import com.devonfw.tools.ide.tool.lazydocker.LazyDocker;
48
import com.devonfw.tools.ide.tool.mvn.Mvn;
49
import com.devonfw.tools.ide.tool.msvc.Msvc;
50
import com.devonfw.tools.ide.tool.nest.Nest;
51
import com.devonfw.tools.ide.tool.ng.Ng;
52
import com.devonfw.tools.ide.tool.node.Node;
53
import com.devonfw.tools.ide.tool.npm.Npm;
54
import com.devonfw.tools.ide.tool.oc.Oc;
55
import com.devonfw.tools.ide.tool.pgadmin.PgAdmin;
56
import com.devonfw.tools.ide.tool.pip.Pip;
57
import com.devonfw.tools.ide.tool.pycharm.Pycharm;
58
import com.devonfw.tools.ide.tool.python.Python;
59
import com.devonfw.tools.ide.tool.quarkus.Quarkus;
60
import com.devonfw.tools.ide.tool.rust.Rust;
61
import com.devonfw.tools.ide.tool.sonar.Sonar;
62
import com.devonfw.tools.ide.tool.spring.Spring;
63
import com.devonfw.tools.ide.tool.squirrelsql.SquirrelSql;
64
import com.devonfw.tools.ide.tool.task.Task;
65
import com.devonfw.tools.ide.tool.terraform.Terraform;
66
import com.devonfw.tools.ide.tool.tomcat.Tomcat;
67
import com.devonfw.tools.ide.tool.uv.Uv;
68
import com.devonfw.tools.ide.tool.vscode.Vscode;
69
import com.devonfw.tools.ide.tool.yarn.Yarn;
70

71
/**
72
 * Implementation of {@link CommandletManager}.
73
 */
74
public class CommandletManagerImpl implements CommandletManager {
75

76
  private static final Logger LOG = LoggerFactory.getLogger(CommandletManagerImpl.class);
4✔
77

78
  private final IdeContext context;
79

80
  private final Map<Class<? extends Commandlet>, Commandlet> commandletTypeMap;
81

82
  private final Map<String, Commandlet> commandletNameMap;
83

84
  private final Map<String, Commandlet> firstKeywordMap;
85

86
  private final Collection<Commandlet> commandlets;
87

88
  /**
89
   * The constructor.
90
   *
91
   * @param context the {@link IdeContext}.
92
   */
93
  public CommandletManagerImpl(IdeContext context) {
94

95
    super();
2✔
96
    this.context = context;
3✔
97
    this.commandletTypeMap = new HashMap<>();
5✔
98
    this.commandletNameMap = new HashMap<>();
5✔
99
    this.firstKeywordMap = new HashMap<>();
5✔
100
    this.commandlets = Collections.unmodifiableCollection(this.commandletTypeMap.values());
6✔
101
    add(new HelpCommandlet(context));
6✔
102
    add(new EnvironmentCommandlet(context));
6✔
103
    add(new CompleteCommandlet(context));
6✔
104
    add(new ShellCommandlet(context));
6✔
105
    add(new InstallCommandlet(context));
6✔
106
    add(new VersionSetCommandlet(context));
6✔
107
    add(new VersionGetCommandlet(context));
6✔
108
    add(new VersionListCommandlet(context));
6✔
109
    add(new EditionGetCommandlet(context));
6✔
110
    add(new EditionSetCommandlet(context));
6✔
111
    add(new EditionListCommandlet(context));
6✔
112
    add(new VersionCommandlet(context));
6✔
113
    add(new StatusCommandlet(context));
6✔
114
    add(new RepositoryCommandlet(context));
6✔
115
    add(new UninstallCommandlet(context));
6✔
116
    add(new LnCommandlet(context));
6✔
117
    add(new UpdateCommandlet(context));
6✔
118
    add(new UpgradeSettingsCommandlet(context));
6✔
119
    add(new CreateCommandlet(context));
6✔
120
    add(new BuildCommandlet(context));
6✔
121
    add(new InstallPluginCommandlet(context));
6✔
122
    add(new UninstallPluginCommandlet(context));
6✔
123
    add(new UpgradeCommandlet(context));
6✔
124
    add(new TruststoreCommandlet(context));
6✔
125
    add(new Gh(context));
6✔
126
    add(new Helm(context));
6✔
127
    add(new Java(context));
6✔
128
    add(new Ng(context));
6✔
129
    add(new Node(context));
6✔
130
    add(new Npm(context));
6✔
131
    add(new Mvn(context));
6✔
132
    add(new Msvc(context));
6✔
133
    add(new GcViewer(context));
6✔
134
    add(new Gradle(context));
6✔
135
    add(new Eclipse(context));
6✔
136
    add(new Terraform(context));
6✔
137
    add(new Oc(context));
6✔
138
    add(new Quarkus(context));
6✔
139
    add(new Rust(context));
6✔
140
    add(new Kotlinc(context));
6✔
141
    add(new KotlincNative(context));
6✔
142
    add(new KubeCtl(context));
6✔
143
    add(new Tomcat(context));
6✔
144
    add(new Task(context));
6✔
145
    add(new Vscode(context));
6✔
146
    add(new Azure(context));
6✔
147
    add(new Aws(context));
6✔
148
    add(new Jmc(context));
6✔
149
    add(new DotNet(context));
6✔
150
    add(new Inso(context));
6✔
151
    add(new Intellij(context));
6✔
152
    add(new Jasypt(context));
6✔
153
    add(new Docker(context));
6✔
154
    add(new Sonar(context));
6✔
155
    add(new AndroidStudio(context));
6✔
156
    add(new GraalVm(context));
6✔
157
    add(new PgAdmin(context));
6✔
158
    add(new LazyDocker(context));
6✔
159
    add(new Python(context));
6✔
160
    add(new Pycharm(context));
6✔
161
    add(new Spring(context));
6✔
162
    add(new Uv(context));
6✔
163
    add(new Yarn(context));
6✔
164
    add(new Copilot(context));
6✔
165
    add(new Corepack(context));
6✔
166
    add(new Pip(context));
6✔
167
    add(new Go(context));
6✔
168
    add(new Gui(context));
6✔
169
    add(new SquirrelSql(context));
6✔
170
    add(new Nest(context));
6✔
171
    add(new Cdk(context));
6✔
172
    add(new Claude(context));
6✔
173
  }
1✔
174

175
  /**
176
   * @param commandlet the {@link Commandlet} to add.
177
   */
178
  protected void add(Commandlet commandlet) {
179

180
    boolean hasRequiredProperty = false;
2✔
181
    List<Property<?>> properties = commandlet.getProperties();
3✔
182
    int propertyCount = properties.size();
3✔
183
    KeywordProperty keyword = commandlet.getFirstKeyword();
3✔
184
    if (keyword != null) {
2!
185
      String name = keyword.getName();
3✔
186
      registerKeyword(name, commandlet);
4✔
187
      String optionName = keyword.getOptionName();
3✔
188
      if (!optionName.equals(name)) {
4✔
189
        registerKeyword(optionName, commandlet);
4✔
190
      }
191
      String alias = keyword.getAlias();
3✔
192
      if (alias != null) {
2✔
193
        registerKeyword(alias, commandlet);
4✔
194
      }
195
    }
196
    for (int i = 0; i < propertyCount; i++) {
5!
197
      Property<?> property = properties.get(i);
5✔
198
      if (property.isRequired()) {
3!
199
        hasRequiredProperty = true;
2✔
200
        break;
1✔
201
      }
202
    }
203
    if (!hasRequiredProperty) {
2!
204
      throw new IllegalStateException("Commandlet " + commandlet + " must have at least one mandatory property!");
×
205
    }
206
    this.commandletTypeMap.put(commandlet.getClass(), commandlet);
7✔
207
    Commandlet duplicate = this.commandletNameMap.put(commandlet.getName(), commandlet);
8✔
208
    if (duplicate != null) {
2!
209
      throw new IllegalStateException("Commandlet " + commandlet + " has the same name as " + duplicate);
×
210
    }
211
  }
1✔
212

213
  private void registerKeyword(String keyword, Commandlet commandlet) {
214

215
    Commandlet duplicate = this.firstKeywordMap.putIfAbsent(keyword, commandlet);
7✔
216
    if (duplicate != null) {
2!
217
      LOG.debug("Duplicate keyword {} already used by {} so it cannot be associated also with {}", keyword, duplicate, commandlet);
×
218
    }
219
  }
1✔
220

221
  @Override
222
  public Collection<Commandlet> getCommandlets() {
223

224
    return this.commandlets;
3✔
225
  }
226

227
  @Override
228
  public <C extends Commandlet> C getCommandlet(Class<C> commandletType) {
229

230
    Commandlet commandlet = this.commandletTypeMap.get(commandletType);
6✔
231
    if (commandlet == null) {
2!
232
      throw new IllegalStateException("Commandlet for type " + commandletType + " is not registered!");
×
233
    }
234
    return commandletType.cast(commandlet);
5✔
235
  }
236

237
  @Override
238
  public Commandlet getCommandlet(String name) {
239

240
    return this.commandletNameMap.get(name);
6✔
241
  }
242

243
  @Override
244
  public Commandlet getCommandletByFirstKeyword(String keyword) {
245

246
    return this.firstKeywordMap.get(keyword);
6✔
247
  }
248

249
  @Override
250
  public Iterator<Commandlet> findCommandlet(CliArguments arguments, CompletionCandidateCollector collector) {
251

252
    CliArgument current = arguments.current();
3✔
253
    if (current.isEnd()) {
3!
254
      return Collections.emptyIterator();
×
255
    }
256
    String keyword = current.get();
3✔
257
    Commandlet commandlet = getCommandletByFirstKeyword(keyword);
4✔
258
    if ((commandlet == null) && (collector == null)) {
4✔
259
      return Collections.emptyIterator();
2✔
260
    }
261
    return new CommandletFinder(commandlet, arguments.copy(), collector);
9✔
262
  }
263

264
  private final class CommandletFinder implements Iterator<Commandlet> {
1✔
265

266
    private final Commandlet firstCandidate;
267

268
    private final Iterator<Commandlet> commandletIterator;
269

270
    private final CliArguments arguments;
271

272
    private final CompletionCandidateCollector collector;
273

274
    private Commandlet next;
275

276
    private CommandletFinder(Commandlet firstCandidate, CliArguments arguments, CompletionCandidateCollector collector) {
8✔
277

278
      this.firstCandidate = firstCandidate;
3✔
279
      this.commandletIterator = getCommandlets().iterator();
5✔
280
      this.arguments = arguments;
3✔
281
      this.collector = collector;
3✔
282
      if (isSuitable(firstCandidate)) {
4✔
283
        this.next = firstCandidate;
4✔
284
      } else {
285
        this.next = findNext();
4✔
286
      }
287
    }
1✔
288

289
    @Override
290
    public boolean hasNext() {
291

292
      return this.next != null;
7✔
293
    }
294

295
    @Override
296
    public Commandlet next() {
297

298
      if (this.next == null) {
3!
299
        throw new NoSuchElementException();
×
300
      }
301
      Commandlet result = this.next;
3✔
302
      this.next = findNext();
4✔
303
      return result;
2✔
304
    }
305

306
    private boolean isSuitable(Commandlet commandlet) {
307

308
      return (commandlet != null) && (!commandlet.isIdeHomeRequired() || (context.getIdeHome() != null));
14✔
309
    }
310

311
    private Commandlet findNext() {
312

313
      while (this.commandletIterator.hasNext()) {
4✔
314
        Commandlet cmd = this.commandletIterator.next();
5✔
315
        if ((cmd != this.firstCandidate) && isSuitable(cmd)) {
8✔
316
          List<Property<?>> properties = cmd.getProperties();
3✔
317
          // validation should already be done in add method and could be removed here...
318
          if (properties.isEmpty()) {
3!
319
            assert false : cmd.getClass().getSimpleName() + " has no properties!";
×
320
          } else {
321
            Property<?> property = properties.getFirst();
4✔
322
            if (property instanceof KeywordProperty) {
3!
323
              boolean matches = property.apply(arguments.copy(), context, cmd, this.collector);
12✔
324
              if (matches) {
2✔
325
                return cmd;
2✔
326
              }
327
            } else {
1✔
328
              assert false : cmd.getClass().getSimpleName() + " is invalid as first property must be keyword property but is " + property;
×
329
            }
330
          }
331
        }
332
      }
1✔
333
      return null;
2✔
334
    }
335
  }
336
}
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