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

devonfw / IDEasy / 9903760381

12 Jul 2024 06:55AM UTC coverage: 61.812% (+0.05%) from 61.761%
9903760381

push

github

web-flow
#12: Implement ToolCommandlet for Android Studio (#299)

1994 of 3543 branches covered (56.28%)

Branch coverage included in aggregate %.

5298 of 8254 relevant lines covered (64.19%)

2.81 hits per line

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

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

36
import java.util.Collection;
37
import java.util.Collections;
38
import java.util.HashMap;
39
import java.util.List;
40
import java.util.Map;
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 Gh(context));
6✔
85
    add(new Helm(context));
6✔
86
    add(new Java(context));
6✔
87
    add(new Node(context));
6✔
88
    add(new Npm(context));
6✔
89
    add(new Mvn(context));
6✔
90
    add(new GcViewer(context));
6✔
91
    add(new Gradle(context));
6✔
92
    add(new Eclipse(context));
6✔
93
    add(new Terraform(context));
6✔
94
    add(new Oc(context));
6✔
95
    add(new Quarkus(context));
6✔
96
    add(new Kotlinc(context));
6✔
97
    add(new KotlincNative(context));
6✔
98
    add(new Tomcat(context));
6✔
99
    add(new Vscode(context));
6✔
100
    add(new Azure(context));
6✔
101
    add(new Aws(context));
6✔
102
    add(new Cobigen(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
  private void add(Commandlet commandlet) {
116

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

141
  @Override
142
  public Collection<Commandlet> getCommandlets() {
143

144
    return this.commandlets;
3✔
145
  }
146

147
  @Override
148
  public <C extends Commandlet> C getCommandlet(Class<C> commandletType) {
149

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

157
  @Override
158
  public Commandlet getCommandlet(String name) {
159

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

164
  @Override
165
  public Commandlet getCommandletByFirstKeyword(String keyword) {
166

167
    return this.firstKeywordMap.get(keyword);
6✔
168
  }
169

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