mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 20:15:09 +00:00
[Fixes #1848] Added support to delombok for properly handling jigsaw (module-info) style projects.
This commit is contained in:
1 parent
836bd0ab57
commit
89907fd11f
5 files changed
+75
-15
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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" />
|
||||
|
||||
Reference in new issue
Block a user