Skip to content

Commit

Permalink
feat: Show install or update depending on if SDKMAN is installed or not
Browse files Browse the repository at this point in the history
  • Loading branch information
jagodevreede committed Sep 23, 2024
1 parent e88027e commit d23e59a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions sdkman-ui/src/main/java/io/github/jagodevreede/sdkmanui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,29 @@ private void install() {
}
File currentRunningFolder = currentExecutable.getParentFile();
if (!currentRunningFolder.equals(installFolder)) {
SERVICE_REGISTRY.getPopupView().showConfirmation("Installation", "Do you want to install/update SDKMAN UI?", () -> {
File installedExecutable = new File(installFolder, currentExecutable.getName());
SERVICE_REGISTRY.getPopupView().showConfirmation("Installation", "Do you want to " + (installedExecutable.exists() ? "update" : "install") + " SDKMAN UI?", () -> {
try {
installFolder.mkdirs();
boolean configured = SERVICE_REGISTRY.getApi().configureEnvironmentPath();

// REPLACE_EXISTING seems to fail on windows, so remove and copy
new File(installFolder, currentExecutable.getName()).delete();
Files.copy(currentExecutable.toPath(), new File(installFolder, currentExecutable.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING);
boolean oldVersion = installedExecutable.delete();
Files.copy(currentExecutable.toPath(), installedExecutable.toPath(), StandardCopyOption.REPLACE_EXISTING);
updateScriptAndVersion();

StringBuilder confirmationMessage = new StringBuilder("SDKMAN UI has been installed, you can now remove ");
confirmationMessage.append(currentExecutable.getAbsolutePath());
StringBuilder confirmationMessage = new StringBuilder("SDKMAN UI has been ");
if (oldVersion) {
confirmationMessage.append("updated");
} else {
confirmationMessage.append("installed");
}
String tmpdir = System.getProperty("java.io.tmpdir");
if (!currentRunningFolder.getAbsolutePath().startsWith(tmpdir)) {
confirmationMessage.append(",\nyou can now remove ");
confirmationMessage.append(currentExecutable.getAbsolutePath());
}

if (configured) {
confirmationMessage.append("\nyou need to relogin to be able to use `sdkui` from the command line.");
}
Expand Down

0 comments on commit d23e59a

Please sign in to comment.