diff options
-rw-r--r-- | buildScripts/compile.ant.xml | 18 | ||||
-rw-r--r-- | buildScripts/create-eclipse-project.ant.xml | 3 | ||||
-rw-r--r-- | buildScripts/create-intellij-project.ant.xml | 3 | ||||
-rw-r--r-- | buildScripts/maven.ant.xml | 3 | ||||
-rw-r--r-- | doc/changelog.markdown | 1 | ||||
-rw-r--r-- | src/eclipseAgent/lombok/eclipse/agent/MavenEcjBootstrapApp.java | 171 | ||||
-rw-r--r-- | src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java | 24 | ||||
-rw-r--r-- | src/mavenEcjBootstrapAgent/lombok/launch/MavenEcjBootstrapAgent.java | 83 | ||||
-rw-r--r-- | test/transform/resource/after-delombok/ExtensionMethodFunctional.java | 1 | ||||
-rw-r--r-- | test/transform/resource/after-ecj/ExtensionMethodFunctional.java | 1 | ||||
-rw-r--r-- | test/transform/resource/before/ExtensionMethodFunctional.java | 2 | ||||
-rw-r--r-- | website/templates/setup/ecj-in-maven-pom-example.xml | 81 | ||||
-rw-r--r-- | website/templates/setup/ecj.html | 79 | ||||
-rw-r--r-- | website/templates/setup/maven.html | 6 |
14 files changed, 371 insertions, 105 deletions
diff --git a/buildScripts/compile.ant.xml b/buildScripts/compile.ant.xml index 23a8a63c..e4283c29 100644 --- a/buildScripts/compile.ant.xml +++ b/buildScripts/compile.ant.xml @@ -1,5 +1,5 @@ <!-- - Copyright (C) 2020-2021 The Project Lombok Authors. + Copyright (C) 2020-2022 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 @@ -74,7 +74,21 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil </jar> </target> - <target name="compile" depends="version, deps, -setup.build, create.spiProcessor" description="Compiles the code"> + <target name="create.mavenEcjBootstrapAgent" depends="-setup.build" description="Compiles the Maven ECJ bootstrap agent"> + <ivy:compile destdir="build/mavenEcjBootstrapAgent" source="1.6" target="1.6" ecj="true"> + <bootclasspath path="${jdk6-rt.loc}" /> + <src path="src/mavenEcjBootstrapAgent" /> + </ivy:compile> + <mkdir dir="build/lombok-main/lombok/launch" /> + <jar destfile="build/lombok-main/lombok/launch/mavenEcjBootstrapAgent.jar" basedir="build/mavenEcjBootstrapAgent"> + <manifest> + <attribute name="Premain-Class" value="lombok.launch.AgentBootstrap" /> + <attribute name="Can-Redefine-Classes" value="true" /> + </manifest> + </jar> + </target> + + <target name="compile" depends="version, deps, -setup.build, create.spiProcessor, create.agentBootstrap" description="Compiles the code"> <!-- 1. Compile stubs. 2. Compile transplants. diff --git a/buildScripts/create-eclipse-project.ant.xml b/buildScripts/create-eclipse-project.ant.xml index b0f5fcca..f9c45bc6 100644 --- a/buildScripts/create-eclipse-project.ant.xml +++ b/buildScripts/create-eclipse-project.ant.xml @@ -1,5 +1,5 @@ <!-- - Copyright (C) 2010-2021 The Project Lombok Authors. + Copyright (C) 2010-2022 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 @@ -34,6 +34,7 @@ This buildfile is part of projectlombok.org. It creates the infrastructure neede <srcdir dir="src/launch" /> <srcdir dir="src/utils" /> <srcdir dir="src/eclipseAgent" /> + <srcdir dir="src/mavenEcjBootstrapAgent" /> <srcdir dir="src/installer" /> <srcdir dir="src/delombok" /> <srcdir dir="src/stubs" srcout="bin/stubs" /> diff --git a/buildScripts/create-intellij-project.ant.xml b/buildScripts/create-intellij-project.ant.xml index f0bba6e4..3a5398dd 100644 --- a/buildScripts/create-intellij-project.ant.xml +++ b/buildScripts/create-intellij-project.ant.xml @@ -1,5 +1,5 @@ <!-- - Copyright (C) 2010-2021 The Project Lombok Authors. + Copyright (C) 2010-2022 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 @@ -45,6 +45,7 @@ This buildfile is part of projectlombok.org. It creates the infrastructure neede <srcdir dir="src/launch" /> <srcdir dir="src/utils" /> <srcdir dir="src/eclipseAgent" /> + <srcdir dir="src/mavenEcjBootstrapAgent" /> <srcdir dir="src/installer" /> <srcdir dir="src/delombok" /> <srcdir dir="src/stubs" /> diff --git a/buildScripts/maven.ant.xml b/buildScripts/maven.ant.xml index 57bb6b99..fe64a611 100644 --- a/buildScripts/maven.ant.xml +++ b/buildScripts/maven.ant.xml @@ -1,5 +1,5 @@ <!-- - Copyright (C) 2020 The Project Lombok Authors. + Copyright (C) 2020-2022 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 @@ -43,6 +43,7 @@ This buildfile is part of projectlombok.org. It makes maven-compatible repositor <fileset dir="src/launch" /> <fileset dir="src/utils" /> <fileset dir="src/eclipseAgent" /> + <fileset dir="src/mavenEcjBootstrapAgent" /> <fileset dir="src/installer" /> <fileset dir="src/delombok" /> <fileset dir="test/transform/src" /> diff --git a/doc/changelog.markdown b/doc/changelog.markdown index 8bdaa918..435388e1 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -4,6 +4,7 @@ Lombok Changelog ### v1.18.23 "Edgy Guinea Pig" * PLATFORM: JDK18 support added. [Issue #3129](https://github.com/projectlombok/lombok/issues/3129). +* PLATFORM: Using ecj and maven? There's now a [command line option to integrate lombok into your build chain](https://projectlombok.org/setup/ecj). [Issue #3143](https://github.com/projectlombok/lombok/issues/3143). * FEATURE: `@ToString` has an annotation parameter called `onlyExplicitlyIncluded`. There's now a config key `lombok.toString.onlyExplicitlyIncluded` to set this property as well. [Issue #2849](https://github.com/projectlombok/lombok/pull/2849). * FEATURE: Turning a field named `uShape` into a getter is tricky: `getUShape` or `getuShape`? The community is split on which style to use. Lombok does `getUShape`, but if you prefer the `getuShape` style, add to `lombok.config`: `lombok.accessors.capitalization = beanspec`. [Issue #2693](https://github.com/projectlombok/lombok/issues/2693) [Pull Request #2996](https://github.com/projectlombok/lombok/pull/2996). Thanks __@YonathanSherwin__! * FEATURE: You can now use `@Accessors(makeFinal = true)` to make `final` getters, setters, and with-ers. [Issue #1456](https://github.com/projectlombok/lombok/issues/1456). diff --git a/src/eclipseAgent/lombok/eclipse/agent/MavenEcjBootstrapApp.java b/src/eclipseAgent/lombok/eclipse/agent/MavenEcjBootstrapApp.java new file mode 100644 index 00000000..7f9d4d36 --- /dev/null +++ b/src/eclipseAgent/lombok/eclipse/agent/MavenEcjBootstrapApp.java @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2022 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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.agent; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.List; + +import com.zwitserloot.cmdreader.CmdReader; +import com.zwitserloot.cmdreader.Description; +import com.zwitserloot.cmdreader.InvalidCommandLineException; +import com.zwitserloot.cmdreader.Shorthand; + +import lombok.core.LombokApp; +import lombok.spi.Provides; + +@Provides +public class MavenEcjBootstrapApp extends LombokApp { + @Override public String getAppName() { + return "createMavenECJBootstrap"; + } + + @Override public String getAppDescription() { + return "Creates .mvn/jvm.config and .mvn/lombok-bootstrap.jar for\n" + + "use with the ECJ compiler."; + } + + private static class CmdArgs { + @Shorthand("w") + @Description("Overwrite existing files. Defaults to false.") + boolean overwrite = false; + + @Shorthand("o") + @Description("The root of a Maven project. Defaults to the current working directory.") + String output; + + @Shorthand({"h", "?"}) + @Description("Shows this help text") + boolean help; + } + + @Override public int runApp(List<String> rawArgs) throws Exception { + CmdReader<CmdArgs> reader = CmdReader.of(CmdArgs.class); + CmdArgs args; + try { + args = reader.make(rawArgs.toArray(new String[0])); + } catch (InvalidCommandLineException e) { + printHelp(reader, e.getMessage(), System.err); + return 1; + } + + if (args.help) { + printHelp(reader, null, System.out); + return 0; + } + + return createBootstrap(args.output, args.overwrite); + } + + private int createBootstrap(String root, boolean overwrite) { + File mvn = new File(root, ".mvn"); + int result = 0; + if (result == 0) result = makeMvn(mvn); + if (result == 0) result = makeJvmConfig(mvn, overwrite); + if (result == 0) result = makeJar(mvn, overwrite); + return result; + } + + private int makeMvn(File mvn) { + int result = 0; + Exception err = null; + try { + if (!mvn.exists() && !mvn.mkdirs()) result = 1; + } catch (Exception e) { + result = 1; + err = e; + } + if (result != 0) { + System.err.println("Could not create " + mvn.getPath()); + if (err != null) err.printStackTrace(System.err); + } + return result; + } + + private int makeJvmConfig(File mvn, boolean overwrite) { + File jvmConfig = new File(mvn, "jvm.config"); + if (jvmConfig.exists() && !overwrite) { + System.err.println(canonical(jvmConfig) + " exists but '-w' not specified."); + return 1; + } + try { + FileWriter writer = new FileWriter(jvmConfig); + writer.write("-javaagent:.mvn/lombok-bootstrap.jar"); + writer.flush(); + writer.close(); + System.out.println("Successfully created: " + canonical(jvmConfig)); + return 0; + } catch (Exception e) { + System.err.println("Could not create: " + canonical(jvmConfig)); + e.printStackTrace(System.err); + return 1; + } + } + + private int makeJar(File mvn, boolean overwrite) { + File jar = new File(mvn, "lombok-bootstrap.jar"); + if (jar.exists() && !overwrite) { + System.err.println(canonical(jar) + " but '-w' not specified."); + return 1; + } + try { + InputStream input = MavenEcjBootstrapApp.class.getResourceAsStream("/lombok/launch/mavenEcjBootstrapAgent.jar"); + FileOutputStream output = new FileOutputStream(jar); + try { + byte[] buffer = new byte[4096]; + int length; + while ((length = input.read(buffer)) > 0) output.write(buffer, 0, length); + output.flush(); + output.close(); + System.out.println("Successfully created: " + canonical(jar)); + return 0; + } finally { + try { + output.close(); + } catch (Exception ignore) {} + } + } catch (Exception e) { + System.err.println("Could not create: " + canonical(jar)); + e.printStackTrace(System.err); + return 1; + } + } + + private static String canonical(File out) { + try { + return out.getCanonicalPath(); + } catch (Exception e) { + return out.getAbsolutePath(); + } + } + + private void printHelp(CmdReader<CmdArgs> reader, String message, PrintStream out) { + if (message != null) { + out.println(message); + out.println("----------------------------"); + } + out.println(reader.generateCommandLineHelp("java -jar lombok.jar createMavenECJBootstrap")); + } +} diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java index 2e540b5e..7743f9c6 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2021 The Project Lombok Authors. + * Copyright (C) 2012-2022 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 @@ -47,6 +47,7 @@ import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; import org.eclipse.jdt.internal.compiler.ast.Expression; import org.eclipse.jdt.internal.compiler.ast.MessageSend; import org.eclipse.jdt.internal.compiler.ast.NameReference; @@ -298,7 +299,7 @@ public class PatchExtensionMethod { List<TypeBinding> argumentTypes = new ArrayList<TypeBinding>(); for (Expression argument : arguments) { TypeBinding argumentType = argument.resolvedType; - if (argumentType == null && Reflection.isFunctionalExpression(argument)) { + if (argumentType == null && requiresPolyBinding(argument)) { argumentType = Reflection.getPolyTypeBinding(argument); } if (argumentType == null) { @@ -338,8 +339,8 @@ public class PatchExtensionMethod { } else { param = parameters[i]; } - // Resolve types for lambdas - if (Reflection.isFunctionalExpression(arg)) { + // Resolve types for polys + if (requiresPolyBinding(arg)) { arg.setExpectedType(param); arg.resolveType(scope); } @@ -377,6 +378,10 @@ public class PatchExtensionMethod { MessageSend_postponedErrors.clear(methodCall); return resolvedType; } + + private static boolean requiresPolyBinding(Expression argument) { + return Reflection.isFunctionalExpression(argument) || argument instanceof ConditionalExpression && Reflection.isPolyExpression(argument); + } private static NameReference createNameRef(TypeBinding typeBinding, ASTNode source) { long p = ((long) source.sourceStart << 32) | source.sourceEnd; @@ -407,6 +412,7 @@ public class PatchExtensionMethod { public static final Field argumentTypes = Permit.permissiveGetField(MessageSend.class, "argumentTypes"); public static final Field argumentsHaveErrors = Permit.permissiveGetField(MessageSend.class, "argumentsHaveErrors"); public static final Field inferenceContexts = Permit.permissiveGetField(MessageSend.class, "inferenceContexts"); + private static final Method isPolyExpression = Permit.permissiveGetMethod(Expression.class, "isPolyExpression"); private static final Class<?> functionalExpression; private static final Constructor<?> polyTypeBindingConstructor; @@ -432,6 +438,16 @@ public class PatchExtensionMethod { return functionalExpression.isInstance(expression); } + public static boolean isPolyExpression(Expression expression) { + if (isPolyExpression == null) return false; + try { + return (Boolean) isPolyExpression.invoke(expression); + } catch (Exception e) { + // Ignore + } + return false; + } + public static TypeBinding getPolyTypeBinding(Expression expression) { if (polyTypeBindingConstructor == null) return null; try { diff --git a/src/mavenEcjBootstrapAgent/lombok/launch/MavenEcjBootstrapAgent.java b/src/mavenEcjBootstrapAgent/lombok/launch/MavenEcjBootstrapAgent.java new file mode 100644 index 00000000..b36e591f --- /dev/null +++ b/src/mavenEcjBootstrapAgent/lombok/launch/MavenEcjBootstrapAgent.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2022 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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.launch; + +import java.lang.instrument.ClassFileTransformer; +import java.lang.instrument.IllegalClassFormatException; +import java.lang.instrument.Instrumentation; +import java.net.URL; +import java.net.URLClassLoader; +import java.security.ProtectionDomain; +import java.util.jar.JarFile; + +/** + * This Java agent does not transform bytecode, but acts as a watcher that can + * figure out when it is appropriate to load Lombok itself within a Maven + * execution. + * + * It relies on several facts: + * <ul> + * <li>maven-compiler-plugin contains an {@code AbstractCompilerMojo} class that + * compiler instances extend. + * <li>Maven loaders are {@code ClassRealms}, which extend {@code URLClassLoader}. + * <li>Each plugin dependency in the <em>pom.xml </em>is represented as a file URL on the + * ClassRealm that points to the artifact. + * <li>URLs to Maven artifacts contain the group and artifact ids + * ({@code [...]/groupid/artifactid/ver/artifactid-ver.jar}). + * <li>The Lombok Java agent class is {@code lombok.launch.Agent}. + * </ul> + * Given all of the above, the transformer simply waits for {@code AbstractCompilerMojo} + * to be loaded, then uses the loader to find the path to the Lombok jar file, + * and finally loads the Lombok agent using reflection. + */ +public final class MavenEcjBootstrapAgent { + private static final String MAVEN_COMPILER_TRIGGER_CLASS = "org/apache/maven/plugin/compiler/AbstractCompilerMojo"; + private static final String LOMBOK_URL_IDENTIFIER = "/org/projectlombok/lombok/"; + private static final String LOMBOK_AGENT_CLASS = "lombok.launch.Agent"; + private static final byte[] NOT_TRANSFORMED = null; + + private MavenEcjBootstrapAgent() {} + + public static void premain(final String agentArgs, final Instrumentation instrumentation) { + instrumentation.addTransformer(new ClassFileTransformer() { + @Override public byte[] transform(final ClassLoader loader, final String className, final Class<?> cbr, final ProtectionDomain pd, final byte[] cfb) throws IllegalClassFormatException { + if (MAVEN_COMPILER_TRIGGER_CLASS.equals(className)) { + for (final URL url : ((URLClassLoader) loader).getURLs()) { + if (url.getPath().contains(LOMBOK_URL_IDENTIFIER)) { + try { + instrumentation.appendToSystemClassLoaderSearch(new JarFile(url.getPath())); + MavenEcjBootstrapAgent.class.getClassLoader().loadClass(LOMBOK_AGENT_CLASS).getDeclaredMethod("premain", String.class, Instrumentation.class).invoke(null, agentArgs, instrumentation); + instrumentation.removeTransformer(this); + break; + } catch (Exception e) { + // There are no appropriate loggers available at + // this point in time. + e.printStackTrace(System.err); + } + } + } + } + return NOT_TRANSFORMED; + } + }); + } +} diff --git a/test/transform/resource/after-delombok/ExtensionMethodFunctional.java b/test/transform/resource/after-delombok/ExtensionMethodFunctional.java index 2b82a957..40d0d4df 100644 --- a/test/transform/resource/after-delombok/ExtensionMethodFunctional.java +++ b/test/transform/resource/after-delombok/ExtensionMethodFunctional.java @@ -11,6 +11,7 @@ class ExtensionMethodFunctional { test = ExtensionMethodFunctional.Extensions.map(test, s -> ExtensionMethodFunctional.Extensions.reverse(s)); ExtensionMethodFunctional.Extensions.consume(test, s -> System.out.println("1: " + s), s -> System.out.println("2: " + s)); ExtensionMethodFunctional.Extensions.consume(test, System.out::println, System.out::println); + ExtensionMethodFunctional.Extensions.consume(test, test.length() > 0 ? System.out::println : null); ExtensionMethodFunctional.Extensions.toList1(Stream.of("a", "b", "c").map(String::toUpperCase)); List<Integer> i2 = ExtensionMethodFunctional.Extensions.toList2(Stream.of("a", "b", "c").map(String::toUpperCase)); } diff --git a/test/transform/resource/after-ecj/ExtensionMethodFunctional.java b/test/transform/resource/after-ecj/ExtensionMethodFunctional.java index 0971a9be..3cd29e44 100644 --- a/test/transform/resource/after-ecj/ExtensionMethodFunctional.java +++ b/test/transform/resource/after-ecj/ExtensionMethodFunctional.java @@ -36,6 +36,7 @@ import lombok.experimental.ExtensionMethod; test = ExtensionMethodFunctional.Extensions.map(test, (<no type> s) -> ExtensionMethodFunctional.Extensions.reverse(s)); ExtensionMethodFunctional.Extensions.consume(test, (<no type> s) -> System.out.println(("1: " + s)), (<no type> s) -> System.out.println(("2: " + s))); ExtensionMethodFunctional.Extensions.consume(test, System.out::println, System.out::println); + ExtensionMethodFunctional.Extensions.consume(test, ((test.length() > 0) ? System.out::println : null)); ExtensionMethodFunctional.Extensions.toList1(Stream.of("a", "b", "c").map(String::toUpperCase)); List<Integer> i2 = ExtensionMethodFunctional.Extensions.toList2(Stream.of("a", "b", "c").map(String::toUpperCase)); } diff --git a/test/transform/resource/before/ExtensionMethodFunctional.java b/test/transform/resource/before/ExtensionMethodFunctional.java index 8586dd7a..20fe2a36 100644 --- a/test/transform/resource/before/ExtensionMethodFunctional.java +++ b/test/transform/resource/before/ExtensionMethodFunctional.java @@ -16,6 +16,8 @@ class ExtensionMethodFunctional { test.consume(s -> System.out.println("1: " + s), s -> System.out.println("2: " + s)); test.consume(System.out::println, System.out::println); + test.consume(test.length() > 0 ? System.out::println : null); + Stream.of("a", "b", "c").map(String::toUpperCase).toList1(); List<Integer> i2 = Stream.of("a", "b", "c").map(String::toUpperCase).toList2(); } diff --git a/website/templates/setup/ecj-in-maven-pom-example.xml b/website/templates/setup/ecj-in-maven-pom-example.xml deleted file mode 100644 index 3bb10722..00000000 --- a/website/templates/setup/ecj-in-maven-pom-example.xml +++ /dev/null @@ -1,81 +0,0 @@ -<#noparse> -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.projectlombok</groupId> - <artifactId>eclipse-compiler-test</artifactId> - <version>1.0-SNAPSHOT</version> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> -</#noparse> - <lombok.version>${version}</lombok.version> -<#noparse> - </properties> - - <dependencies> - <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <version>${lombok.version}</version> - <scope>provided</scope> - </dependency> - </dependencies> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.8.1</version> - <configuration> - <compilerId>eclipse</compilerId> - <release>11</release> - </configuration> - <dependencies> - <dependency> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-compiler-eclipse</artifactId> - <version>2.8.6</version> - </dependency> - <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <version>${lombok.version}</version> - </dependency> - </dependencies> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <version>3.1.1</version> - <executions> - <execution> - <id>get-lombok</id> - <goals> - <goal>copy</goal> - </goals> - <configuration> - <artifactItems> - <artifactItem> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <version>${lombok.version}</version> - <type>jar</type> - <outputDirectory>${project.build.directory}</outputDirectory> - <destFileName>lombok.jar</destFileName> - </artifactItem> - </artifactItems> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </pluginManagement> - </build> -</project> -</#noparse> diff --git a/website/templates/setup/ecj.html b/website/templates/setup/ecj.html index e01bc653..d888938a 100644 --- a/website/templates/setup/ecj.html +++ b/website/templates/setup/ecj.html @@ -1,32 +1,81 @@ <#import "_setup.html" as s> -<@s.scaffold title="ecj"> +<@s.scaffold title="ECJ"> <@s.introduction> <p> - ecj (the eclipse standalone compiler) is compatible with lombok. Use the following command line to enable lombok with ecj: + ECJ (the Eclipse standalone compiler) is compatible with Lombok. Use the following command line to enable Lombok with ECJ: <pre>java <strong>-javaagent:lombok.jar=ECJ</strong> -jar ecj.jar -cp lombok.jar -source 1.8 <em class="note">(rest of arguments)</em></pre> </p><p> - You may have to add the following VM argument, if you're using an older version of lombok or java: + You may have to add the following VM argument, if you're using an older version of Lombok or Java: <pre><strong>-Xbootclasspath/p:lombok.jar</strong></pre> </p><p> - If you're using a tool based on ecj, adding these VM arguments and adding lombok.jar to the classpath should work. + If you're using a tool based on ECJ, adding these VM arguments and adding <code>lombok.jar</code> to the classpath should work. </p> </@s.introduction> - + <@s.section title="Maven"> <p> - It is possible to <a href="/setup/ecj-in-maven-pom-example.xml">configure</a> <code>maven-compiler-plugin</code> with <code>maven-dependency-plugin</code> and <code>plexus-compiler-eclipse</code>. + Lombok comes with a tiny bootstrap agent that can be included in your project to allow ECJ to easily work with Maven. + To create this agent, run: + <pre>java -jar lombok.jar createMavenECJBootstrap -o <em class="note">/path/to/project/root</em></pre> + </p><p> + The -o path should contain your <code>pom.xml</code>. </p><p> - Before the <code>compile</code> phase, you will have to set your <code>MAVEN_OPTS</code> environment variable to include the <code>javaagent</code> argument. In the example below, <code>target</code> is your <code>${r"${project.build.directory}"}</code>. + This will create two files, <code>.mvn/jvm.config</code> and <code>.mvn/lombok-bootstrap.jar</code>. Maven will use these files + to activate the standard Lombok Java agent at the right time. These can be committed in source control for a portable build. </p><p> - Use the following commands in sequence to enable lombok with ecj in your Maven build: -<pre> -# Make sure you've updated your pom as per <a href="/setup/ecj-in-maven-pom-example.xml">this example</a>. -mvn clean <strong>dependency:copy@get-lombok</strong> -set MAVEN_OPTS=<strong>-javaagent:target/lombok.jar=ECJ</strong> <em class="note">(or your OS's equivalent)</em> -mvn install -set MAVEN_OPTS= <em class="note">(or your OS's equivalent)</em> + You must also update your <code>pom.xml</code> to add Lombok as a dependency to the <code>maven-compiler-plugin</code>. A minimal example follows:<pre> +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.projectlombok</groupId> + <artifactId>eclipse-compiler-test</artifactId> + <version>1.0-SNAPSHOT</version> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <lombok.version>${version}</lombok.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>${lombok.version}</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <pluginManagement> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.10.1</version> + <configuration> + <compilerId>eclipse</compilerId> + </configuration> + <dependencies> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-compiler-eclipse</artifactId> + <version>2.11.1</version> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>${lombok.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> </pre> - </p> +</p> </@s.section> </@s.scaffold> diff --git a/website/templates/setup/maven.html b/website/templates/setup/maven.html index 0e28421f..f6c36822 100644 --- a/website/templates/setup/maven.html +++ b/website/templates/setup/maven.html @@ -37,6 +37,12 @@ </pre> </p> </@s.section> + + <@s.section title="Eclipse Compiler (ECJ/JDT)"> + <p> + Check out the instructions on <a href="/setup/ecj">the ECJ page</a>. + </p> + </@s.section> <@s.section title="Delomboking: The Lombok Maven Plugin"> <p> |