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(-) 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(-) 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 f4ddece6140a9e3e8b76b0549c85e4675af12959 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 11 Jan 2010 18:28:03 +0100 Subject: Added fix for tools.jar finding to the changelog --- doc/changelog.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/changelog.markdown b/doc/changelog.markdown index e09b9c33..a63759ef 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -6,6 +6,7 @@ Lombok Changelog * Eclipse: `@Data` and other annotations now don't throw errors when you include fields with bounded wildcard generics, such as `List`. [Issue #84](http://code.google.com/p/projectlombok/issues/detail?id=84) * plugins and `@SneakyThrows`: Resolving types in annotations now works better especially for classes that aren't in the core java libraries. [Issue #88](http://code.google.com/p/projectlombok/issues/detail?id=88) * BUGFIX: complex enums didn't get delomboked properly. [Issue #96](http://code.google.com/p/projectlombok/issues/detail?id=96) +* FEATURE: If `tools.jar` isn't found (required when running _delombok_), now a useful error message is generated. The search for `tools.jar` now also looks in `JAVA_HOME`. ### v0.9.2 "Hailbunny" (December 15th, 2009) * preliminary support for lombok on NetBeans! - thanks go to Jan Lahoda from NetBeans. [Issue #20](http://code.google.com/p/projectlombok/issues/detail?id=20) -- 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(-) 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 From 3c75487f716549c5d2838585cd347cc2820306ef Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 10 Feb 2010 22:06:08 +0100 Subject: mavenrepo example now adds scope=provided to reflect that lombok is only a build-time and not a run-time dependency. --- website/mavenrepo/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/website/mavenrepo/index.html b/website/mavenrepo/index.html index ea7b8715..6b8ea48d 100644 --- a/website/mavenrepo/index.html +++ b/website/mavenrepo/index.html @@ -51,6 +51,7 @@ <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>@VERSION@</version> + <scope>provided</scope> </dependency> </dependencies> <repositories> -- cgit