From e6154ac11685d5a9d368fea92793abaebd7c4afe Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 1 Sep 2023 02:40:46 +0200 Subject: [PATCH] [launch] 27 lines of pure magic - act as a maven compiler (compilerid 'lombok') that makes lombok work with any version of javac. Using lombok with maven in this fashion means our com.sun.misc.Unsafe-based method to allow access to javac is no longer needed, and basic reflection is sufficient. In addition, this route is not on the kill-with-extreme-prejudice list of team OpenJDK. --- buildScripts/compile.ant.xml | 25 +++++++++++++++++ buildScripts/create-eclipse-project.ant.xml | 2 ++ buildScripts/ivy.xml | 3 +++ buildScripts/setup.ant.xml | 3 ++- .../mavenplugin/LombokedJavacCompiler.java | 27 +++++++++++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/maven-plugin/lombok/mavenplugin/LombokedJavacCompiler.java diff --git a/buildScripts/compile.ant.xml b/buildScripts/compile.ant.xml index cce756f7a..bfe061794 100644 --- a/buildScripts/compile.ant.xml +++ b/buildScripts/compile.ant.xml @@ -199,6 +199,16 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil + + + + + + + + + + @@ -235,6 +245,20 @@ lombok.launch.AnnotationProcessorHider$ClaimingProcessor lombok.launch.AnnotationProcessorHider$AnnotationProcessor,isolating lombok.launch.AnnotationProcessorHider$ClaimingProcessor,isolating + + + + + + org.codehaus.plexus.compiler.Compiler + lombok + lombok.mavenplugin.LombokedJavacCompiler + + false + + + +]]> @@ -275,6 +299,7 @@ lombok.launch.AnnotationProcessorHider$ClaimingProcessor,isolating + diff --git a/buildScripts/create-eclipse-project.ant.xml b/buildScripts/create-eclipse-project.ant.xml index e475bc8e5..0a0c759aa 100644 --- a/buildScripts/create-eclipse-project.ant.xml +++ b/buildScripts/create-eclipse-project.ant.xml @@ -34,6 +34,7 @@ This buildfile is part of projectlombok.org. It creates the infrastructure neede + @@ -52,6 +53,7 @@ This buildfile is part of projectlombok.org. It creates the infrastructure neede + diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml index 1f6fb3784..b4a8918c2 100644 --- a/buildScripts/ivy.xml +++ b/buildScripts/ivy.xml @@ -17,6 +17,7 @@ + @@ -42,6 +43,8 @@ + + diff --git a/buildScripts/setup.ant.xml b/buildScripts/setup.ant.xml index 092c2ab28..f203a9112 100644 --- a/buildScripts/setup.ant.xml +++ b/buildScripts/setup.ant.xml @@ -314,13 +314,14 @@ This buildfile is part of projectlombok.org. It sets up the build itself. - + + diff --git a/src/maven-plugin/lombok/mavenplugin/LombokedJavacCompiler.java b/src/maven-plugin/lombok/mavenplugin/LombokedJavacCompiler.java new file mode 100644 index 000000000..15f16d8db --- /dev/null +++ b/src/maven-plugin/lombok/mavenplugin/LombokedJavacCompiler.java @@ -0,0 +1,27 @@ +package lombok.mavenplugin; + +import java.util.HashMap; +import java.util.Map; + +import org.codehaus.plexus.compiler.CompilerConfiguration; +import org.codehaus.plexus.compiler.CompilerException; +import org.codehaus.plexus.compiler.CompilerResult; +import org.codehaus.plexus.compiler.javac.JavacCompiler; + +public class LombokedJavacCompiler extends JavacCompiler { + @Override public String getCompilerId() { + return "lombok"; + } + + private static final String[] LOMBOK_ADD_OPENS_C_S_T_J = {"code", "comp", "file", "main", "model", "parser", "processing", "tree", "util"}; + + @Override public CompilerResult performCompile(CompilerConfiguration conf) throws CompilerException { + conf.setFork(true); + Map out = new HashMap(); + Map map = conf.getCustomCompilerArgumentsAsMap(); + if (map != null) out.putAll(map); + for (String n : LOMBOK_ADD_OPENS_C_S_T_J) out.put("-J--add-opens=jdk.compiler/com.sun.tools.javac." + n + "=ALL-UNNAMED", null); + conf.setCustomCompilerArgumentsAsMap(out); + return super.performCompile(conf); + } +}