diff options
author | Roel Spilker <r.spilker@gmail.com> | 2010-02-14 03:50:39 +0100 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2010-02-14 03:50:39 +0100 |
commit | 5f276b620901e7b41a213c2a9c2dc252b6b4cfa1 (patch) | |
tree | 507d63c0a9a77ba6d61bc0c3facc72b58eea3f46 /src/delombok/lombok | |
parent | 2552315058146bc94a38afba5a1a9cd630d4febe (diff) | |
parent | 3c75487f716549c5d2838585cd347cc2820306ef (diff) | |
download | lombok-5f276b620901e7b41a213c2a9c2dc252b6b4cfa1.tar.gz lombok-5f276b620901e7b41a213c2a9c2dc252b6b4cfa1.tar.bz2 lombok-5f276b620901e7b41a213c2a9c2dc252b6b4cfa1.zip |
Merge branch 'master' of git@github.com:rzwitserloot/lombok
Diffstat (limited to 'src/delombok/lombok')
-rw-r--r-- | src/delombok/lombok/delombok/Delombok.java | 4 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/DelombokApp.java | 65 |
2 files changed, 54 insertions, 15 deletions
diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 943136cf..b38d3ef5 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<String> input = new ArrayList<String>(); @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/delombok/lombok/delombok/DelombokApp.java b/src/delombok/lombok/delombok/DelombokApp.java index b48337c8..f129704a 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; @@ -25,13 +26,12 @@ public class DelombokApp implements LombokApp { runDirectly(args); return 0; } catch (ClassNotFoundException e) { - Class<?> delombokClass = loadDelombok(); + Class<?> delombokClass = loadDelombok(args); if (delombokClass == null) { - System.err.println("Can't find tools.jar. Rerun delombok with tools.jar on the classpath."); 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<String> 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; } @@ -136,20 +149,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 + } + + 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 findToolsJarViaProperties(); + 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; } |