mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 22:16:11 +00:00
When the installer errors, for example because it's trying to remove itself, which is not possible in windows, the GUI would hang after telling you about the problem. It no longer does this. It will also remove itself from the INI file BEFORE removing itself, because then the uninstall process is more likely to do what you want, and it'll detect the situation of either trying to install itself (which it skips, no point), or uninstalling itself (which, if it leads to a problem in windows, now leads to a customized error message explaining what the user is to do next).
Fixes issue #57.
This commit is contained in:
1 parent
8c15e904eb
commit
f9d82911dc
6 files changed
+174
-94
No files matched your search
@@ -54,7 +54,7 @@ public abstract class IdeLocation {
|
||||
|
||||
/**
|
||||
* Returns a full path to the provided file.
|
||||
* Returns the canonical path, unless that is not available, in which cae it returns the absolute path.
|
||||
* Returns the canonical path, unless that is not available, in which case it returns the absolute path.
|
||||
*/
|
||||
public static String canonical(File p) {
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
|
||||
* Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -22,6 +22,7 @@
|
||||
package lombok.installer;
|
||||
|
||||
import java.awt.HeadlessException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
@@ -38,6 +39,7 @@ import lombok.core.LombokApp;
|
||||
import lombok.core.SpiLoadUtil;
|
||||
import lombok.core.Version;
|
||||
import lombok.installer.IdeFinder.OS;
|
||||
import lombok.patcher.inject.LiveInjector;
|
||||
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
@@ -98,6 +100,16 @@ public class Installer {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isSelf(String jar) {
|
||||
String self = LiveInjector.findPathJar(Installer.class);
|
||||
if (self == null) return false;
|
||||
File a = new File(jar).getAbsoluteFile();
|
||||
File b = new File(self).getAbsoluteFile();
|
||||
try { a = a.getCanonicalFile(); } catch (IOException ignore) {}
|
||||
try { b = b.getCanonicalFile(); } catch (IOException ignore) {}
|
||||
return a.equals(b);
|
||||
}
|
||||
|
||||
@ProviderFor(LombokApp.class)
|
||||
public static class GraphicalInstallerApp implements LombokApp {
|
||||
@Override public String getAppName() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
|
||||
* Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -512,39 +512,63 @@ public class InstallerGUI {
|
||||
spinner.setLayout(new FlowLayout());
|
||||
spinner.add(new JLabel(new ImageIcon(Installer.class.getResource("/lombok/installer/loading.gif"))));
|
||||
|
||||
final Container originalContentPane = appWindow.getContentPane();
|
||||
appWindow.setContentPane(spinner);
|
||||
|
||||
final AtomicReference<Boolean> success = new AtomicReference<Boolean>(true);
|
||||
new Thread() {
|
||||
new Thread(new Runnable() {
|
||||
@Override public void run() {
|
||||
for (IdeLocation loc : toUninstall) {
|
||||
try {
|
||||
loc.uninstall();
|
||||
} catch (final UninstallException e) {
|
||||
success.set(false);
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override public void run() {
|
||||
JOptionPane.showMessageDialog(appWindow,
|
||||
e.getMessage(), "Uninstall Problem", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
} catch (Exception e2) {
|
||||
//Shouldn't happen.
|
||||
throw new RuntimeException(e2);
|
||||
if (e.isWarning()) {
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override public void run() {
|
||||
JOptionPane.showMessageDialog(appWindow,
|
||||
e.getMessage(), "Uninstall Problem", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
});
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
//Shouldn't happen.
|
||||
throw new RuntimeException(e2);
|
||||
}
|
||||
} else {
|
||||
success.set(false);
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override public void run() {
|
||||
JOptionPane.showMessageDialog(appWindow,
|
||||
e.getMessage(), "Uninstall Problem", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
//Shouldn't happen.
|
||||
throw new RuntimeException(e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (success.get()) SwingUtilities.invokeLater(new Runnable() {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override public void run() {
|
||||
JOptionPane.showMessageDialog(appWindow, "Lombok has been removed from the selected IDE installations.", "Uninstall successful", JOptionPane.INFORMATION_MESSAGE);
|
||||
appWindow.setVisible(false);
|
||||
System.exit(0);
|
||||
if (success.get()) {
|
||||
JOptionPane.showMessageDialog(appWindow, "Lombok has been removed from the selected IDE installations.", "Uninstall successful", JOptionPane.INFORMATION_MESSAGE);
|
||||
appWindow.setVisible(false);
|
||||
System.exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
appWindow.setContentPane(originalContentPane);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}.start();
|
||||
}).start();
|
||||
}
|
||||
|
||||
private IdesList idesList = new IdesList();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
|
||||
* Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -25,7 +25,16 @@ package lombok.installer;
|
||||
* Thrown when uninstallation of lombok into an IDE fails.
|
||||
*/
|
||||
public class UninstallException extends Exception {
|
||||
private boolean warning;
|
||||
public UninstallException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
public UninstallException(boolean warning, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.warning = warning;
|
||||
}
|
||||
|
||||
public boolean isWarning() {
|
||||
return warning;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
|
||||
* Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -38,6 +38,7 @@ import lombok.installer.CorruptedIdeLocationException;
|
||||
import lombok.installer.IdeFinder;
|
||||
import lombok.installer.IdeLocation;
|
||||
import lombok.installer.InstallException;
|
||||
import lombok.installer.Installer;
|
||||
import lombok.installer.UninstallException;
|
||||
|
||||
/**
|
||||
@@ -141,23 +142,7 @@ public class EclipseLocation extends IdeLocation {
|
||||
*/
|
||||
@Override
|
||||
public void uninstall() throws UninstallException {
|
||||
for (File dir : getUninstallDirs()) {
|
||||
File lombokJar = new File(dir, "lombok.jar");
|
||||
if (lombokJar.exists()) {
|
||||
if (!lombokJar.delete()) throw new UninstallException(
|
||||
"Can't delete " + lombokJar.getAbsolutePath() + generateWriteErrorMessage(), null);
|
||||
}
|
||||
|
||||
/* legacy code - lombok at one point used to have a separate jar for the eclipse agent.
|
||||
* Leave this code in to delete it for those upgrading from an old version. */ {
|
||||
File agentJar = new File(dir, "lombok.eclipse.agent.jar");
|
||||
if (agentJar.exists()) {
|
||||
if (!agentJar.delete()) throw new UninstallException(
|
||||
"Can't delete " + agentJar.getAbsolutePath() + generateWriteErrorMessage(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final List<File> lombokJarsForWhichCantDeleteSelf = new ArrayList<File>();
|
||||
StringBuilder newContents = new StringBuilder();
|
||||
if (eclipseIniPath.exists()) {
|
||||
try {
|
||||
@@ -202,6 +187,35 @@ public class EclipseLocation extends IdeLocation {
|
||||
throw new UninstallException("Cannot uninstall lombok from " + name + generateWriteErrorMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
for (File dir : getUninstallDirs()) {
|
||||
File lombokJar = new File(dir, "lombok.jar");
|
||||
if (lombokJar.exists()) {
|
||||
if (!lombokJar.delete()) {
|
||||
if (IdeFinder.getOS() == IdeFinder.OS.WINDOWS && Installer.isSelf(lombokJar.getAbsolutePath())) {
|
||||
lombokJarsForWhichCantDeleteSelf.add(lombokJar);
|
||||
} else {
|
||||
throw new UninstallException(
|
||||
"Can't delete " + lombokJar.getAbsolutePath() + generateWriteErrorMessage(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* legacy code - lombok at one point used to have a separate jar for the eclipse agent.
|
||||
* Leave this code in to delete it for those upgrading from an old version. */ {
|
||||
File agentJar = new File(dir, "lombok.eclipse.agent.jar");
|
||||
if (agentJar.exists()) {
|
||||
agentJar.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!lombokJarsForWhichCantDeleteSelf.isEmpty()) {
|
||||
throw new UninstallException(true, String.format(
|
||||
"lombok.jar cannot delete itself on windows.\nHowever, lombok has been uncoupled from your %s.\n" +
|
||||
"You can safely delete this jar file. You can find it at:\n%s",
|
||||
getTypeName(), lombokJarsForWhichCantDeleteSelf.get(0).getAbsolutePath()), null);
|
||||
}
|
||||
}
|
||||
|
||||
private static String generateWriteErrorMessage() {
|
||||
@@ -244,36 +258,39 @@ public class EclipseLocation extends IdeLocation {
|
||||
|
||||
File lombokJar = new File(eclipseIniPath.getParentFile(), "lombok.jar");
|
||||
|
||||
File ourJar = findOurJar();
|
||||
byte[] b = new byte[524288];
|
||||
boolean readSucceeded = true;
|
||||
try {
|
||||
FileOutputStream out = new FileOutputStream(lombokJar);
|
||||
/* No need to copy lombok.jar to itself, obviously. On windows this would generate an error so we check for this. */
|
||||
if (!Installer.isSelf(lombokJar.getAbsolutePath())) {
|
||||
File ourJar = findOurJar();
|
||||
byte[] b = new byte[524288];
|
||||
boolean readSucceeded = true;
|
||||
try {
|
||||
readSucceeded = false;
|
||||
InputStream in = new FileInputStream(ourJar);
|
||||
FileOutputStream out = new FileOutputStream(lombokJar);
|
||||
try {
|
||||
while (true) {
|
||||
int r = in.read(b);
|
||||
if (r == -1) break;
|
||||
if (r > 0) readSucceeded = true;
|
||||
out.write(b, 0, r);
|
||||
readSucceeded = false;
|
||||
InputStream in = new FileInputStream(ourJar);
|
||||
try {
|
||||
while (true) {
|
||||
int r = in.read(b);
|
||||
if (r == -1) break;
|
||||
if (r > 0) readSucceeded = true;
|
||||
out.write(b, 0, r);
|
||||
}
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
} finally {
|
||||
in.close();
|
||||
out.close();
|
||||
}
|
||||
} finally {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
lombokJar.delete();
|
||||
} catch (Throwable ignore) { /* Nothing we can do about that. */ }
|
||||
if (!readSucceeded) throw new InstallException(
|
||||
"I can't read my own jar file. I think you've found a bug in this installer!\nI suggest you restart it " +
|
||||
"and use the 'what do I do' link, to manually install lombok. Also, tell us about this at:\n" +
|
||||
"http://groups.google.com/group/project-lombok - Thanks!", e);
|
||||
throw new InstallException("I can't write to your " + getTypeName() + " directory at " + name + generateWriteErrorMessage(), e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
lombokJar.delete();
|
||||
} catch (Throwable ignore) { /* Nothing we can do about that. */ }
|
||||
if (!readSucceeded) throw new InstallException(
|
||||
"I can't read my own jar file. I think you've found a bug in this installer!\nI suggest you restart it " +
|
||||
"and use the 'what do I do' link, to manually install lombok. Also, tell us about this at:\n" +
|
||||
"http://groups.google.com/group/project-lombok - Thanks!", e);
|
||||
throw new InstallException("I can't write to your " + getTypeName() + " directory at " + name + generateWriteErrorMessage(), e);
|
||||
}
|
||||
|
||||
/* legacy - delete lombok.eclipse.agent.jar if its there, which lombok no longer uses. */ {
|
||||
@@ -307,7 +324,6 @@ public class EclipseLocation extends IdeLocation {
|
||||
|
||||
newContents.append(line).append(OS_NEWLINE);
|
||||
}
|
||||
|
||||
} finally {
|
||||
fis.close();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
|
||||
* Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,6 +29,8 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -36,6 +38,7 @@ import lombok.installer.CorruptedIdeLocationException;
|
||||
import lombok.installer.IdeFinder;
|
||||
import lombok.installer.IdeLocation;
|
||||
import lombok.installer.InstallException;
|
||||
import lombok.installer.Installer;
|
||||
import lombok.installer.UninstallException;
|
||||
|
||||
public class NetbeansLocation extends IdeLocation {
|
||||
@@ -117,12 +120,8 @@ public class NetbeansLocation extends IdeLocation {
|
||||
*/
|
||||
@Override
|
||||
public void uninstall() throws UninstallException {
|
||||
final List<File> lombokJarsForWhichCantDeleteSelf = new ArrayList<File>();
|
||||
File dir = netbeansConfPath.getParentFile();
|
||||
File lombokJar = new File(dir, "lombok.jar");
|
||||
if (lombokJar.exists()) {
|
||||
if (!lombokJar.delete()) throw new UninstallException(
|
||||
"Can't delete " + lombokJar.getAbsolutePath() + generateWriteErrorMessage(), null);
|
||||
}
|
||||
|
||||
StringBuilder newContents = new StringBuilder();
|
||||
if (netbeansConfPath.exists()) {
|
||||
@@ -154,6 +153,23 @@ public class NetbeansLocation extends IdeLocation {
|
||||
throw new UninstallException("Cannot uninstall lombok from " + name + generateWriteErrorMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
File lombokJar = new File(dir, "lombok.jar");
|
||||
if (lombokJar.exists()) {
|
||||
if (IdeFinder.getOS() == IdeFinder.OS.WINDOWS && Installer.isSelf(lombokJar.getAbsolutePath())) {
|
||||
lombokJarsForWhichCantDeleteSelf.add(lombokJar);
|
||||
} else {
|
||||
throw new UninstallException(
|
||||
"Can't delete " + lombokJar.getAbsolutePath() + generateWriteErrorMessage(), null);
|
||||
}
|
||||
}
|
||||
|
||||
if (!lombokJarsForWhichCantDeleteSelf.isEmpty()) {
|
||||
throw new UninstallException(true,
|
||||
"lombok.jar cannot delete itself on windows.\nHowever, lombok has been uncoupled from your netbeans.\n" +
|
||||
"You can safely delete this jar file. You can find it at:\n" +
|
||||
lombokJarsForWhichCantDeleteSelf.get(0).getAbsolutePath(), null);
|
||||
}
|
||||
}
|
||||
|
||||
private static String generateWriteErrorMessage() {
|
||||
@@ -190,36 +206,39 @@ public class NetbeansLocation extends IdeLocation {
|
||||
|
||||
File lombokJar = new File(netbeansConfPath.getParentFile(), "lombok.jar");
|
||||
|
||||
File ourJar = findOurJar();
|
||||
byte[] b = new byte[524288];
|
||||
boolean readSucceeded = true;
|
||||
try {
|
||||
FileOutputStream out = new FileOutputStream(lombokJar);
|
||||
/* No need to copy lombok.jar to itself, obviously. On windows this would generate an error so we check for this. */
|
||||
if (!Installer.isSelf(lombokJar.getAbsolutePath())) {
|
||||
File ourJar = findOurJar();
|
||||
byte[] b = new byte[524288];
|
||||
boolean readSucceeded = true;
|
||||
try {
|
||||
readSucceeded = false;
|
||||
InputStream in = new FileInputStream(ourJar);
|
||||
FileOutputStream out = new FileOutputStream(lombokJar);
|
||||
try {
|
||||
while (true) {
|
||||
int r = in.read(b);
|
||||
if (r == -1) break;
|
||||
if (r > 0) readSucceeded = true;
|
||||
out.write(b, 0, r);
|
||||
readSucceeded = false;
|
||||
InputStream in = new FileInputStream(ourJar);
|
||||
try {
|
||||
while (true) {
|
||||
int r = in.read(b);
|
||||
if (r == -1) break;
|
||||
if (r > 0) readSucceeded = true;
|
||||
out.write(b, 0, r);
|
||||
}
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
} finally {
|
||||
in.close();
|
||||
out.close();
|
||||
}
|
||||
} finally {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
lombokJar.delete();
|
||||
} catch (Throwable ignore) { /* Nothing we can do about that. */ }
|
||||
if (!readSucceeded) throw new InstallException(
|
||||
"I can't read my own jar file. I think you've found a bug in this installer!\nI suggest you restart it " +
|
||||
"and use the 'what do I do' link, to manually install lombok. Also, tell us about this at:\n" +
|
||||
"http://groups.google.com/group/project-lombok - Thanks!", e);
|
||||
throw new InstallException("I can't write to your Netbeans directory at " + name + generateWriteErrorMessage(), e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
lombokJar.delete();
|
||||
} catch (Throwable ignore) { /* Nothing we can do about that. */ }
|
||||
if (!readSucceeded) throw new InstallException(
|
||||
"I can't read my own jar file. I think you've found a bug in this installer!\nI suggest you restart it " +
|
||||
"and use the 'what do I do' link, to manually install lombok. Also, tell us about this at:\n" +
|
||||
"http://groups.google.com/group/project-lombok - Thanks!", e);
|
||||
throw new InstallException("I can't write to your Netbeans directory at " + name + generateWriteErrorMessage(), e);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user