aboutsummaryrefslogtreecommitdiff
path: root/src/delombok
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2018-10-16 00:14:10 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2018-10-16 00:14:49 +0200
commit89907fd11f99903d4dc8f65c628d0c63fc511a7b (patch)
tree2fce20b46a784ef22d0b2a37434b35d095a62400 /src/delombok
parent836bd0ab573124ea6c168ef8351a7153fbfea363 (diff)
downloadlombok-89907fd11f99903d4dc8f65c628d0c63fc511a7b.tar.gz
lombok-89907fd11f99903d4dc8f65c628d0c63fc511a7b.tar.bz2
lombok-89907fd11f99903d4dc8f65c628d0c63fc511a7b.zip
[Fixes #1848] Added support to delombok for properly handling jigsaw (module-info) style projects.
Diffstat (limited to 'src/delombok')
-rw-r--r--src/delombok/lombok/delombok/Delombok.java51
-rw-r--r--src/delombok/lombok/delombok/ant/DelombokTask.java30
-rw-r--r--src/delombok/lombok/delombok/ant/DelombokTaskImpl.java4
3 files changed, 71 insertions, 14 deletions
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));