diff options
Diffstat (limited to 'src')
-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 |
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)); |