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

devonfw / IDEasy / 18883196970

28 Oct 2025 05:12PM UTC coverage: 68.864% (+0.3%) from 68.544%
18883196970

push

github

web-flow
#1492: Add Spring-Boot-CLI Commandlet (#1496)

Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>

3484 of 5543 branches covered (62.85%)

Branch coverage included in aggregate %.

9116 of 12754 relevant lines covered (71.48%)

3.14 hits per line

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

89.95
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.cli.CliArgument;
12
import com.devonfw.tools.ide.cli.CliArguments;
13
import com.devonfw.tools.ide.completion.CompletionCandidateCollector;
14
import com.devonfw.tools.ide.context.IdeContext;
15
import com.devonfw.tools.ide.git.repository.RepositoryCommandlet;
16
import com.devonfw.tools.ide.property.KeywordProperty;
17
import com.devonfw.tools.ide.property.Property;
18
import com.devonfw.tools.ide.tool.androidstudio.AndroidStudio;
19
import com.devonfw.tools.ide.tool.aws.Aws;
20
import com.devonfw.tools.ide.tool.az.Azure;
21
import com.devonfw.tools.ide.tool.corepack.Corepack;
22
import com.devonfw.tools.ide.tool.docker.Docker;
23
import com.devonfw.tools.ide.tool.dotnet.DotNet;
24
import com.devonfw.tools.ide.tool.eclipse.Eclipse;
25
import com.devonfw.tools.ide.tool.gcviewer.GcViewer;
26
import com.devonfw.tools.ide.tool.gh.Gh;
27
import com.devonfw.tools.ide.tool.graalvm.GraalVm;
28
import com.devonfw.tools.ide.tool.gradle.Gradle;
29
import com.devonfw.tools.ide.tool.helm.Helm;
30
import com.devonfw.tools.ide.tool.intellij.Intellij;
31
import com.devonfw.tools.ide.tool.jasypt.Jasypt;
32
import com.devonfw.tools.ide.tool.java.Java;
33
import com.devonfw.tools.ide.tool.jmc.Jmc;
34
import com.devonfw.tools.ide.tool.kotlinc.Kotlinc;
35
import com.devonfw.tools.ide.tool.kotlinc.KotlincNative;
36
import com.devonfw.tools.ide.tool.kubectl.KubeCtl;
37
import com.devonfw.tools.ide.tool.lazydocker.LazyDocker;
38
import com.devonfw.tools.ide.tool.mvn.Mvn;
39
import com.devonfw.tools.ide.tool.ng.Ng;
40
import com.devonfw.tools.ide.tool.node.Node;
41
import com.devonfw.tools.ide.tool.npm.Npm;
42
import com.devonfw.tools.ide.tool.oc.Oc;
43
import com.devonfw.tools.ide.tool.pgadmin.PgAdmin;
44
import com.devonfw.tools.ide.tool.pycharm.Pycharm;
45
import com.devonfw.tools.ide.tool.python.Python;
46
import com.devonfw.tools.ide.tool.quarkus.Quarkus;
47
import com.devonfw.tools.ide.tool.sonar.Sonar;
48
import com.devonfw.tools.ide.tool.spring.Spring;
49
import com.devonfw.tools.ide.tool.terraform.Terraform;
50
import com.devonfw.tools.ide.tool.tomcat.Tomcat;
51
import com.devonfw.tools.ide.tool.uv.Uv;
52
import com.devonfw.tools.ide.tool.vscode.Vscode;
53
import com.devonfw.tools.ide.tool.yarn.Yarn;
54

55
/**
56
 * Implementation of {@link CommandletManager}.
57
 */
