Skip to content

Commit

Permalink
devonfw#519: install-plugin commandlet (devonfw#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
slskiba authored Aug 20, 2024
1 parent b82996b commit 12cdd64
Show file tree
Hide file tree
Showing 24 changed files with 327 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.devonfw.tools.ide.property.KeywordProperty;
import com.devonfw.tools.ide.property.Property;
import com.devonfw.tools.ide.tool.ToolCommandlet;
import com.devonfw.tools.ide.tool.plugin.PluginDescriptor;
import com.devonfw.tools.ide.version.VersionIdentifier;

/**
Expand Down Expand Up @@ -179,10 +180,7 @@ protected <C extends Commandlet> C getCommandlet(Class<C> commandletType) {
*/
public boolean isIdeHomeRequired() {

if (!isIdeRootRequired()) {
return false;
}
return true;
return isIdeRootRequired();
}

/**
Expand Down Expand Up @@ -251,11 +249,10 @@ public String toString() {
}

/**
* @return the {@link ToolCommandlet} set in a {@link Property} of this commandlet used for auto-completion of a {@link VersionIdentifier} or {@code null} if
* not exists or not configured.
* @return the {@link ToolCommandlet} set in a {@link Property} of this commandlet used for auto-completion of a {@link VersionIdentifier} or
* {@link PluginDescriptor}, otherwise {@code null} if not exists or not configured.
*/
public ToolCommandlet getToolForVersionCompletion() {

public ToolCommandlet getToolForCompletion() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public CommandletManagerImpl(IdeContext context) {
add(new UpdateCommandlet(context));
add(new CreateCommandlet(context));
add(new BuildCommandlet(context));
add(new InstallPluginCommandlet(context));
add(new UninstallPluginCommandlet(context));
add(new Gh(context));
add(new Helm(context));
add(new Java(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void run() {
}

@Override
public ToolCommandlet getToolForVersionCompletion() {
public ToolCommandlet getToolForCompletion() {

return this.tool.getValue();
}
Expand Down
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();
}

}
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void run() {
}

@Override
public ToolCommandlet getToolForVersionCompletion() {
public ToolCommandlet getToolForCompletion() {

return this.tool.getValue();
}
Expand Down
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);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public VersionIdentifier parse(String valueAsString, IdeContext context) {
@Override
protected void completeValue(String arg, IdeContext context, Commandlet commandlet, CompletionCandidateCollector collector) {

ToolCommandlet tool = commandlet.getToolForVersionCompletion();
ToolCommandlet tool = commandlet.getToolForCompletion();
if (tool != null) {
completeVersion(VersionIdentifier.of(arg), tool, context, commandlet, collector);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.process.ProcessMode;
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;
import com.devonfw.tools.ide.tool.ide.IdeaBasedPluginInstaller;
import com.devonfw.tools.ide.tool.ide.PluginDescriptor;
import com.devonfw.tools.ide.tool.ide.IdeaBasedIdeToolCommandlet;
import com.devonfw.tools.ide.version.VersionIdentifier;

/**
* {@link IdeToolCommandlet} for <a href="https://developer.android.com/studio">AndroidStudio</a>.
*/
public class AndroidStudio extends IdeToolCommandlet {
public class AndroidStudio extends IdeaBasedIdeToolCommandlet {

private static final String STUDIO = "studio";

Expand Down Expand Up @@ -64,12 +63,4 @@ protected void postInstall() {
envVars.set("STUDIO_PROPERTIES", this.context.getWorkspacePath().resolve("studio.properties").toString(), true);
envVars.save();
}

@Override
public void installPlugin(PluginDescriptor plugin) {

IdeaBasedPluginInstaller pluginInstaller = new IdeaBasedPluginInstaller(context, this);
String downloadUrl = pluginInstaller.getDownloadUrl(plugin);
pluginInstaller.installPlugin(plugin, downloadUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import com.devonfw.tools.ide.process.ProcessMode;
import com.devonfw.tools.ide.process.ProcessResult;
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;
import com.devonfw.tools.ide.tool.ide.PluginDescriptor;
import com.devonfw.tools.ide.tool.java.Java;
import com.devonfw.tools.ide.tool.plugin.PluginDescriptor;

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

0 comments on commit 12cdd64

Please sign in to comment.