diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-10-16 00:14:10 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-10-16 00:14:49 +0200 |
commit | 89907fd11f99903d4dc8f65c628d0c63fc511a7b (patch) | |
tree | 2fce20b46a784ef22d0b2a37434b35d095a62400 | |
parent | 836bd0ab573124ea6c168ef8351a7153fbfea363 (diff) | |
download | lombok-89907fd11f99903d4dc8f65c628d0c63fc511a7b.tar.gz lombok-89907fd11f99903d4dc8f65c628d0c63fc511a7b.tar.bz2 lombok-89907fd11f99903d4dc8f65c628d0c63fc511a7b.zip |
[Fixes #1848] Added support to delombok for properly handling jigsaw (module-info) style projects.
-rw-r--r-- | doc/changelog.markdown | 1 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/Delombok.java | 51 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/ant/DelombokTask.java | 30 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/ant/DelombokTaskImpl.java | 4 | ||||
-rw-r--r-- | website/templates/features/delombok.html | 4 |
5 files changed, 75 insertions, 15 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown index a0de9c4f..dcdb9042 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -6,6 +6,7 @@ Lombok Changelog * FEATURE: The `@FieldNameConstants` feature has been completely redesigned. [Issue #1774](https://github.com/rzwitserloot/lombok/issues/1774) [FieldNameConstants documentation](https://projectlombok.org/features/experimental/FieldNameConstants) * FEATURE: Lombok's `@NonNull` annotation can now be used on types (annotation on types has been introduced in JDK 8). `@Builder`'s `@Singular` annotation now properly deals with annotations on the generics type on the collection: `@Singular List<@NonNull String> names;` now does the right thing. * FEATURE: You can now mix `@SuperBuilder` and `toBuilder`, and `toBuilder` no longer throws `NullPointerException` if an `@Singular`-marked collection field is `null`. [Issue #1324](https://github.com/rzwitserloot/lombok/issues/1324) +* FEATURE: delombok now supports module paths via the `--module-path` option, and will automatically add lombok itself to the module path. This should make it possible to delombok your modularized projects. [Issue #1848](https://github.com/rzwitserloot/lombok/issues/1848) * BREAKING CHANGE: Lombok will now always copy specific annotations around (from field to getter, from field to builder 'setter', etcetera): A specific curated list of known annotations where that is the right thing to do (generally, `@NonNull` style annotations from various libraries), as well as any annotations you explicitly list in the `lombok.copyableAnnotations` config key in your `lombok.config` file. Also, lombok is more consistent about copying these annotations. (Previous behaviour: Lombok used to copy any annotation whose simple name was `NonNull`, `Nullable`, or `CheckForNull`). [Issue #1570](https://github.com/rzwitserloot/lombok/issues/1570) and [Issue #1634](https://github.com/rzwitserloot/lombok/issues/1634) * BUGFIX: `@NoArgsConstructor(force=true)` would try to initialize already initialized final fields in Eclipse. [Issue #1829](https://github.com/rzwitserloot/lombok/issues/1829) * BUGFIX: When using lombok to compile modularized (`module-info.java`-style) code, if the module name has dots in it, it wouldn't work. [Issue #1808](https://github.com/rzwitserloot/lombok/issues/1808) diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index be0ce81c..9d55c68f 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2017 The Project Lombok Authors. + * Copyright (C) 2009-2018 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,11 +29,13 @@ import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import java.io.Writer; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; +import java.net.URLDecoder; import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; import java.util.ArrayList; @@ -88,7 +90,7 @@ public class Delombok { private boolean noCopy; private boolean onlyChanged; private boolean force = false; - private String classpath, sourcepath, bootclasspath; + private String classpath, sourcepath, bootclasspath, modulepath; private LinkedHashMap<File, File> fileToBase = new LinkedHashMap<File, File>(); private List<File> filesToParse = new ArrayList<File>(); private Map<String, String> formatPrefs = new HashMap<String, String>(); @@ -138,6 +140,10 @@ public class Delombok { @Description("override Bootclasspath (analogous to javac -bootclasspath option)") private String bootclasspath; + @Description("Module path (analogous to javac --module-path option)") + @FullName("module-path") + private String modulepath; + @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 private List<String> input = new ArrayList<String>(); @@ -182,6 +188,28 @@ public class Delombok { return out.toString(); } + static String getPathOfSelf() { + String url = Delombok.class.getResource("Delombok.class").toString(); + if (url.endsWith("lombok/delombok/Delombok.class")) { + url = urlDecode(url.substring(0, url.length() - "lombok/delombok/Delombok.class".length())); + } else if (url.endsWith("lombok/delombok/Delombok.SCL.lombok")) { + url = urlDecode(url.substring(0, url.length() - "lombok/delombok/Delombok.SCL.lombok".length())); + } else { + return null; + } + if (url.startsWith("jar:file:") && url.endsWith("!/")) return url.substring(9, url.length() - 2); + if (url.startsWith("file:")) return url.substring(5); + return null; + } + + private static String urlDecode(String in) { + try { + return URLDecoder.decode(in, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new InternalError("UTF-8 not supported"); + } + } + public static void main(String[] rawArgs) { CmdReader<CmdArgs> reader = CmdReader.of(CmdArgs.class); CmdArgs args; @@ -253,6 +281,7 @@ public class Delombok { if (args.classpath != null) delombok.setClasspath(args.classpath); if (args.sourcepath != null) delombok.setSourcepath(args.sourcepath); if (args.bootclasspath != null) delombok.setBootclasspath(args.bootclasspath); + if (args.modulepath != null) delombok.setModulepath(args.modulepath); try { for (String in : args.input) { @@ -273,9 +302,7 @@ public class Delombok { if (!args.quiet) { String msg = e.getMessage(); if (msg != null && msg.startsWith("DELOMBOK: ")) System.err.println(msg.substring("DELOMBOK: ".length())); - else { - e.printStackTrace(); - } + else e.printStackTrace(); System.exit(1); return; } @@ -385,6 +412,10 @@ public class Delombok { this.output = null; } + public void setModulepath(String modulepath) { + this.modulepath = modulepath; + } + public void addDirectory(File base) throws IOException { addDirectory0(false, base, "", 0); } @@ -525,9 +556,19 @@ public class Delombok { argsList.add("-encoding"); argsList.add(charset.name()); } + String pathToSelfJar = getPathOfSelf(); + if (pathToSelfJar != null) { + argsList.add("--module-path"); + argsList.add((modulepath == null || modulepath.isEmpty()) ? pathToSelfJar : (pathToSelfJar + File.pathSeparator + modulepath)); + } else if (modulepath != null && !modulepath.isEmpty()) { + argsList.add("--module-path"); + argsList.add(modulepath); + } String[] argv = argsList.toArray(new String[0]); args.init("javac", argv); options.put("diags.legacy", "TRUE"); + } else { + if (modulepath != null && !modulepath.isEmpty()) throw new IllegalStateException("DELOMBOK: Option --module-path requires usage of JDK9 or higher."); } CommentCatcher catcher = CommentCatcher.create(context); diff --git a/src/delombok/lombok/delombok/ant/DelombokTask.java b/src/delombok/lombok/delombok/ant/DelombokTask.java index 06bbe3e0..adaf43dd 100644 --- a/src/delombok/lombok/delombok/ant/DelombokTask.java +++ b/src/delombok/lombok/delombok/ant/DelombokTask.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2015 The Project Lombok Authors. + * Copyright (C) 2009-2018 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -78,6 +78,7 @@ class Tasks { private File fromDir, toDir; private Path classpath; private Path sourcepath; + private Path modulepath; private boolean verbose; private String encoding; private Path path; @@ -92,9 +93,7 @@ class Tasks { } public Path createClasspath() { - if (classpath == null) { - classpath = new Path(getProject()); - } + if (classpath == null) classpath = new Path(getProject()); return classpath.createPath(); } @@ -111,9 +110,7 @@ class Tasks { } public Path createSourcepath() { - if (sourcepath == null) { - sourcepath = new Path(getProject()); - } + if (sourcepath == null) sourcepath = new Path(getProject()); return sourcepath.createPath(); } @@ -121,6 +118,23 @@ class Tasks { createSourcepath().setRefid(r); } + public void setModulepath(Path modulepath) { + if (this.modulepath == null) { + this.modulepath = modulepath; + } else { + this.modulepath.append(modulepath); + } + } + + public Path createModulepath() { + if (modulepath == null) modulepath = new Path(getProject()); + return modulepath.createPath(); + } + + public void setModulepathRef(Reference r) { + createModulepath().setRefid(r); + } + public void setFrom(File dir) { this.fromDir = dir; } @@ -180,7 +194,7 @@ class Tasks { try { Object instance = shadowLoadClass("lombok.delombok.ant.DelombokTaskImpl").newInstance(); - for(Field selfField : getClass().getDeclaredFields()) { + for (Field selfField : getClass().getDeclaredFields()) { if (selfField.isSynthetic() || Modifier.isStatic(selfField.getModifiers())) continue; Field otherField = instance.getClass().getDeclaredField(selfField.getName()); otherField.setAccessible(true); diff --git a/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java b/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java index 470819cd..bd2f93e7 100644 --- a/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java +++ b/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2015 The Project Lombok Authors. + * Copyright (C) 2009-2018 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -40,6 +40,7 @@ public class DelombokTaskImpl { private File fromDir, toDir; private Path classpath; private Path sourcepath; + private Path modulepath; private boolean verbose; private String encoding; private Path path; @@ -60,6 +61,7 @@ public class DelombokTaskImpl { if (classpath != null) delombok.setClasspath(classpath.toString()); if (sourcepath != null) delombok.setSourcepath(sourcepath.toString()); + if (modulepath != null) delombok.setModulepath(modulepath.toString()); try { delombok.setFormatPreferences(Delombok.formatOptionsToMap(formatOptions)); diff --git a/website/templates/features/delombok.html b/website/templates/features/delombok.html index 56b02f7d..75178740 100644 --- a/website/templates/features/delombok.html +++ b/website/templates/features/delombok.html @@ -23,6 +23,8 @@ </p><p> To let delombok print the transformation result of a single java file directly to standard output, you can use: <pre>java -jar lombok.jar delombok -p MyJavaFile.java</pre> + </p><p> + The <code>-classpath</code>, <code>-sourcepath</code>, and <code>--module-path</code> options of javac are replicated as <code>--classpath</code>, <code>--sourcepath</code>, and <code>--module-path</code> in delombok. </p> <@f.main.h3 title="Running delombok in ant" /> @@ -39,7 +41,7 @@ <javadoc sourcepath="build/src-delomboked" defaultexcludes="yes" destdir="build/api" /> </target></pre> <br /> - Instead of a <code>from</code> attribute, you can also nest <code><fileset></code> nodes. + Instead of a <code>from</code> attribute, you can also nest <code><fileset></code> nodes. The <code>delombok</code> supports <code>sourcepath</code>, <code>classpath</code>, and <code>modulepath</code> as parameter or as nested element, or as nested refid element, similar to the <code>javac</code> task. </p> <@f.main.h3 title="Running delombok in maven" /> |