forked from devonfw/IDEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devonfw#519: install-plugin commandlet (devonfw#543)
- Loading branch information
Showing
24 changed files
with
327 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
cli/src/main/java/com/devonfw/tools/ide/commandlet/InstallPluginCommandlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.devonfw.tools.ide.commandlet; | ||
|
||
import com.devonfw.tools.ide.context.IdeContext; | ||
import com.devonfw.tools.ide.property.PluginProperty; | ||
import com.devonfw.tools.ide.property.ToolProperty; | ||
import com.devonfw.tools.ide.tool.ToolCommandlet; | ||
import com.devonfw.tools.ide.tool.plugin.PluginBasedCommandlet; | ||
|
||
/** | ||
* {@link Commandlet} to install a tool. | ||
* | ||
* @see ToolCommandlet#install() | ||
*/ | ||
public class InstallPluginCommandlet extends Commandlet { | ||
|
||
/** The tool to install. */ | ||
public final ToolProperty tool; | ||
|
||
/** The optional version to set and install. */ | ||
public final PluginProperty plugin; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param context the {@link IdeContext}. | ||
*/ | ||
public InstallPluginCommandlet(IdeContext context) { | ||
|
||
super(context); | ||
addKeyword(getName()); | ||
this.tool = add(new ToolProperty("", true, "tool")); | ||
this.plugin = add(new PluginProperty("", true, "plugin")); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
|
||
return "install-plugin"; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
ToolCommandlet commandlet = this.tool.getValue(); | ||
String plugin = this.plugin.getValue(); | ||
|
||
if (commandlet instanceof PluginBasedCommandlet cmd) { | ||
cmd.installPlugin(cmd.getPlugin(plugin)); | ||
} else { | ||
context.warning("Tool {} does not support installation of plugins.", commandlet.getName()); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public ToolCommandlet getToolForCompletion() { | ||
|
||
return this.tool.getValue(); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
cli/src/main/java/com/devonfw/tools/ide/commandlet/UninstallPluginCommandlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.devonfw.tools.ide.commandlet; | ||
|
||
import com.devonfw.tools.ide.context.IdeContext; | ||
import com.devonfw.tools.ide.property.PluginProperty; | ||
import com.devonfw.tools.ide.property.ToolProperty; | ||
import com.devonfw.tools.ide.tool.ToolCommandlet; | ||
import com.devonfw.tools.ide.tool.plugin.PluginBasedCommandlet; | ||
|
||
/** | ||
* {@link Commandlet} to install a tool. | ||
* | ||
* @see ToolCommandlet#install() | ||
*/ | ||
public class UninstallPluginCommandlet extends Commandlet { | ||
|
||
/** The tool to install. */ | ||
public final ToolProperty tool; | ||
|
||
/** The optional version to set and install. */ | ||
public final PluginProperty plugin; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param context the {@link IdeContext}. | ||
*/ | ||
public UninstallPluginCommandlet(IdeContext context) { | ||
|
||
super(context); | ||
addKeyword(getName()); | ||
this.tool = add(new ToolProperty("", true, "tool")); | ||
this.plugin = add(new PluginProperty("", true, "plugin")); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
|
||
return "uninstall-plugin"; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
ToolCommandlet commandlet = this.tool.getValue(); | ||
String plugin = this.plugin.getValue(); | ||
|
||
if (commandlet instanceof PluginBasedCommandlet cmd) { | ||
cmd.uninstallPlugin(cmd.getPlugin(plugin)); | ||
} else { | ||
context.warning("Tool {} does not support plugins.", tool.getName()); | ||
} | ||
} | ||
|
||
@Override | ||
public ToolCommandlet getToolForCompletion() { | ||
return this.tool.getValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
cli/src/main/java/com/devonfw/tools/ide/property/PluginProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.devonfw.tools.ide.property; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import com.devonfw.tools.ide.commandlet.Commandlet; | ||
import com.devonfw.tools.ide.completion.CompletionCandidateCollector; | ||
import com.devonfw.tools.ide.context.IdeContext; | ||
import com.devonfw.tools.ide.tool.ToolCommandlet; | ||
import com.devonfw.tools.ide.tool.plugin.PluginBasedCommandlet; | ||
import com.devonfw.tools.ide.tool.plugin.PluginDescriptor; | ||
import com.devonfw.tools.ide.tool.plugin.PluginMaps; | ||
|
||
/** | ||
* {@link Property} representing the plugin of a {@link PluginBasedCommandlet}. | ||
*/ | ||
public class PluginProperty extends Property<String> { | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param name the {@link #getName() property name}. | ||
* @param required the {@link #isRequired() required flag}. | ||
* @param alias the {@link #getAlias() property alias}. | ||
*/ | ||
public PluginProperty(String name, boolean required, String alias) { | ||
|
||
this(name, required, alias, false, null); | ||
} | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param name the {@link #getName() property name}. | ||
* @param required the {@link #isRequired() required flag}. | ||
* @param alias the {@link #getAlias() property alias}. | ||
* @param multivalued the boolean flag about multiple arguments | ||
* @param validator the {@link Consumer} used to {@link #validate() validate} the {@link #getValue() value}. | ||
*/ | ||
public PluginProperty(String name, boolean required, String alias, boolean multivalued, Consumer<String> validator) { | ||
|
||
super(name, required, alias, multivalued, validator); | ||
} | ||
|
||
@Override | ||
public Class<String> getValueType() { | ||
|
||
return String.class; | ||
} | ||
|
||
@Override | ||
public String parse(String valueAsString, IdeContext context) { | ||
|
||
return valueAsString; | ||
} | ||
|
||
@Override | ||
protected void completeValue(String arg, IdeContext context, Commandlet commandlet, CompletionCandidateCollector collector) { | ||
|
||
ToolCommandlet cmd = commandlet.getToolForCompletion(); | ||
if (cmd instanceof PluginBasedCommandlet) { | ||
PluginMaps pluginMap = ((PluginBasedCommandlet) cmd).getPluginsMap(); | ||
for (PluginDescriptor pluginDescriptor : pluginMap.getPlugins()) { | ||
if (pluginDescriptor.getName().toLowerCase().startsWith(arg.toLowerCase())) { | ||
collector.add(pluginDescriptor.getName(), null, null, commandlet); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.