From 31bd6b35a6045f3f9971970874429fe4d75602cc Mon Sep 17 00:00:00 2001 From: Sonja Skiba Date: Tue, 18 Jun 2024 12:36:43 +0200 Subject: [PATCH 1/3] Move uninstall logic into LocalToolCommandlet --- .../ide/commandlet/UninstallCommandlet.java | 21 ++--------------- .../tools/ide/tool/GlobalToolCommandlet.java | 18 ++++++++++----- .../tools/ide/tool/LocalToolCommandlet.java | 23 ++++++++++++++++++- .../tools/ide/tool/ToolCommandlet.java | 5 ++++ 4 files changed, 41 insertions(+), 26 deletions(-) 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..0d7f5d667 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,28 @@ protected void postExtract(Path extractedDir) { } - private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier resolvedVersion, Path toolVersionFile, boolean newInstallation) { + public void uninstall() { + + try { + String commandletName = this.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()); + } + } + + 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. */ From 37dde0577a11ad4f9cb463df7605a00f138f7636 Mon Sep 17 00:00:00 2001 From: Sonja Skiba Date: Tue, 18 Jun 2024 14:57:19 +0200 Subject: [PATCH 2/3] Use getToolPath to uninstall local tools --- .../java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0d7f5d667..553d5c262 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 @@ -180,7 +180,7 @@ public void uninstall() { try { String commandletName = this.getName(); - Path softwarePath = context.getSoftwarePath().resolve(commandletName); + Path softwarePath = this.getToolPath(); if (Files.exists(softwarePath)) { try { context.getFileAccess().delete(softwarePath); From a6e3512ffdb91ac87d77ae7e1008af01eba57ea8 Mon Sep 17 00:00:00 2001 From: Sonja Skiba Date: Tue, 18 Jun 2024 17:28:52 +0200 Subject: [PATCH 3/3] Address review comment --- .../com/devonfw/tools/ide/tool/LocalToolCommandlet.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 553d5c262..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 @@ -179,17 +179,16 @@ protected void postExtract(Path extractedDir) { public void uninstall() { try { - String commandletName = this.getName(); - Path softwarePath = this.getToolPath(); + Path softwarePath = getToolPath(); if (Files.exists(softwarePath)) { try { context.getFileAccess().delete(softwarePath); - this.context.success("Successfully uninstalled " + commandletName); + this.context.success("Successfully uninstalled " + this.tool); } catch (Exception e) { - this.context.error("Couldn't uninstall " + commandletName); + this.context.error("Couldn't uninstall " + this.tool); } } else { - this.context.warning("An installed version of " + commandletName + " does not exist"); + this.context.warning("An installed version of " + this.tool + " does not exist"); } } catch (Exception e) { this.context.error(e.getMessage());