aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2010-01-11 18:17:35 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2010-01-11 18:17:35 +0100
commit77036ce732f6cd5fd0568e4e10314c1be9e2d87a (patch)
tree6f818a819c22efa736037245b381097f822b2ff8 /src
parent9c07a465c1976140a11c1bee78af485a1c907f63 (diff)
downloadlombok-77036ce732f6cd5fd0568e4e10314c1be9e2d87a.tar.gz
lombok-77036ce732f6cd5fd0568e4e10314c1be9e2d87a.tar.bz2
lombok-77036ce732f6cd5fd0568e4e10314c1be9e2d87a.zip
Made discovery of tools.jar slightly more robust and got rid of the double error you'd get if it cant be found.
Diffstat (limited to 'src')
-rw-r--r--src/delombok/lombok/delombok/DelombokApp.java44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/delombok/lombok/delombok/DelombokApp.java b/src/delombok/lombok/delombok/DelombokApp.java
index b48337c8..b1732994 100644
--- a/src/delombok/lombok/delombok/DelombokApp.java
+++ b/src/delombok/lombok/delombok/DelombokApp.java
@@ -10,6 +10,7 @@ import java.net.URL;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
+import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -27,7 +28,6 @@ public class DelombokApp implements LombokApp {
} catch (ClassNotFoundException e) {
Class<?> delombokClass = loadDelombok();
if (delombokClass == null) {
- System.err.println("Can't find tools.jar. Rerun delombok with tools.jar on the classpath.");
return 1;
}
try {
@@ -136,20 +136,50 @@ public class DelombokApp implements LombokApp {
try {
File toolsJar = findToolsJarViaRT();
if (toolsJar != null) return toolsJar;
- } catch (Throwable ignore) {}
+ } catch (Throwable ignore) {
+ //fallthrough
+ }
+
+ try {
+ File toolsJar = findToolsJarViaProperties();
+ if (toolsJar != null) return toolsJar;
+ } catch (Throwable ignore) {
+ //fallthrough
+ }
- return findToolsJarViaProperties();
+ try {
+ File toolsJar = findToolsJarViaEnvironment();
+ return toolsJar;
+ } catch (Throwable ignore) {
+ //fallthrough
+ }
+
+ return null;
+ }
+
+ private static File findToolsJarViaEnvironment() {
+ for (Map.Entry<String, String> s : System.getenv().entrySet()) {
+ if ("JAVA_HOME".equalsIgnoreCase(s.getKey())) {
+ return extensiveCheckToolsJar(new File(s.getValue()));
+ }
+ }
+
+ return null;
}
private static File findToolsJarViaProperties() {
File home = new File(System.getProperty("java.home", "."));
- File toolsJar = checkToolsJar(home);
+ return extensiveCheckToolsJar(home);
+ }
+
+ private static File extensiveCheckToolsJar(File base) {
+ File toolsJar = checkToolsJar(base);
if (toolsJar != null) return toolsJar;
- toolsJar = checkToolsJar(new File(home, "lib"));
+ toolsJar = checkToolsJar(new File(base, "lib"));
if (toolsJar != null) return toolsJar;
- toolsJar = checkToolsJar(new File(home.getParentFile(), "lib"));
+ toolsJar = checkToolsJar(new File(base.getParentFile(), "lib"));
if (toolsJar != null) return toolsJar;
- toolsJar = checkToolsJar(new File(new File(home, "jdk"), "lib"));
+ toolsJar = checkToolsJar(new File(new File(base, "jdk"), "lib"));
if (toolsJar != null) return toolsJar;
return null;
}