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

devonfw / IDEasy / 12021911622

26 Nov 2024 01:18AM UTC coverage: 67.39% (+0.005%) from 67.385%
12021911622

push

github

web-flow
improved test infrastructure to mock aspects of IdeContext (#775)

2493 of 4038 branches covered (61.74%)

Branch coverage included in aggregate %.

6478 of 9274 relevant lines covered (69.85%)

3.09 hits per line

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

90.53
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 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 StatusCommandlet(context));
6✔
80
    add(new RepositoryCommandlet(context));
6✔
81
    add(new UninstallCommandlet(context));
6✔
82
    add(new UpdateCommandlet(context));
6✔
83
    add(new CreateCommandlet(context));
6✔
84
    add(new BuildCommandlet(context));
6✔
85
    add(new InstallPluginCommandlet(context));
6✔
86
    add(new UninstallPluginCommandlet(context));
6✔
87
    add(new Gh(context));
6✔
88
    add(new Helm(context));
6✔
89
    add(new Java(context));
6✔
90
    add(new Node(context));
6✔
91
    add(new Npm(context));
6✔
92
    add(new Mvn(context));
6✔
93
    add(new GcViewer(context));
6✔
94
    add(new Gradle(context));
6✔
95
    add(new Eclipse(context));
6✔
96
    add(new Terraform(context));
6✔
97
    add(new Oc(context));
6✔
98
    add(new Quarkus(context));
6✔
99
    add(new Kotlinc(context));
6✔
100
    add(new KotlincNative(context));
6✔
101
    add(new KubeCtl(context));
6✔
102
    add(new Tomcat(context));
6✔
103
    add(new Vscode(context));
6✔
104
    add(new Azure(context));
6✔
105
    add(new Aws(context));
6✔
106
    add(new Jmc(context));
6✔
107
    add(new DotNet(context));
6✔
108
    add(new Intellij(context));
6✔
109
    add(new Jasypt(context));
6✔
110
    add(new Docker(context));
6✔
111
    add(new Sonar(context));
6✔
112
    add(new AndroidStudio(context));
6✔
113
    add(new GraalVm(context));
6✔
114
    add(new PgAdmin(context));
6✔
115
    add(new LazyDocker(context));
6✔
116
  }
1✔
117

118
  /**
119
   * @param commandlet the {@link Commandlet} to add.
120
   */
121
  protected void add(Commandlet commandlet) {
122

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

147
  @Override
148
  public Collection<Commandlet> getCommandlets() {
149

150
    return this.commandlets;
3✔
151
  }
152

153
  @Override
154
  public <C extends Commandlet> C getCommandlet(Class<C> commandletType) {
155

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

163
  @Override
164
  public Commandlet getCommandlet(String name) {
165

166
    Commandlet commandlet = this.commandletNameMap.get(name);
6✔
167
    return commandlet;
2✔
168
  }
169

170
  @Override
171
  public Commandlet getCommandletByFirstKeyword(String keyword) {
172

173
    return this.firstKeywordMap.get(keyword);
6✔
174
  }
175

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