Skip to content

Commit 12cdd64

Browse files
authored
#519: install-plugin commandlet (#543)
1 parent b82996b commit 12cdd64

24 files changed

+327
-287
lines changed

cli/src/main/java/com/devonfw/tools/ide/commandlet/Commandlet.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.devonfw.tools.ide.property.KeywordProperty;
1313
import com.devonfw.tools.ide.property.Property;
1414
import com.devonfw.tools.ide.tool.ToolCommandlet;
15+
import com.devonfw.tools.ide.tool.plugin.PluginDescriptor;
1516
import com.devonfw.tools.ide.version.VersionIdentifier;
1617

1718
/**
@@ -179,10 +180,7 @@ protected <C extends Commandlet> C getCommandlet(Class<C> commandletType) {
179180
*/
180181
public boolean isIdeHomeRequired() {
181182

182-
if (!isIdeRootRequired()) {
183-
return false;
184-
}
185-
return true;
183+
return isIdeRootRequired();
186184
}
187185

188186
/**
@@ -251,11 +249,10 @@ public String toString() {
251249
}
252250

253251
/**
254-
* @return the {@link ToolCommandlet} set in a {@link Property} of this commandlet used for auto-completion of a {@link VersionIdentifier} or {@code null} if
255-
* not exists or not configured.
252+
* @return the {@link ToolCommandlet} set in a {@link Property} of this commandlet used for auto-completion of a {@link VersionIdentifier} or
253+
* {@link PluginDescriptor}, otherwise {@code null} if not exists or not configured.
256254
*/
257-
public ToolCommandlet getToolForVersionCompletion() {
258-
255+
public ToolCommandlet getToolForCompletion() {
259256
return null;
260257
}
261258
}

