Skip to content

Commit

Permalink
#395: Improve uninstall to also support graalvm (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
slskiba authored Jun 21, 2024
1 parent d195546 commit ee596da
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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();

}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
*/
Expand Down Expand Up @@ -143,4 +143,10 @@ protected boolean doInstall(boolean silent) {
postInstall();
return true;
}

@Override
public void uninstall() {
//TODO: handle "uninstall <globaltool>"
this.context.error("Couldn't uninstall " + this.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit ee596da

Please sign in to comment.