58
public class CommandletManagerImpl implements CommandletManager {
59

60
  private final IdeContext context;
61

62
  private final Map<Class<? extends Commandlet>, Commandlet> commandletTypeMap;
63

64
  private final Map<String, Commandlet> commandletNameMap;
65

66
  private final Map<String, Commandlet> firstKeywordMap;
67

68
  private final Collection<Commandlet> commandlets;
69

70
  /**
71
   * The constructor.
72
   *
73
   * @param context the {@link IdeContext}.
74
   */
75
  public CommandletManagerImpl(IdeContext context) {
76

77
    super();
2✔
78
    this.context = context;
3✔
79
    this.commandletTypeMap = new HashMap<>();
5✔
80
    this.commandletNameMap = new HashMap<>();
5✔
81
    this.firstKeywordMap = new HashMap<>();
5✔
82
    this.commandlets = Collections.unmodifiableCollection(this.commandletTypeMap.values());
6✔
83
    add(new HelpCommandlet(context));
6✔
84
    add(new EnvironmentCommandlet(context));
6✔
85
    add(new CompleteCommandlet(context));
6✔
86
    add(new ShellCommandlet(context));
6✔
87
    add(new InstallCommandlet(context));
6✔
88
    add(new VersionSetCommandlet(context));
6✔
89
    add(new VersionGetCommandlet(context));
6✔
90
    add(new VersionListCommandlet(context));
6✔
91
    add(new EditionGetCommandlet(context));
6✔
92
    add(new EditionSetCommandlet(context));
6✔
93
    add(new EditionListCommandlet(context));
6✔
94
    add(new VersionCommandlet(context));
6✔
95
    add(new StatusCommandlet(context));
6✔
96
    add(new RepositoryCommandlet(context));
6✔
97
    add(new UninstallCommandlet(context));
6✔
98
    add(new UpdateCommandlet(context));
6✔
99
    add(new UpgradeSettingsCommandlet(context));
6✔
100
    add(new CreateCommandlet(context));
6✔
101
    add(new BuildCommandlet(context));
6✔
102
    add(new InstallPluginCommandlet(context));
6✔
103
    add(new UninstallPluginCommandlet(context));
6✔
104
    add(new UpgradeCommandlet(context));
6✔
105
    add(new Gh(context));
6✔
106
    add(new Helm(context));
6✔
107
    add(new Java(context));
6✔
108
    add(new Ng(context));
6✔
109
    add(new Node(context));
6✔
110
    add(new Npm(context));
6✔
111
    add(new Mvn(context));
6✔
112
    add(new GcViewer(context));
6✔
113
    add(new Gradle(context));
6✔
114
    add(new Eclipse(context));
6✔
115
    add(new Terraform(context));
6✔
116
    add(new Oc(context));
6✔
117
    add(new Quarkus(context));
6✔
118
    add(new Kotlinc(context));
6✔
119
    add(new KotlincNative(context));
6✔
120
    add(new KubeCtl(context));
6✔
121
    add(new Tomcat(context));
6✔
122
    add(new Vscode(context));
6✔
123
    add(new Azure(context));
6✔
124
    add(new Aws(context));
6✔
125
    add(new Jmc(context));
6✔
126
    add(new DotNet(context));
6✔
127
    add(new Intellij(context));
6✔
128
    add(new Jasypt(context));
6✔
129
    add(new Docker(context));
6✔
130
    add(new Sonar(context));
6✔
131
    add(new AndroidStudio(context));
6✔
132
    add(new GraalVm(context));
6✔
133
    add(new PgAdmin(context));
6✔
134
    add(new LazyDocker(context));
6✔
135
    add(new Python(context));
6✔
136
    add(new Pycharm(context));
6✔
137
    add(new Spring(context));
6✔
138
    add(new Uv(context));
6✔
139
    add(new Yarn(context));
6✔
140
    add(new Corepack(context));
6✔
141
  }
1✔
142

143
  /**
144
   * @param commandlet the {@link Commandlet} to add.
145
   */
146
  protected void add(Commandlet commandlet) {
147

148
    boolean hasRequiredProperty = false;
2✔
149
    List<Property<?>> properties = commandlet.getProperties();
3✔
150
    int propertyCount = properties.size();
3✔
151
    KeywordProperty keyword = commandlet.getFirstKeyword();
3✔
152
    if (keyword != null) {
2!
153
      String name = keyword.getName();
3✔
154
      registerKeyword(name, commandlet);
4✔
155
      String optionName = keyword.getOptionName();
3✔
156
      if (!optionName.equals(name)) {
4✔
157
        registerKeyword(optionName, commandlet);
4✔
158
      }
159
      String alias = keyword.getAlias();
3✔
160
      if (alias != null) {
2✔
161
        registerKeyword(alias, commandlet);
4✔
162
      }
163
    }
164
    for (int i = 0; i < propertyCount; i++) {
5!
165
      Property<?> property = properties.get(i);
5✔
166
      if (property.isRequired()) {
3!
167
        hasRequiredProperty = true;
2✔
168
        break;
1✔
169
      }
170
    }
171
    if (!hasRequiredProperty) {
2!
172
      throw new IllegalStateException("Commandlet " + commandlet + " must have at least one mandatory property!");
×
173
    }
174
    this.commandletTypeMap.put(commandlet.getClass(), commandlet);
7✔
175
    Commandlet duplicate = this.commandletNameMap.put(commandlet.getName(), commandlet);
8✔
176
    if (duplicate != null) {
2!
177
      throw new IllegalStateException("Commandlet " + commandlet + " has the same name as " + duplicate);
×
178
    }
179
  }
1✔
180

181
  private void registerKeyword(String keyword, Commandlet commandlet) {
182

183
    Commandlet duplicate = this.firstKeywordMap.putIfAbsent(keyword, commandlet);
7✔
184
    if (duplicate != null) {
2!
185
      this.context.debug("Duplicate keyword {} already used by {} so it cannot be associated also with {}", keyword, duplicate, commandlet);
×
186
    }
187
  }
1✔
188

189
  @Override
190
  public Collection<Commandlet> getCommandlets() {
191

192
    return this.commandlets;
3✔
193
  }
194

195
  @Override
196
  public <C extends Commandlet> C getCommandlet(Class<C> commandletType) {
197

198
    Commandlet commandlet = this.commandletTypeMap.get(commandletType);
6✔
199
    if (commandlet == null) {
2!
200
      throw new IllegalStateException("Commandlet for type " + commandletType + " is not registered!");
×
201
    }
202
    return commandletType.cast(commandlet);
5✔
203
  }
204

205
  @Override
206
  public Commandlet getCommandlet(String name) {
207

208
    return this.commandletNameMap.get(name);
6✔
209
  }
210

211
  @Override
212
  public Commandlet getCommandletByFirstKeyword(String keyword) {
213

214
    return this.firstKeywordMap.get(keyword);
6✔
215
  }
216

217
  @Override
218
  public Iterator<Commandlet> findCommandlet(CliArguments arguments, CompletionCandidateCollector collector) {
219

220
    CliArgument current = arguments.current();
3✔
221
    if (current.isEnd()) {
3!
222
      return Collections.emptyIterator();
×
223
    }
224
    String keyword = current.get();
3✔
225
    Commandlet commandlet = getCommandletByFirstKeyword(keyword);
4✔
226
    if ((commandlet == null) && (collector == null)) {
4✔
227
      return Collections.emptyIterator();
2✔
228
    }
229
    return new CommandletFinder(commandlet, arguments.copy(), collector);
9✔
230
  }
231

232
  private final class CommandletFinder implements Iterator<Commandlet> {
1✔
233

234
    private final Commandlet firstCandidate;
235

236
    private final Iterator<Commandlet> commandletIterator;
237

238
    private final CliArguments arguments;
239

240
    private final CompletionCandidateCollector collector;
241

242
    private Commandlet next;
243

244
    private CommandletFinder(Commandlet firstCandidate, CliArguments arguments, CompletionCandidateCollector collector) {
5✔
245

246
      this.firstCandidate = firstCandidate;
3✔
247
      this.commandletIterator = getCommandlets().iterator();
5✔
248
      this.arguments = arguments;
3✔
249
      this.collector = collector;
3✔
250
      if (isSuitable(firstCandidate)) {
4✔
251
        this.next = firstCandidate;
4✔
252
      } else {
253
        this.next = findNext();
4✔
254
      }
255
    }
1✔
256

257
    @Override
258
    public boolean hasNext() {
259

260
      return this.next != null;
7✔
261
    }
262

263
    @Override
264
    public Commandlet next() {
265

266
      if (this.next == null) {
3!
267
        throw new NoSuchElementException();
×
268
      }
269
      Commandlet result = this.next;
3✔
270
      this.next = findNext();
4✔
271
      return result;
2✔
272
    }
273

274
    private boolean isSuitable(Commandlet commandlet) {
275

276
      return (commandlet != null) && (!commandlet.isIdeHomeRequired() || (context.getIdeHome() != null));
14✔
277
    }
278

279
    private Commandlet findNext() {
280

281
      while (this.commandletIterator.hasNext()) {
4✔
282
        Commandlet cmd = this.commandletIterator.next();
5✔
283
        if ((cmd != this.firstCandidate) && isSuitable(cmd)) {
8✔
284
          List<Property<?>> properties = cmd.getProperties();
3✔
285
          // validation should already be done in add method and could be removed here...
286
          if (properties.isEmpty()) {
3!
287
            assert false : cmd.getClass().getSimpleName() + " has no properties!";
×
288
          } else {
289
            Property<?> property = properties.get(0);
5✔
290
            if (property instanceof KeywordProperty) {
3!
291
              boolean matches = property.apply(arguments.copy(), context, cmd, this.collector);
12✔
292
              if (matches) {
2✔
293
                return cmd;
2✔
294
              }
295
            } else {
1✔
296
              assert false : cmd.getClass().getSimpleName() + " is invalid as first property must be keyword property but is " + property;
×
297
            }
298
          }
299
        }
300
      }
1✔
301
      return null;
2✔
302
    }
303
  }
304
}
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