cli/src/main/java/com/devonfw/tools/ide/commandlet/CommandletManagerImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public CommandletManagerImpl(IdeContext context) {
8080
add(new UpdateCommandlet(context));
8181
add(new CreateCommandlet(context));
8282
add(new BuildCommandlet(context));
83+
add(new InstallPluginCommandlet(context));
84+
add(new UninstallPluginCommandlet(context));
8385
add(new Gh(context));
8486
add(new Helm(context));
8587
add(new Java(context));

cli/src/main/java/com/devonfw/tools/ide/commandlet/InstallCommandlet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void run() {
5050
}
5151

5252
@Override
53-
public ToolCommandlet getToolForVersionCompletion() {
53+
public ToolCommandlet getToolForCompletion() {
5454

5555
return this.tool.getValue();
5656
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.devonfw.tools.ide.commandlet;
2+
3+
import com.devonfw.tools.ide.context.IdeContext;
4+
import com.devonfw.tools.ide.property.PluginProperty;
5+
import com.devonfw.tools.ide.property.ToolProperty;
6+
import com.devonfw.tools.ide.tool.ToolCommandlet;
7+
import com.devonfw.tools.ide.tool.plugin.PluginBasedCommandlet;
8+
9+
/**
10+
* {@link Commandlet} to install a tool.
11+
*
12+
* @see ToolCommandlet#install()
13+
*/
14+
public class InstallPluginCommandlet extends Commandlet {
15+
16+
/** The tool to install. */
17+
public final ToolProperty tool;
18+
19+
/** The optional version to set and install. */
20+
public final PluginProperty plugin;
21+
22+
/**
23+
* The constructor.
24+
*
25+
* @param context the {@link IdeContext}.
26+
*/
27+
public InstallPluginCommandlet(IdeContext context) {
28+
29+
super(context);
30+
addKeyword(getName());
31+
this.tool = add(new ToolProperty("", true, "tool"));
32+
this.plugin = add(new PluginProperty("", true, "plugin"));
33+
}
34+
35+
@Override
36+
public String getName() {
37+
38+
return "install-plugin";
39+
}
40+
41+
@Override
42+
public void run() {
43+
ToolCommandlet commandlet = this.tool.getValue();
44+
String plugin = this.plugin.getValue();
45+
46+
if (commandlet instanceof PluginBasedCommandlet cmd) {
47+
cmd.installPlugin(cmd.getPlugin(plugin));
48+
} else {
49+
context.warning("Tool {} does not support installation of plugins.", commandlet.getName());
50+
}
51+
52+
}
53+
54+
@Override
55+
public ToolCommandlet getToolForCompletion() {
56+
57+
return this.tool.getValue();
58+
}
59+
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.devonfw.tools.ide.commandlet;
2+
3+
import com.devonfw.tools.ide.context.IdeContext;
4+
import com.devonfw.tools.ide.property.PluginProperty;
5+
import com.devonfw.tools.ide.property.ToolProperty;
6+
import com.devonfw.tools.ide.tool.ToolCommandlet;
7+
import com.devonfw.tools.ide.tool.plugin.PluginBasedCommandlet;
8+
9+
/**
10+
* {@link Commandlet} to install a tool.
11+
*
12+
* @see ToolCommandlet#install()
13+
*/
14+
public class UninstallPluginCommandlet extends Commandlet {
15+
16+
/** The tool to install. */
17+
public final ToolProperty tool;
18+
19+
/** The optional version to set and install. */
20+
public final PluginProperty plugin;
21+
22+
/**
23+
* The constructor.
24+
*
25+
* @param context the {@link IdeContext}.
26+
*/
27+
public UninstallPluginCommandlet(IdeContext context) {
28+
29+
super(context);
30+
addKeyword(getName());
31+
this.tool = add(new ToolProperty("", true, "tool"));
32+
this.plugin = add(new PluginProperty("", true, "plugin"));
33+
}
34+
35+
@Override
36+
public String getName() {
37+
38+
return "uninstall-plugin";
39+
}
40+
41+
@Override
42+
public void run() {
43+
ToolCommandlet commandlet = this.tool.getValue();
44+
String plugin = this.plugin.getValue();
45+
46+
if (commandlet instanceof PluginBasedCommandlet cmd) {
47+
cmd.uninstallPlugin(cmd.getPlugin(plugin));
48+
} else {
49+
context.warning("Tool {} does not support plugins.", tool.getName());
50+
}
51+
}
52+
53+
@Override
54+
public ToolCommandlet getToolForCompletion() {
55+
return this.tool.getValue();
56+
}
57+
}

cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionSetCommandlet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void run() {
5353
}
5454

5555
@Override
56-
public ToolCommandlet getToolForVersionCompletion() {
56+
public ToolCommandlet getToolForCompletion() {
5757

5858
return this.tool.getValue();
5959
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.devonfw.tools.ide.property;
2+
3+
import java.util.function.Consumer;
4+
5+
import com.devonfw.tools.ide.commandlet.Commandlet;
6+
import com.devonfw.tools.ide.completion.CompletionCandidateCollector;
7+
import com.devonfw.tools.ide.context.IdeContext;
8+
import com.devonfw.tools.ide.tool.ToolCommandlet;
9+
import com.devonfw.tools.ide.tool.plugin.PluginBasedCommandlet;
10+
import com.devonfw.tools.ide.tool.plugin.PluginDescriptor;
11+
import com.devonfw.tools.ide.tool.plugin.PluginMaps;
12+
13+
/**
14+
* {@link Property} representing the plugin of a {@link PluginBasedCommandlet}.
15+
*/
16+
public class PluginProperty extends Property<String> {
17+
18+
/**
19+
* The constructor.
20+
*
21+
* @param name the {@link #getName() property name}.
22+
* @param required the {@link #isRequired() required flag}.
23+
* @param alias the {@link #getAlias() property alias}.
24+
*/
25+
public PluginProperty(String name, boolean required, String alias) {
26+
27+
this(name, required, alias, false, null);
28+
}
29+
30+
/**
31+
* The constructor.
32+
*
33+
* @param name the {@link #getName() property name}.
34+
* @param required the {@link #isRequired() required flag}.
35+
* @param alias the {@link #getAlias() property alias}.
36+
* @param multivalued the boolean flag about multiple arguments
37+
* @param validator the {@link Consumer} used to {@link #validate() validate} the {@link #getValue() value}.
38+
*/
39+
public PluginProperty(String name, boolean required, String alias, boolean multivalued, Consumer<String> validator) {
40+
41+
super(name, required, alias, multivalued, validator);
42+
}
43+
44+
@Override
45+
public Class<String> getValueType() {
46+
47+
return String.class;
48+
}
49+
50+
@Override
51+
public String parse(String valueAsString, IdeContext context) {
52+
53+
return valueAsString;
54+
}
55+
56+
@Override
57+
protected void completeValue(String arg, IdeContext context, Commandlet commandlet, CompletionCandidateCollector collector) {
58+
59+
ToolCommandlet cmd = commandlet.getToolForCompletion();
60+
if (cmd instanceof PluginBasedCommandlet) {
61+
PluginMaps pluginMap = ((PluginBasedCommandlet) cmd).getPluginsMap();
62+
for (PluginDescriptor pluginDescriptor : pluginMap.getPlugins()) {
63+
if (pluginDescriptor.getName().toLowerCase().startsWith(arg.toLowerCase())) {
64+
collector.add(pluginDescriptor.getName(), null, null, commandlet);
65+
}
66+
}
67+
}
68+
}
69+
}

cli/src/main/java/com/devonfw/tools/ide/property/VersionProperty.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public VersionIdentifier parse(String valueAsString, IdeContext context) {
5858
@Override
5959
protected void completeValue(String arg, IdeContext context, Commandlet commandlet, CompletionCandidateCollector collector) {
6060

61-
ToolCommandlet tool = commandlet.getToolForVersionCompletion();
61+
ToolCommandlet tool = commandlet.getToolForCompletion();
6262
if (tool != null) {
6363
completeVersion(VersionIdentifier.of(arg), tool, context, commandlet, collector);
6464
}

cli/src/main/java/com/devonfw/tools/ide/tool/androidstudio/AndroidStudio.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
1010
import com.devonfw.tools.ide.process.ProcessMode;
1111
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;
12-
import com.devonfw.tools.ide.tool.ide.IdeaBasedPluginInstaller;
13-
import com.devonfw.tools.ide.tool.ide.PluginDescriptor;
12+
import com.devonfw.tools.ide.tool.ide.IdeaBasedIdeToolCommandlet;
1413
import com.devonfw.tools.ide.version.VersionIdentifier;
1514

1615
/**
1716
* {@link IdeToolCommandlet} for <a href="https://developer.android.com/studio">AndroidStudio</a>.
1817
*/
19-
public class AndroidStudio extends IdeToolCommandlet {
18+
public class AndroidStudio extends IdeaBasedIdeToolCommandlet {
2019

2120
private static final String STUDIO = "studio";
2221

@@ -64,12 +63,4 @@ protected void postInstall() {
6463
envVars.set("STUDIO_PROPERTIES", this.context.getWorkspacePath().resolve("studio.properties").toString(), true);
6564
envVars.save();
6665
}
67-
68-
@Override
69-
public void installPlugin(PluginDescriptor plugin) {
70-
71-
IdeaBasedPluginInstaller pluginInstaller = new IdeaBasedPluginInstaller(context, this);
72-
String downloadUrl = pluginInstaller.getDownloadUrl(plugin);
73-
pluginInstaller.installPlugin(plugin, downloadUrl);
74-
}
7566
}

cli/src/main/java/com/devonfw/tools/ide/tool/eclipse/Eclipse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import com.devonfw.tools.ide.process.ProcessMode;
1919
import com.devonfw.tools.ide.process.ProcessResult;
2020
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;
21-
import com.devonfw.tools.ide.tool.ide.PluginDescriptor;
2221
import com.devonfw.tools.ide.tool.java.Java;
22+
import com.devonfw.tools.ide.tool.plugin.PluginDescriptor;
2323

2424
/**
2525
* {@link IdeToolCommandlet} for <a href="https://www.eclipse.org/">Eclipse</a>.

0 commit comments

Comments
 (0)