aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2010-07-25 00:56:18 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2010-07-25 00:56:18 +0200
commitdec77abcca98da50e5678008be7e5f6a2d7bb981 (patch)
treee0854d30af2223306298e558df55f78168c4b8d9 /src
parentf89dbe5d0e505cc6e05a9bbb389d8303333ef4e0 (diff)
downloadlombok-dec77abcca98da50e5678008be7e5f6a2d7bb981.tar.gz
lombok-dec77abcca98da50e5678008be7e5f6a2d7bb981.tar.bz2
lombok-dec77abcca98da50e5678008be7e5f6a2d7bb981.zip
Added version detection for netbeans. Installing into netbeans now does:
pre 6.8: Error explaining lombok isn't supported pre 6.8. 6.8: Install. post 6.8: Explain its no longer needed + how to make lombok.jar work in 6.9.
Diffstat (limited to 'src')
-rw-r--r--src/installer/lombok/installer/InstallException.java13
-rw-r--r--src/installer/lombok/installer/Installer.java16
-rw-r--r--src/installer/lombok/installer/InstallerGUI.java107
-rw-r--r--src/installer/lombok/installer/UninstallException.java2
-rw-r--r--src/installer/lombok/installer/netbeans/NetbeansLocation.java110
5 files changed, 202 insertions, 46 deletions
diff --git a/src/installer/lombok/installer/InstallException.java b/src/installer/lombok/installer/InstallException.java
index ba75f0e1..ddf17c64 100644
--- a/src/installer/lombok/installer/InstallException.java
+++ b/src/installer/lombok/installer/InstallException.java
@@ -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,18 @@ package lombok.installer;
* Thrown when installation of lombok into an IDE fails.
*/
public class InstallException extends Exception {
+ private boolean warning;
+
public InstallException(String message, Throwable cause) {
super(message, cause);
}
+
+ public InstallException(boolean warning, String message, Throwable cause) {
+ super(message, cause);
+ this.warning = warning;
+ }
+
+ public boolean isWarning() {
+ return warning;
+ }
}
diff --git a/src/installer/lombok/installer/Installer.java b/src/installer/lombok/installer/Installer.java
index f9e5d967..6195a5c8 100644
--- a/src/installer/lombok/installer/Installer.java
+++ b/src/installer/lombok/installer/Installer.java
@@ -266,13 +266,21 @@ public class Installer {
}
System.out.printf("Lombok %s %s: %s\n", uninstall ? "uninstalled" : "installed", uninstall ? "from" : "to", loc.getName());
} catch (InstallException e) {
- System.err.printf("Installation at %s failed:\n", loc.getName());
+ if (e.isWarning()) {
+ System.err.printf("Warning while installing at %s:\n", loc.getName());
+ } else {
+ System.err.printf("Installation at %s failed:\n", loc.getName());
+ validLocations--;
+ }
System.err.println(e.getMessage());
- validLocations--;
} catch (UninstallException e) {
- System.err.printf("Uninstall at %s failed:\n", loc.getName());
+ if (e.isWarning()) {
+ System.err.printf("Warning while uninstalling at %s:\n", loc.getName());
+ } else {
+ System.err.printf("Uninstall at %s failed:\n", loc.getName());
+ validLocations--;
+ }
System.err.println(e.getMessage());
- validLocations--;
}
}
diff --git a/src/installer/lombok/installer/InstallerGUI.java b/src/installer/lombok/installer/InstallerGUI.java
index 99968e34..2488eb13 100644
--- a/src/installer/lombok/installer/InstallerGUI.java
+++ b/src/installer/lombok/installer/InstallerGUI.java
@@ -45,6 +45,8 @@ import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
@@ -452,56 +454,81 @@ public class InstallerGUI {
spinner.add(new JLabel(new ImageIcon(Installer.class.getResource("loading.gif"))));
appWindow.setContentPane(spinner);
- final AtomicReference<Boolean> success = new AtomicReference<Boolean>(true);
+ final AtomicInteger successes = new AtomicInteger();
+ final AtomicBoolean failure = new AtomicBoolean();
new Thread() {
@Override public void run() {
for (IdeLocation loc : toInstall) {
try {
installSpecificMessages.add(loc.install());
+ successes.incrementAndGet();
} catch (final InstallException e) {
- success.set(false);
- try {
- SwingUtilities.invokeAndWait(new Runnable() {
- @Override public void run() {
- JOptionPane.showMessageDialog(appWindow,
- e.getMessage(), "Install 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(), "Install Problem", JOptionPane.WARNING_MESSAGE);
+ }
+ });
+ } catch (Exception e2) {
+ e2.printStackTrace();
+ //Shouldn't happen.
+ throw new RuntimeException(e2);
+ }
+ } else {
+ failure.set(true);
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override public void run() {
+ JOptionPane.showMessageDialog(appWindow,
+ e.getMessage(), "Install Problem", JOptionPane.ERROR_MESSAGE);
+ }
+ });
+ } catch (Exception e2) {
+ e2.printStackTrace();
+ //Shouldn't happen.
+ throw new RuntimeException(e2);
+ }
}
}
}
- if (success.get()) SwingUtilities.invokeLater(new Runnable() {
- @Override public void run() {
- StringBuilder installSpecific = new StringBuilder();
- for (String installSpecificMessage : installSpecificMessages) {
- installSpecific.append("<br>").append(installSpecificMessage);
- }
- JOptionPane.showMessageDialog(appWindow,
- "<html>Lombok has been installed on the selected IDE installations.<br>" +
- "Don't forget to add <code>lombok.jar</code> to your projects, and restart your IDE!" + installSpecific.toString() + "</html>",
- "Install successful",
- JOptionPane.INFORMATION_MESSAGE);
- appWindow.setVisible(false);
- synchronized (exitMarker) {
- exitMarker.set(0);
- exitMarker.notifyAll();
- }
+ if (successes.get() > 0) {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override public void run() {
+ StringBuilder installSpecific = new StringBuilder();
+ for (String installSpecificMessage : installSpecificMessages) {
+ installSpecific.append("<br>").append(installSpecificMessage);
+ }
+ JOptionPane.showMessageDialog(appWindow,
+ "<html>Lombok has been installed on the selected IDE installations.<br>" +
+ "Don't forget to add <code>lombok.jar</code> to your projects, and restart your IDE!" + installSpecific.toString() + "</html>",
+ "Install successful",
+ JOptionPane.INFORMATION_MESSAGE);
+ appWindow.setVisible(false);
+ synchronized (exitMarker) {
+ exitMarker.set(0);
+ exitMarker.notifyAll();
+ }
+ }
+ });
+ } catch (Exception e) {
+ // Shouldn't happen.
+ throw new RuntimeException(e);
}
- });
-
- if (!success.get()) SwingUtilities.invokeLater(new Runnable() {
- @Override public void run() {
- synchronized (exitMarker) {
- exitMarker.set(1);
- exitMarker.notifyAll();
+ } else {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override public void run() {
+ synchronized (exitMarker) {
+ exitMarker.set(failure.get() ? 1 : 0);
+ exitMarker.notifyAll();
+ }
}
- }
- });
+ });
+ }
}
}.start();
}
@@ -515,12 +542,13 @@ public class InstallerGUI {
final Container originalContentPane = appWindow.getContentPane();
appWindow.setContentPane(spinner);
- final AtomicReference<Boolean> success = new AtomicReference<Boolean>(true);
+ final AtomicInteger successes = new AtomicInteger();
new Thread(new Runnable() {
@Override public void run() {
for (IdeLocation loc : toUninstall) {
try {
loc.uninstall();
+ successes.incrementAndGet();
} catch (final UninstallException e) {
if (e.isWarning()) {
try {
@@ -536,7 +564,6 @@ public class InstallerGUI {
throw new RuntimeException(e2);
}
} else {
- success.set(false);
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
@@ -555,7 +582,7 @@ public class InstallerGUI {
SwingUtilities.invokeLater(new Runnable() {
@Override public void run() {
- if (success.get()) {
+ if (successes.get() > 0) {
JOptionPane.showMessageDialog(appWindow, "Lombok has been removed from the selected IDE installations.", "Uninstall successful", JOptionPane.INFORMATION_MESSAGE);
appWindow.setVisible(false);
System.exit(0);
diff --git a/src/installer/lombok/installer/UninstallException.java b/src/installer/lombok/installer/UninstallException.java
index c381ecec..71c140b1 100644
--- a/src/installer/lombok/installer/UninstallException.java
+++ b/src/installer/lombok/installer/UninstallException.java
@@ -26,9 +26,11 @@ package lombok.installer;
*/
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;
diff --git a/src/installer/lombok/installer/netbeans/NetbeansLocation.java b/src/installer/lombok/installer/netbeans/NetbeansLocation.java
index 7ef5f1c8..6db57207 100644
--- a/src/installer/lombok/installer/netbeans/NetbeansLocation.java
+++ b/src/installer/lombok/installer/netbeans/NetbeansLocation.java
@@ -44,7 +44,9 @@ import lombok.installer.UninstallException;
public class NetbeansLocation extends IdeLocation {
private final String name;
private final File netbeansConfPath;
- private volatile boolean hasLombok;
+ private final String version;
+ private final int versionFirst, versionSecond;
+ private final boolean hasLombok;
private static final String OS_NEWLINE = IdeFinder.getOS().getLineEnding();
@@ -58,6 +60,33 @@ public class NetbeansLocation extends IdeLocation {
"I can't read the configuration file of the Netbeans installed at " + name + "\n" +
"You may need to run this installer with root privileges if you want to modify that Netbeans.", "netbeans", e);
}
+ this.version = findNetbeansVersion(netbeansConfPath);
+ int first, second;
+ String[] vs = version.split("\\.");
+ try {
+ first = Integer.parseInt(vs[0]);
+ } catch (Exception e) {
+ first = 0;
+ }
+ try {
+ second = Integer.parseInt(vs[1]);
+ } catch (Exception e) {
+ second = 0;
+ }
+ this.versionFirst = first;
+ this.versionSecond = second;
+ }
+
+ public boolean versionIsPre68() {
+ return versionFirst < 6 || (versionFirst == 6 && versionSecond < 8);
+ }
+
+ public boolean versionIs68() {
+ return versionFirst == 6 && versionSecond == 8;
+ }
+
+ public boolean versionIsPost68() {
+ return versionFirst > 6 || (versionFirst == 6 && versionSecond > 8);
}
@Override public int hashCode() {
@@ -92,6 +121,51 @@ public class NetbeansLocation extends IdeLocation {
private final Pattern OPTIONS_LINE_MATCHER = Pattern.compile(
"^\\s*netbeans_default_options\\s*=\\s*\"\\s*" + ID_CHARS + "\\s*(\")\\s*(?:#.*)?$", Pattern.CASE_INSENSITIVE);
+ private String findNetbeansVersion(File iniFile) {
+ String forcedVersion = System.getProperty("force.netbeans.version", null);
+ if (forcedVersion != null) return forcedVersion;
+
+ try {
+ for (File child : iniFile.getParentFile().getParentFile().listFiles()) {
+ if (!child.isDirectory()) continue;
+ String name = child.getName();
+ if (name == null || !name.startsWith("nb")) continue;
+ String version = name.substring(2);
+ File versionFile = new File(child, "VERSION.txt");
+ if (versionFile.exists() && versionFile.canRead() && !versionFile.isDirectory()) {
+ try {
+ version = readVersionFile(versionFile);
+ } catch (IOException e) {
+ // Intentional Fallthrough
+ }
+ }
+ if (version != null && version.length() > 0) {
+ return version;
+ }
+ }
+ } catch (NullPointerException e) {
+ // Intentional Fallthrough
+ }
+
+ return "UNKNOWN";
+ }
+
+ private static String readVersionFile(File file) throws IOException {
+ FileInputStream fis = new FileInputStream(file);
+ StringBuilder version = new StringBuilder();
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
+ for (String line = br.readLine(); line != null; line = br.readLine()) {
+ if (line.startsWith("#")) continue;
+ if (version.length() > 0) version.append(" ");
+ version.append(line);
+ }
+ return version.toString();
+ } finally {
+ fis.close();
+ }
+ }
+
private boolean checkForLombok(File iniFile) throws IOException {
if (!iniFile.exists()) return false;
FileInputStream fis = new FileInputStream(iniFile);
@@ -203,6 +277,40 @@ public class NetbeansLocation extends IdeLocation {
*/
@Override
public String install() throws InstallException {
+ if ("UNKNOWN".equals(version)) {
+ throw new InstallException(String.format(
+ "Can't determine version of Netbeans installed at:\n%s\n\n" +
+ "Your Netbeans version determines what this installer does:\n" +
+ "Pre 6.8: Lombok is not compatible with netbeans pre 6.8, and thus won't install.\n" +
+ "6.8: Lombok will install itself into Netbeans.\n" +
+ "6.9 and later: NetBeans supports lombok natively. This installer will explain how to enable it.\n\n" +
+ "If you know your netbeans version, you can force this by starting the installer with:\n" +
+ "java -Dforce.netbeans.version=6.8 -jar lombok.jar", this.getName()), null);
+ }
+
+ if (versionIsPre68()) {
+ throw new InstallException(String.format(
+ "Lombok is not compatible with Netbeans versions prior to 6.8.\n" +
+ "Therefore, lombok will not be installed at:\n%s\nbecause it is version: %s",
+ this.getName(), version), null);
+ }
+ if (versionIsPost68()) {
+ try {
+ uninstall();
+ } catch (Exception e) {
+ // Well, we tried. Lombok on 6.9 doesn't do anything, so we'll leave it then.
+ }
+
+ throw new InstallException(true, String.format(
+ "Starting with NetBeans 6.9, lombok is natively supported and does not need to be installed at:\n%s\n\n" +
+ "To use lombok.jar in your netbeans project:\n" +
+ "1. Add lombok.jar to your project (Go to Project Properties, 'Libraries' page, and add lombok.jar in the 'Compile' tab).\n" +
+ "2. Enable Annotation Processors (Go to Project Properties, 'Build/Compiling' page, and check 'Enable Annotation Processing in Editor').\n" +
+ "\n" +
+ "NB: In the first release of NetBeans 6.9, due to a netbeans bug, maven-based projects don't run annotation processors. This \n" +
+ "issue should be fixed by the great folks at NetBeans soon.", this.getName()), null);
+ }
+
boolean installSucceeded = false;
StringBuilder newContents = new StringBuilder();