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

devonfw / IDEasy / 11933051706

20 Nov 2024 12:07PM UTC coverage: 67.254% (+0.005%) from 67.249%
11933051706

Pull #775

github

web-flow
Merge 868db0950 into b737f839a
Pull Request #775: improved test infrastructure to mock aspects of IdeContext

2462 of 4001 branches covered (61.53%)

Branch coverage included in aggregate %.

6396 of 9170 relevant lines covered (69.75%)

3.08 hits per line

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

90.32
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.lazydocker.LazyDocker;
30
import com.devonfw.tools.ide.tool.mvn.Mvn;
31
import com.devonfw.tools.ide.tool.node.Node;
32
import com.devonfw.tools.ide.tool.npm.Npm;
33
import com.devonfw.tools.ide.tool.oc.Oc;
34
import com.devonfw.tools.ide.tool.pgadmin.PgAdmin;
35
import com.devonfw.tools.ide.tool.quarkus.Quarkus;
36
import com.devonfw.tools.ide.tool.sonar.Sonar;
37
import com.devonfw.tools.ide.tool.terraform.Terraform;
38
import com.devonfw.tools.ide.tool.tomcat.Tomcat;
39
import com.devonfw.tools.ide.tool.vscode.Vscode;
40

41
/**
42
 * Implementation of {@link CommandletManager}.
43
 */
44
public 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 BuildCommandlet(context));
6✔
83
    add(new InstallPluginCommandlet(context));
6✔
84
    add(new UninstallPluginCommandlet(context));
6✔
85
    add(new Gh(context));
6✔
86
    add(new Helm(context));
6✔
87
    add(new Java(context));
6✔
88
    add(new Node(context));
6✔
89
    add(new Npm(context));
6✔
90
    add(new Mvn(context));
6✔
91
    add(new GcViewer(context));
6✔
92
    add(new Gradle(context));
6✔
93
    add(new Eclipse(context));
6✔
94
    add(new Terraform(context));
6✔
95
    add(new Oc(context));
6✔
96
    add(new Quarkus(context));
6✔
97
    add(new Kotlinc(context));
6✔
98
    add(new KotlincNative(context));
6✔
99
    add(new Tomcat(context));
6✔
100
    add(new Vscode(context));
6✔
101
    add(new Azure(context));
6✔
102
    add(new Aws(context));
6✔
103
    add(new Jmc(context));
6✔
104
    add(new DotNet(context));
6✔
105
    add(new Intellij(context));
6✔
106
    add(new Jasypt(context));
6✔
107
    add(new Docker(context));
6✔
108
    add(new Sonar(context));
6✔
109
    add(new AndroidStudio(context));
6✔
110
    add(new GraalVm(context));
6✔
111
    add(new PgAdmin(context));
6✔
112
    add(new LazyDocker(context));
6✔
113
  }
1✔
114

115
  /**
116
   * @param commandlet the {@link Commandlet} to add.
117
   */
118
  protected void add(Commandlet commandlet) {
119

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

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

147
    return this.commandlets;
3✔
148
  }
149

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

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

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

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

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

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

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