From 77036ce732f6cd5fd0568e4e10314c1be9e2d87a Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 11 Jan 2010 18:17:35 +0100 Subject: Made discovery of tools.jar slightly more robust and got rid of the double error you'd get if it cant be found. --- src/delombok/lombok/delombok/DelombokApp.java | 44 ++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'src/delombok/lombok') 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 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; } -- cgit From b0c712833b3845e46a1447392ef553c47668fc0d Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 11 Jan 2010 18:24:27 +0100 Subject: Made DelombokApp's error message if tools.jar is in fact missing more useful; the advice it gives will now actually work. --- src/delombok/lombok/delombok/DelombokApp.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/delombok/lombok') diff --git a/src/delombok/lombok/delombok/DelombokApp.java b/src/delombok/lombok/delombok/DelombokApp.java index b1732994..f129704a 100644 --- a/src/delombok/lombok/delombok/DelombokApp.java +++ b/src/delombok/lombok/delombok/DelombokApp.java @@ -26,12 +26,12 @@ public class DelombokApp implements LombokApp { runDirectly(args); return 0; } catch (ClassNotFoundException e) { - Class delombokClass = loadDelombok(); + Class delombokClass = loadDelombok(args); if (delombokClass == null) { return 1; } try { - loadDelombok().getMethod("main", String[].class).invoke(null, new Object[] {args.toArray(new String[0])}); + loadDelombok(args).getMethod("main", String[].class).invoke(null, new Object[] {args.toArray(new String[0])}); } catch (InvocationTargetException e1) { Throwable t = e1.getCause(); if (t instanceof Error) throw (Error)t; @@ -42,11 +42,24 @@ public class DelombokApp implements LombokApp { } } - public static Class loadDelombok() throws Exception { + public static Class loadDelombok(List args) throws Exception { //tools.jar is probably not on the classpath. We're going to try and find it, and then load the rest via a ClassLoader that includes tools.jar. final File toolsJar = findToolsJar(); if (toolsJar == null) { - System.err.println("Can't find tools.jar. Rerun delombok with tools.jar on the classpath."); + String examplePath = "/path/to/tools.jar"; + if (File.separator.equals("\\")) examplePath = "C:\\path\\to\\tools.jar"; + StringBuilder sb = new StringBuilder(); + for (String arg : args) { + if (sb.length() > 0) sb.append(' '); + if (arg.contains(" ")) { + sb.append('"').append(arg).append('"'); + } else { + sb.append(arg); + } + } + + System.err.printf("Can't find tools.jar. Rerun delombok as: java -cp lombok.jar%1$s%2$s lombok.core.Main delombok %3$s\n", + File.pathSeparator, examplePath, sb.toString()); return null; } -- cgit From 06e0ff4ab3dbbe96bf38ef184ab100cd4e080a10 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 10 Feb 2010 22:04:10 +0100 Subject: cmdreader no longer needs @Parameterized --- lib/lombok/com.zwitserloot.cmdreader.jar | Bin 19507 -> 19082 bytes .../runtimeDependencies/CreateLombokRuntimeApp.java | 2 -- src/delombok/lombok/delombok/Delombok.java | 4 ---- src/installer/lombok/installer/Installer.java | 2 -- 4 files changed, 8 deletions(-) (limited to 'src/delombok/lombok') diff --git a/lib/lombok/com.zwitserloot.cmdreader.jar b/lib/lombok/com.zwitserloot.cmdreader.jar index dade537a..7eb37b5a 100644 Binary files a/lib/lombok/com.zwitserloot.cmdreader.jar and b/lib/lombok/com.zwitserloot.cmdreader.jar differ diff --git a/src/core/lombok/core/runtimeDependencies/CreateLombokRuntimeApp.java b/src/core/lombok/core/runtimeDependencies/CreateLombokRuntimeApp.java index f30ff761..cac327d1 100644 --- a/src/core/lombok/core/runtimeDependencies/CreateLombokRuntimeApp.java +++ b/src/core/lombok/core/runtimeDependencies/CreateLombokRuntimeApp.java @@ -45,7 +45,6 @@ import com.zwitserloot.cmdreader.CmdReader; import com.zwitserloot.cmdreader.Description; import com.zwitserloot.cmdreader.InvalidCommandLineException; import com.zwitserloot.cmdreader.Mandatory; -import com.zwitserloot.cmdreader.Parameterized; import com.zwitserloot.cmdreader.Requires; import com.zwitserloot.cmdreader.Shorthand; @@ -81,7 +80,6 @@ public class CreateLombokRuntimeApp implements LombokApp { @Shorthand("o") @Description("Where to write the lombok-runtime.jar. Defaults to the current working directory.") - @Parameterized @Requires("create") String output; diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 88e8decb..8d28735a 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -44,7 +44,6 @@ import com.zwitserloot.cmdreader.Description; import com.zwitserloot.cmdreader.Excludes; import com.zwitserloot.cmdreader.InvalidCommandLineException; import com.zwitserloot.cmdreader.Mandatory; -import com.zwitserloot.cmdreader.Parameterized; import com.zwitserloot.cmdreader.Sequential; import com.zwitserloot.cmdreader.Shorthand; @@ -72,7 +71,6 @@ public class Delombok { @Shorthand("e") @Description("Sets the encoding of your source files. Defaults to the system default charset. Example: \"UTF-8\"") - @Parameterized private String encoding; @Shorthand("p") @@ -82,12 +80,10 @@ public class Delombok { @Shorthand("d") @Description("Directory to save delomboked files to") @Mandatory(onlyIfNot={"print", "help"}) - @Parameterized private String target; @Description("Files to delombok. Provide either a file, or a directory. If you use a directory, all files in it (recursive) are delombok-ed") @Sequential - @Parameterized private List input = new ArrayList(); @Description("Lombok will only delombok source files. Without this option, non-java, non-class files are copied to the target directory.") diff --git a/src/installer/lombok/installer/Installer.java b/src/installer/lombok/installer/Installer.java index 7700cd90..6ce8efdb 100644 --- a/src/installer/lombok/installer/Installer.java +++ b/src/installer/lombok/installer/Installer.java @@ -44,7 +44,6 @@ import org.mangosdk.spi.ProviderFor; import com.zwitserloot.cmdreader.CmdReader; import com.zwitserloot.cmdreader.Description; import com.zwitserloot.cmdreader.InvalidCommandLineException; -import com.zwitserloot.cmdreader.Parameterized; import com.zwitserloot.cmdreader.Sequential; import com.zwitserloot.cmdreader.Shorthand; @@ -196,7 +195,6 @@ public class Installer { private static class CmdArgs { @Description("Specify paths to a location to install/uninstall. Use 'auto' to apply to all automatically discoverable installations.") - @Parameterized @Sequential List path = new ArrayList(); -- cgit