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

devonfw / IDEasy / 29005436339

09 Jul 2026 08:38AM UTC coverage: 72.178% (-0.002%) from 72.18%
29005436339

Pull #2023

github

web-flow
Merge 7833fc0e5 into 8ed88cfeb
Pull Request #2023: #1594: Implement release commandlet

4894 of 7496 branches covered (65.29%)

Branch coverage included in aggregate %.

12641 of 16798 relevant lines covered (75.25%)

3.19 hits per line

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

91.83
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 org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
13

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

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

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

80
  private final IdeContext context;
81

82
  private final Map<Class<? extends Commandlet>, Commandlet> commandletTypeMap;
83

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

86
  private final Map<String, Commandlet> firstKeywordMap;
87

88
  private final Collection<Commandlet> commandlets;
89

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

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

181
  /**
182
   * @param commandlet the {@link Commandlet} to add.
183
   */
184
  protected void add(Commandlet commandlet) {
185

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

219
  private void registerKeyword(String keyword, Commandlet commandlet) {
220

221
    Commandlet duplicate = this.firstKeywordMap.putIfAbsent(keyword, commandlet);
7✔
222
    if (duplicate != null) {
2!
223
      LOG.debug("Duplicate keyword {} already used by {} so it cannot be associated also with {}", keyword, duplicate, commandlet);
×
224
    }
225
  }
1✔
226

227
  @Override
228
  public Collection<Commandlet> getCommandlets() {
229

230
    return this.commandlets;
3✔
231
  }
232

233
  @Override
234
  public <C extends Commandlet> C getCommandlet(Class<C> commandletType) {
235

236
    Commandlet commandlet = this.commandletTypeMap.get(commandletType);
6✔
237
    if (commandlet == null) {
2!
238
      throw new IllegalStateException("Commandlet for type " + commandletType + " is not registered!");
×
239
    }
240
    return commandletType.cast(commandlet);
5✔
241
  }
242

243
  @Override
244
  public Commandlet getCommandlet(String name) {
245

246
    return this.commandletNameMap.get(name);
6✔
247
  }
248

249
  @Override
250
  public Commandlet getCommandletByFirstKeyword(String keyword) {
251

252
    return this.firstKeywordMap.get(keyword);
6✔
253
  }
254

255
  @Override
256
  public Iterator<Commandlet> findCommandlet(CliArguments arguments, CompletionCandidateCollector collector) {
257

258
    CliArgument current = arguments.current();
3✔
259
    if (current.isEnd()) {
3✔
260
      return Collections.emptyIterator();
2✔
261
    }
262
    String keyword = current.get();
3✔
263
    Commandlet commandlet = getCommandletByFirstKeyword(keyword);
4✔
264
    if ((commandlet == null) && (collector == null)) {
4✔
265
      return Collections.emptyIterator();
2✔
266
    }
267
    return new CommandletFinder(commandlet, arguments.copy(), collector);
9✔
268
  }
269

270
  private final class CommandletFinder implements Iterator<Commandlet> {
1✔
271

272
    private final Commandlet firstCandidate;
273

274
    private final Iterator<Commandlet> commandletIterator;
275

276
    private final CliArguments arguments;
277

278
    private final CompletionCandidateCollector collector;
279

280
    private Commandlet next;
281

282
    private CommandletFinder(Commandlet firstCandidate, CliArguments arguments, CompletionCandidateCollector collector) {
8✔
283

284
      this.firstCandidate = firstCandidate;
3✔
285
      this.commandletIterator = getCommandlets().iterator();
5✔
286
      this.arguments = arguments;
3✔
287
      this.collector = collector;
3✔
288
      if (isSuitable(firstCandidate)) {
4✔
289
        this.next = firstCandidate;
4✔
290
      } else {
291
        this.next = findNext();
4✔
292
      }
293
    }
1✔
294

295
    @Override
296
    public boolean hasNext() {
297

298
      return this.next != null;
7✔
299
    }
300

301
    @Override
302
    public Commandlet next() {
303

304
      if (this.next == null) {
3!
305
        throw new NoSuchElementException();
×
306
      }
307
      Commandlet result = this.next;
3✔
308
      this.next = findNext();
4✔
309
      return result;
2✔
310
    }
311

312
    private boolean isSuitable(Commandlet commandlet) {
313

314
      return (commandlet != null) && (!commandlet.isIdeHomeRequired() || (context.getIdeHome() != null));
14✔
315
    }
316

317
    private Commandlet findNext() {
318

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