mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 00:14:50 +00:00
[fixes #1795] you can now pass arguments to delombok via file in the same way javac/java support it.
This commit is contained in:
1 parent
89907fd11f
commit
e40eab2e34
2 files changed
+122
-2
No files matched your search
@@ -7,6 +7,7 @@ Lombok Changelog
|
||||
* 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)
|
||||
* FEATURE: You can pass `@args.txt` to `delombok` to read args from the text file; useful if you have really long classpaths you need to pass to delombok. [Issue #1795](https://github.com/rzwitserloot/lombok/issues/1795)
|
||||
* 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)
|
||||
|
||||
@@ -26,6 +26,8 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintStream;
|
||||
@@ -211,20 +213,27 @@ public class Delombok {
|
||||
}
|
||||
|
||||
public static void main(String[] rawArgs) {
|
||||
try {
|
||||
rawArgs = fileExpand(rawArgs);
|
||||
} catch (IOException e) {
|
||||
System.out.println(e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
CmdReader<CmdArgs> reader = CmdReader.of(CmdArgs.class);
|
||||
CmdArgs args;
|
||||
try {
|
||||
args = reader.make(rawArgs);
|
||||
} catch (InvalidCommandLineException e) {
|
||||
System.err.println("ERROR: " + e.getMessage());
|
||||
System.err.println(reader.generateCommandLineHelp("delombok"));
|
||||
System.err.println(cmdHelp(reader));
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.help || (args.input.isEmpty() && !args.formatHelp)) {
|
||||
if (!args.help) System.err.println("ERROR: no files or directories to delombok specified.");
|
||||
System.err.println(reader.generateCommandLineHelp("delombok"));
|
||||
System.err.println(cmdHelp(reader));
|
||||
System.exit(args.help ? 0 : 1);
|
||||
return;
|
||||
}
|
||||
@@ -309,6 +318,116 @@ public class Delombok {
|
||||
}
|
||||
}
|
||||
|
||||
private static String cmdHelp(CmdReader<CmdArgs> reader) {
|
||||
String x = reader.generateCommandLineHelp("delombok");
|
||||
int idx = x.indexOf('\n');
|
||||
return x.substring(0, idx) + "\n You can use @filename.args to read arguments from the file 'filename.args'.\n" + x.substring(idx);
|
||||
}
|
||||
|
||||
private static String[] fileExpand(String[] rawArgs) throws IOException {
|
||||
String[] out = rawArgs;
|
||||
int offset = 0;
|
||||
for (int i = 0; i < rawArgs.length; i++) {
|
||||
if (rawArgs[i].length() > 0 && rawArgs[i].charAt(0) == '@') {
|
||||
String[] parts = readArgsFromFile(rawArgs[i].substring(1));
|
||||
String[] newOut = new String[out.length + parts.length - 1];
|
||||
System.arraycopy(out, 0, newOut, 0, i + offset);
|
||||
System.arraycopy(parts, 0, newOut, i + offset, parts.length);
|
||||
System.arraycopy(out, i + offset + 1, newOut, i + offset + parts.length, out.length - (i + offset + 1));
|
||||
offset += parts.length - 1;
|
||||
out = newOut;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
private static String[] readArgsFromFile(String file) throws IOException {
|
||||
InputStream in = new FileInputStream(file);
|
||||
StringBuilder s = new StringBuilder();
|
||||
try {
|
||||
InputStreamReader isr = new InputStreamReader(in, "UTF-8");
|
||||
char[] c = new char[4096];
|
||||
while (true) {
|
||||
int r = isr.read(c);
|
||||
if (r == -1) break;
|
||||
s.append(c, 0, r);
|
||||
}
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
|
||||
List<String> x = new ArrayList<String>();
|
||||
StringBuilder a = new StringBuilder();
|
||||
int state = 1;
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (state < 0) {
|
||||
state = -state;
|
||||
if (c != '\n') a.append(c);
|
||||
continue;
|
||||
}
|
||||
if (state == 1) {
|
||||
if (c == '\\') {
|
||||
state = -1;
|
||||
continue;
|
||||
}
|
||||
if (c == '"') {
|
||||
state = 2;
|
||||
continue;
|
||||
}
|
||||
if (c == '\'') {
|
||||
state = 3;
|
||||
continue;
|
||||
}
|
||||
if (Character.isWhitespace(c)) {
|
||||
String aa = a.toString();
|
||||
if (!aa.isEmpty()) x.add(aa);
|
||||
a.setLength(0);
|
||||
continue;
|
||||
}
|
||||
a.append(c);
|
||||
continue;
|
||||
}
|
||||
if (state == 2) {
|
||||
if (c == '\\') {
|
||||
state = -2;
|
||||
continue;
|
||||
}
|
||||
if (c == '"') {
|
||||
state = 1;
|
||||
x.add(a.toString());
|
||||
a.setLength(0);
|
||||
continue;
|
||||
}
|
||||
a.append(c);
|
||||
continue;
|
||||
}
|
||||
if (state == 3) {
|
||||
if (c == '\'') {
|
||||
state = 1;
|
||||
x.add(a.toString());
|
||||
a.setLength(0);
|
||||
continue;
|
||||
}
|
||||
a.append(c);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (state == 1) {
|
||||
String aa = a.toString();
|
||||
if (!aa.isEmpty()) x.add(aa);
|
||||
} else if (state < 0) {
|
||||
throw new IOException("Unclosed backslash escape in @ file");
|
||||
} else if (state == 2) {
|
||||
throw new IOException("Unclosed \" in @ file");
|
||||
} else if (state == 3) {
|
||||
throw new IOException("Unclosed ' in @ file");
|
||||
}
|
||||
|
||||
return x.toArray(new String[x.size()]);
|
||||
}
|
||||
|
||||
public static class InvalidFormatOptionException extends Exception {
|
||||
public InvalidFormatOptionException(String msg) {
|
||||
super(msg);
|
||||
|
||||
Reference in new issue
Block a user