Skip to content

Commit

Permalink
Ask confirmation before uninstalling application
Browse files Browse the repository at this point in the history
Request: CT_BDEPLOY-10
Change-Id: I041de783f5b7c36545bbfe6abdfc4c9984533d1d
  • Loading branch information
Dastan Yessekeyev authored and Dastan Yessekeyev committed Jun 20, 2024
1 parent f73efe1 commit 93e4ed1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.function.Consumer;
import java.util.function.Function;

import javax.swing.JOptionPane;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -49,6 +51,9 @@ public class UninstallerTool extends ConfiguredCliTool<UninstallerConfig> {
@Help("Directory where the launcher stores the hive as well as all applications. ")
String homeDir();

@Help(value = "Don't ask for confirmation before uninstalling application", arg = false)
boolean yes() default false;

}

public UninstallerTool() {
Expand All @@ -63,6 +68,9 @@ protected RenderableResult run(UninstallerConfig config) {
if (config.app() == null) {
throw new IllegalStateException("Missing --app argument");
}
if (!config.yes() && !confirmDelete()) {
return createResultWithErrorMessage("Aborted, no confirmation");
}

Path rootDir = Paths.get(config.homeDir()).toAbsolutePath();
Path bhiveDir = rootDir.resolve("bhive");
Expand All @@ -73,6 +81,13 @@ protected RenderableResult run(UninstallerConfig config) {
return createSuccess();
}

private boolean confirmDelete() {
int result = JOptionPane.showConfirmDialog(null,
"Are you sure you want to delete this application? This CANNOT be undone.", "Uninstall",
JOptionPane.YES_NO_OPTION);
return result == JOptionPane.YES_OPTION;
}

/** Uninstall the given application and removes all not required artifacts */
private void doUninstall(Path rootDir, BHive hive, String appId) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,6 @@ private void onRefreshButtonClicked(ActionEvent e) {
/** Notification that the selected app should be removed */
private void onUninstallButtonClicked(ActionEvent e) {
ClientSoftwareConfiguration app = getSelectedApps().get(0);
String appName = app.metadata != null ? app.metadata.appName : app.clickAndStart.applicationId;

String message = "Are you sure you want to uninstall '" + appName + "'?";
int result = JOptionPane.showConfirmDialog(this, message, "Uninstall", JOptionPane.YES_NO_OPTION);
if (result != JOptionPane.YES_OPTION) {
return;
}
doUninstall(app);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void testRemoteDeploy(BHive local, MasterRootResource master, CommonRootResource
/* STEP 8: launcher client, assert that the script does some sleeping... */
launcher.execute(LauncherTool.class, "--homeDir=" + tmp.resolve("launcher"), "--launch=" + bdeployFile, "--unattended",
"--consoleLog");
launcher.execute(UninstallerTool.class, "--homeDir=" + tmp.resolve("launcher"), "--app=client");
launcher.execute(UninstallerTool.class, "--homeDir=" + tmp.resolve("launcher"), "--app=client", "--yes");

// if we reach here, launching succeeded. unfortunately no better way to check right now.

Expand Down

0 comments on commit 93e4ed1

Please sign in to comment.