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

devonfw / IDEasy / 9778043214

03 Jul 2024 12:41PM UTC coverage: 60.631% (+0.5%) from 60.142%
9778043214

push

github

web-flow
#36: Tool Commandlet for tomcat (#250)

1939 of 3515 branches covered (55.16%)

Branch coverage included in aggregate %.

5133 of 8149 relevant lines covered (62.99%)

2.76 hits per line

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

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

3
import com.devonfw.tools.ide.context.IdeContext;
4
import com.devonfw.tools.ide.property.KeywordProperty;
5
import com.devonfw.tools.ide.property.Property;
6
import com.devonfw.tools.ide.tool.aws.Aws;
7
import com.devonfw.tools.ide.tool.az.Azure;
8
import com.devonfw.tools.ide.tool.cobigen.Cobigen;
9
import com.devonfw.tools.ide.tool.docker.Docker;
10
import com.devonfw.tools.ide.tool.dotnet.DotNet;
11
import com.devonfw.tools.ide.tool.eclipse.Eclipse;
12
import com.devonfw.tools.ide.tool.gcviewer.GcViewer;
13
import com.devonfw.tools.ide.tool.gh.Gh;
14
import com.devonfw.tools.ide.tool.graalvm.GraalVm;
15
import com.devonfw.tools.ide.tool.gradle.Gradle;
16
import com.devonfw.tools.ide.tool.helm.Helm;
17
import com.devonfw.tools.ide.tool.intellij.Intellij;
18
import com.devonfw.tools.ide.tool.jasypt.Jasypt;
19
import com.devonfw.tools.ide.tool.java.Java;
20
import com.devonfw.tools.ide.tool.jmc.Jmc;
21
import com.devonfw.tools.ide.tool.kotlinc.Kotlinc;
22
import com.devonfw.tools.ide.tool.kotlinc.KotlincNative;
23
import com.devonfw.tools.ide.tool.lazydocker.LazyDocker;
24
import com.devonfw.tools.ide.tool.mvn.Mvn;
25
import com.devonfw.tools.ide.tool.node.Node;
26
import com.devonfw.tools.ide.tool.npm.Npm;
27
import com.devonfw.tools.ide.tool.oc.Oc;
28
import com.devonfw.tools.ide.tool.pgadmin.PgAdmin;
29
import com.devonfw.tools.ide.tool.quarkus.Quarkus;
30
import com.devonfw.tools.ide.tool.sonar.Sonar;
31
import com.devonfw.tools.ide.tool.terraform.Terraform;
32
import com.devonfw.tools.ide.tool.tomcat.Tomcat;
33
import com.devonfw.tools.ide.tool.vscode.Vscode;
34

35
import java.util.Collection;
36
import java.util.Collections;
37
import java.util.HashMap;
38
import java.util.List;
39
import java.util.Map;
40

41
/**
42
 * Implementation of {@link CommandletManager}.
43
 */
