From 937a4dfca209d30e567a4c4fcbc9fe868221680a Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 19 Mar 2021 03:05:25 +0100 Subject: [jdk16] fix delombok (and the test suite, which depends on it) for jdk16. --- src/ant/lombok/ant/SimpleTestFormatter.java | 63 ++++++++++++++++++++++ src/core/lombok/javac/apt/LombokProcessor.java | 2 +- src/delombok/lombok/delombok/Delombok.java | 2 + src/delombok/lombok/delombok/DelombokApp.java | 2 + .../lombok/delombok/ant/DelombokTaskImpl.java | 5 ++ src/support/lombok/ant/SimpleTestFormatter.java | 63 ---------------------- test/core/src/lombok/RunTestsViaDelombok.java | 5 ++ 7 files changed, 78 insertions(+), 64 deletions(-) create mode 100644 src/ant/lombok/ant/SimpleTestFormatter.java delete mode 100644 src/support/lombok/ant/SimpleTestFormatter.java diff --git a/src/ant/lombok/ant/SimpleTestFormatter.java b/src/ant/lombok/ant/SimpleTestFormatter.java new file mode 100644 index 00000000..a2a38420 --- /dev/null +++ b/src/ant/lombok/ant/SimpleTestFormatter.java @@ -0,0 +1,63 @@ +package lombok.ant; + +import java.io.OutputStream; +import java.io.PrintStream; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter; +import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest; + +public class SimpleTestFormatter implements JUnitResultFormatter { + private PrintStream out = System.out; + + @Override + public void addError(Test test, Throwable error) { + logResult(test, "ERR"); + out.println(error.getMessage()); + } + + @Override + public void addFailure(Test test, AssertionFailedError failure) { + logResult(test, "FAIL"); + out.println(failure.getMessage()); + } + + @Override + public void endTest(Test test) { + logResult(test, "PASS"); + } + + @Override + public void startTest(Test test) { } + + @Override + public void endTestSuite(JUnitTest testSuite) throws BuildException { } + + @Override + public void setOutput(OutputStream out) { + this.out = new PrintStream(out); + } + + @Override + public void setSystemError(String msg) { + if (msg.trim().isEmpty()) return; + out.println(msg); + } + + @Override + public void setSystemOutput(String msg) { + if (msg.trim().isEmpty()) return; + out.println(msg); + } + + @Override + public void startTestSuite(JUnitTest testSuite) throws BuildException { } + + private void logResult(Test test, String result) { + out.println("[" + result + "] " + String.valueOf(test)); + out.flush(); + } +} diff --git a/src/core/lombok/javac/apt/LombokProcessor.java b/src/core/lombok/javac/apt/LombokProcessor.java index e9837cc9..6552f15b 100644 --- a/src/core/lombok/javac/apt/LombokProcessor.java +++ b/src/core/lombok/javac/apt/LombokProcessor.java @@ -480,7 +480,7 @@ public class LombokProcessor extends AbstractProcessor { } /** Useful from jdk9 and up; required from jdk16 and up. This code is supposed to gracefully do nothing on jdk8 and below, as this operation isn't needed there. */ - private static void addOpensForLombok() { + public static void addOpensForLombok() { Class cModule; try { cModule = Class.forName("java.lang.Module"); diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 6ab4d3e5..b210bab9 100755 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -61,6 +61,7 @@ import lombok.Lombok; import lombok.javac.CommentCatcher; import lombok.javac.Javac; import lombok.javac.LombokOptions; +import lombok.javac.apt.LombokProcessor; import lombok.permit.Permit; import com.sun.tools.javac.code.Symtab; @@ -314,6 +315,7 @@ public class Delombok { } } + LombokProcessor.addOpensForLombok(); delombok.delombok(); } catch (Exception e) { if (!args.quiet) { diff --git a/src/delombok/lombok/delombok/DelombokApp.java b/src/delombok/lombok/delombok/DelombokApp.java index f5a5fc81..ef3bbd50 100644 --- a/src/delombok/lombok/delombok/DelombokApp.java +++ b/src/delombok/lombok/delombok/DelombokApp.java @@ -36,6 +36,7 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; import lombok.core.LombokApp; +import lombok.javac.apt.LombokProcessor; import lombok.permit.Permit; import lombok.spi.Provides; @@ -173,6 +174,7 @@ public class DelombokApp extends LombokApp { } private void runDirectly(List args) { + LombokProcessor.addOpensForLombok(); Delombok.main(args.toArray(new String[0])); } diff --git a/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java b/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java index bd2f93e7..f2cd80e1 100644 --- a/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java +++ b/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java @@ -30,6 +30,7 @@ import java.util.List; import lombok.delombok.Delombok; import lombok.delombok.Delombok.InvalidFormatOptionException; +import lombok.javac.apt.LombokProcessor; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Location; @@ -46,6 +47,10 @@ public class DelombokTaskImpl { private Path path; private List formatOptions = new ArrayList(); + static { + LombokProcessor.addOpensForLombok(); + } + public void execute(Location location) throws BuildException { if (fromDir == null && path == null) throw new BuildException("Either 'from' attribute, or nested tags are required."); if (fromDir != null && path != null) throw new BuildException("You can't specify both 'from' attribute and nested filesets. You need one or the other."); diff --git a/src/support/lombok/ant/SimpleTestFormatter.java b/src/support/lombok/ant/SimpleTestFormatter.java deleted file mode 100644 index a2a38420..00000000 --- a/src/support/lombok/ant/SimpleTestFormatter.java +++ /dev/null @@ -1,63 +0,0 @@ -package lombok.ant; - -import java.io.OutputStream; -import java.io.PrintStream; - -import junit.framework.AssertionFailedError; -import junit.framework.Test; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter; -import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest; - -public class SimpleTestFormatter implements JUnitResultFormatter { - private PrintStream out = System.out; - - @Override - public void addError(Test test, Throwable error) { - logResult(test, "ERR"); - out.println(error.getMessage()); - } - - @Override - public void addFailure(Test test, AssertionFailedError failure) { - logResult(test, "FAIL"); - out.println(failure.getMessage()); - } - - @Override - public void endTest(Test test) { - logResult(test, "PASS"); - } - - @Override - public void startTest(Test test) { } - - @Override - public void endTestSuite(JUnitTest testSuite) throws BuildException { } - - @Override - public void setOutput(OutputStream out) { - this.out = new PrintStream(out); - } - - @Override - public void setSystemError(String msg) { - if (msg.trim().isEmpty()) return; - out.println(msg); - } - - @Override - public void setSystemOutput(String msg) { - if (msg.trim().isEmpty()) return; - out.println(msg); - } - - @Override - public void startTestSuite(JUnitTest testSuite) throws BuildException { } - - private void logResult(Test test, String result) { - out.println("[" + result + "] " + String.valueOf(test)); - out.flush(); - } -} diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java index 13acdf55..08e3283f 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -62,10 +62,15 @@ import lombok.delombok.Delombok; import lombok.javac.CapturingDiagnosticListener; import lombok.javac.Javac; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; +import lombok.javac.apt.LombokProcessor; public class RunTestsViaDelombok extends AbstractRunTests { private Delombok delombok = new Delombok(); + static { + LombokProcessor.addOpensForLombok(); + } + @Override public boolean transformCode(Collection messages, StringWriter result, final File file, String encoding, Map formatPreferences, int version, boolean checkPositions) throws Throwable { delombok.setVerbose(true); -- cgit