diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/UninstallCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/UninstallCommandlet.java index 0fb940066..3b9a44cf3 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/UninstallCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/UninstallCommandlet.java @@ -4,9 +4,6 @@ import com.devonfw.tools.ide.property.ToolProperty; import com.devonfw.tools.ide.tool.ToolCommandlet; -import java.nio.file.Files; -import java.nio.file.Path; - /** * An internal {@link Commandlet} to uninstall a tool. */ @@ -39,22 +36,8 @@ public void run() { for (int i = 0; i < this.tools.getValueCount(); i++) { ToolCommandlet toolCommandlet = this.tools.getValue(i); - try { - String commandletName = toolCommandlet.getName(); - Path softwarePath = context.getSoftwarePath().resolve(commandletName); - if (Files.exists(softwarePath)) { - try { - context.getFileAccess().delete(softwarePath); - this.context.success("Successfully uninstalled " + commandletName); - } catch (Exception e) { - this.context.error("Couldn't uninstall " + commandletName); - } - } else { - this.context.warning("An installed version of " + commandletName + " does not exist"); - } - } catch (Exception e) { - this.context.error(e.getMessage()); - } + toolCommandlet.uninstall(); + } } } diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/GlobalToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/GlobalToolCommandlet.java index 0787bd2bb..097f36828 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/GlobalToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/GlobalToolCommandlet.java @@ -1,11 +1,5 @@ package com.devonfw.tools.ide.tool; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.List; -import java.util.Set; - import com.devonfw.tools.ide.common.Tag; import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.io.FileAccess; @@ -15,6 +9,12 @@ import com.devonfw.tools.ide.repo.ToolRepository; import com.devonfw.tools.ide.version.VersionIdentifier; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import java.util.Set; + /** * {@link ToolCommandlet} that is installed globally. */ @@ -143,4 +143,10 @@ protected boolean doInstall(boolean silent) { postInstall(); return true; } + + @Override + public void uninstall() { + //TODO: handle "uninstall " + this.context.error("Couldn't uninstall " + this.getName()); + } } diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java index 11291cc86..9df148109 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java @@ -176,7 +176,27 @@ protected void postExtract(Path extractedDir) { } - private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier resolvedVersion, Path toolVersionFile, boolean newInstallation) { + public void uninstall() { + + try { + Path softwarePath = getToolPath(); + if (Files.exists(softwarePath)) { + try { + context.getFileAccess().delete(softwarePath); + this.context.success("Successfully uninstalled " + this.tool); + } catch (Exception e) { + this.context.error("Couldn't uninstall " + this.tool); + } + } else { + this.context.warning("An installed version of " + this.tool + " does not exist"); + } + } catch (Exception e) { + this.context.error(e.getMessage()); + } + } + + private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier resolvedVersion, Path toolVersionFile, + boolean newInstallation) { Path linkDir = getMacOsHelper().findLinkDir(rootDir, this.tool); Path binDir = linkDir; diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java index 8a4916054..dd9629321 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java @@ -283,6 +283,11 @@ public String getInstalledEdition(Path toolPath) { } + /** + * Uninstalls the {@link #getName() tool}. + */ + public abstract void uninstall(); + /** * List the available editions of this tool. */