44
public final class CommandletManagerImpl implements CommandletManager {
45

46
  private final Map<Class<? extends Commandlet>, Commandlet> commandletTypeMap;
47

48
  private final Map<String, Commandlet> commandletNameMap;
49

50
  private final Map<String, Commandlet> firstKeywordMap;
51

52
  private final Collection<Commandlet> commandlets;
53

54
  /**
55
   * The constructor.
56
   *
57
   * @param context the {@link IdeContext}.
58
   */
59
  public CommandletManagerImpl(IdeContext context) {
60

61
    super();
2✔
62
    this.commandletTypeMap = new HashMap<>();
5✔
63
    this.commandletNameMap = new HashMap<>();
5✔
64
    this.firstKeywordMap = new HashMap<>();
5✔
65
    this.commandlets = Collections.unmodifiableCollection(this.commandletTypeMap.values());
6✔
66
    add(new HelpCommandlet(context));
6✔
67
    add(new EnvironmentCommandlet(context));
6✔
68
    add(new CompleteCommandlet(context));
6✔
69
    add(new ShellCommandlet(context));
6✔
70
    add(new InstallCommandlet(context));
6✔
71
    add(new VersionSetCommandlet(context));
6✔
72
    add(new VersionGetCommandlet(context));
6✔
73
    add(new VersionListCommandlet(context));
6✔
74
    add(new EditionGetCommandlet(context));
6✔
75
    add(new EditionSetCommandlet(context));
6✔
76
    add(new EditionListCommandlet(context));
6✔
77
    add(new VersionCommandlet(context));
6✔
78
    add(new RepositoryCommandlet(context));
6✔
79
    add(new UninstallCommandlet(context));
6✔
80
    add(new UpdateCommandlet(context));
6✔
81
    add(new CreateCommandlet(context));
6✔
82
    add(new Gh(context));
6✔
83
    add(new Helm(context));
6✔
84
    add(new Java(context));
6✔
85
    add(new Node(context));
6✔
86
    add(new Npm(context));
6✔
87
    add(new Mvn(context));
6✔
88
    add(new GcViewer(context));
6✔
89
    add(new Gradle(context));
6✔
90
    add(new Eclipse(context));
6✔
91
    add(new Terraform(context));
6✔
92
    add(new Oc(context));
6✔
93
    add(new Quarkus(context));
6✔
94
    add(new Kotlinc(context));
6✔
95
    add(new KotlincNative(context));
6✔
96
    add(new Tomcat(context));
6✔
97
    add(new Vscode(context));
6✔
98
    add(new Azure(context));
6✔
99
    add(new Aws(context));
6✔
100
    add(new Cobigen(context));
6✔
101
    add(new Jmc(context));
6✔
102
    add(new DotNet(context));
6✔
103
    add(new Intellij(context));
6✔
104
    add(new Jasypt(context));
6✔
105
    add(new Docker(context));
6✔
106
    add(new Sonar(context));
6✔
107
    add(new GraalVm(context));
6✔
108
    add(new PgAdmin(context));
6✔
109
    add(new LazyDocker(context));
6✔
110
  }
1✔
111

112
  private void add(Commandlet commandlet) {
113

114
    boolean hasRequiredProperty = false;
2✔
115
    List<Property<?>> properties = commandlet.getProperties();
3✔
116
    int propertyCount = properties.size();
3✔
117
    for (int i = 0; i < propertyCount; i++) {
5!
118
      Property<?> property = properties.get(i);
5✔
119
      if (property.isRequired()) {
3!
120
        hasRequiredProperty = true;
2✔
121
        if ((i == 0) && (property instanceof KeywordProperty)) {
5!
122
          String keyword = property.getName();
3✔
123
          this.firstKeywordMap.putIfAbsent(keyword, commandlet);
6✔
124
        }
1✔
125
        break;
126
      }
127
    }
128
    if (!hasRequiredProperty) {
2!
129
      throw new IllegalStateException("Commandlet " + commandlet + " must have at least one mandatory property!");
×
130
    }
131
    this.commandletTypeMap.put(commandlet.getClass(), commandlet);
7✔
132
    Commandlet duplicate = this.commandletNameMap.put(commandlet.getName(), commandlet);
8✔
133
    if (duplicate != null) {
2!
134
      throw new IllegalStateException("Commandlet " + commandlet + " has the same name as " + duplicate);
×
135
    }
136
  }
1✔
137

138
  @Override
139
  public Collection<Commandlet> getCommandlets() {
140

141
    return this.commandlets;
3✔
142
  }
143

144
  @Override
145
  public <C extends Commandlet> C getCommandlet(Class<C> commandletType) {
146

147
    Commandlet commandlet = this.commandletTypeMap.get(commandletType);
6✔
148
    if (commandlet == null) {
2!
149
      throw new IllegalStateException("Commandlet for type " + commandletType + " is not registered!");
×
150
    }
151
    return commandletType.cast(commandlet);
5✔
152
  }
153

154
  @Override
155
  public Commandlet getCommandlet(String name) {
156

157
    Commandlet commandlet = this.commandletNameMap.get(name);
6✔
158
    return commandlet;
2✔
159
  }
160

161
  @Override
162
  public Commandlet getCommandletByFirstKeyword(String keyword) {
163

164
    return this.firstKeywordMap.get(keyword);
6✔
165
  }
166

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