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

devonfw / IDEasy / 11892982640

18 Nov 2024 01:01PM UTC coverage: 67.276% (-0.006%) from 67.282%
11892982640

Pull #702

github

web-flow
Merge 5b12a1574 into 2966a61ee
Pull Request #702: #81: Implement ToolCommandlet for Kubernetes

2461 of 3999 branches covered (61.54%)

Branch coverage included in aggregate %.

6406 of 9181 relevant lines covered (69.77%)

3.08 hits per line

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

90.43
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.List;
7
import java.util.Map;
8

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

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

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

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

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

53
  private final Collection<Commandlet> commandlets;
54

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

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

117
  private void add(Commandlet commandlet) {
118

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

143
  @Override
144
  public Collection<Commandlet> getCommandlets() {
145

146
    return this.commandlets;
3✔
147
  }
148

149
  @Override
150
  public <C extends Commandlet> C getCommandlet(Class<C> commandletType) {
151

152
    Commandlet commandlet = this.commandletTypeMap.get(commandletType);
6✔
153
    if (commandlet == null) {
2!
154
      throw new IllegalStateException("Commandlet for type " + commandletType + " is not registered!");
×
155
    }
156
    return commandletType.cast(commandlet);
5✔
157
  }
158

159
  @Override
160
  public Commandlet getCommandlet(String name) {
161

162
    Commandlet commandlet = this.commandletNameMap.get(name);
6✔
163
    return commandlet;
2✔
164
  }
165

166
  @Override
167
  public Commandlet getCommandletByFirstKeyword(String keyword) {
168

169
    return this.firstKeywordMap.get(keyword);
6✔
170
  }
171

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