Skip to content

Commit

Permalink
Add Gradle Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 committed Sep 14, 2023
1 parent e6154ac commit 825c4f2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
11 changes: 11 additions & 0 deletions buildScripts/compile.ant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil
<src path="src/core" />
<src path="src/installer" />
<src path="src/eclipseAgent" />
<src path="src/delombok" />
<exclude name="**/*Transplants.java" />
<classpath refid="cp.build" />
<classpath refid="cp.eclipse-oxygen" />
Expand Down Expand Up @@ -209,6 +210,13 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil
<annotationProcessor jar="dist/spiProcessor.jar" processor="lombok.spi.SpiProcessor" />
</ivy:compile>

<ivy:compile destdir="build/lombok-main" source="1.6" target="1.6" ecj="true" nowarn="true">
<bootclasspath location="build/stubs" />
<bootclasspath path="${jdk6-rt.loc}" />
<src path="src/gradle-plugin" />
<classpath refid="cp.gradle-plugin" />
</ivy:compile>

<!-- This is really part of the eclipse agent, but references lombok, so that had to be compiled first -->
<ivy:compile destdir="build/lombok-main/Class50" source="1.5" target="1.6" ecj="true">
<bootclasspath location="build/stubs" />
Expand Down Expand Up @@ -259,6 +267,8 @@ lombok.launch.AnnotationProcessorHider$ClaimingProcessor,isolating</echo>
</components>
</component-set>
]]></echo>
<mkdir dir="build/lombok-main/META-INF/gradle-plugins" />
<echo file="build/lombok-main/META-INF/gradle-plugins/org.projectlombok.lombok.properties">implementation-class=lombok.gradleplugin.LombokPlugin</echo>
</target>

<!-- compiles the bit of API from mapstruct that lombok compiles against. -->
Expand Down Expand Up @@ -300,6 +310,7 @@ lombok.launch.AnnotationProcessorHider$ClaimingProcessor,isolating</echo>
<include name="lombok/launch/**" />
<include name="lombok/delombok/ant/Tasks*" />
<include name="lombok/mavenplugin/*" />
<include name="lombok/gradleplugin/*" />
<include name="lombok/javac/apt/Processor.class" />
<include name="lombok/META-INF/**" />
</patternset>
Expand Down
2 changes: 2 additions & 0 deletions buildScripts/create-eclipse-project.ant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This buildfile is part of projectlombok.org. It creates the infrastructure neede
<srcdir dir="src/utils" />
<srcdir dir="src/ant-plugin" />
<srcdir dir="src/maven-plugin" />
<srcdir dir="src/gradle-plugin" />
<srcdir dir="src/eclipseAgent" />
<srcdir dir="src/mavenEcjBootstrapAgent" />
<srcdir dir="src/installer" />
Expand All @@ -54,6 +55,7 @@ This buildfile is part of projectlombok.org. It creates the infrastructure neede
<conf name="buildtools" sources="sources" />
<conf name="ant-plugin" sources="sources" />
<conf name="maven-plugin" sources="sources" />
<conf name="gradle-plugin" sources="sources" />
<local org="org.projectlombok" name="lombok.patcher" dir="../lombok.patcher" />
<settings>
<url url="https://projectlombok.org/downloads/lombok.eclipse.settings" />
Expand Down
2 changes: 2 additions & 0 deletions buildScripts/ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<conf name="ant-plugin" />
<conf name="maven-plugin" />
<conf name="gradle-plugin" />

<!-- and now for custom configs for testing lombok against -->

Expand Down Expand Up @@ -45,6 +46,7 @@
<dependency org="org.apache.ant" name="ant-junit" rev="1.10.5" conf="ant-plugin->default" />
<dependency org="org.codehaus.plexus" name="plexus-compiler-javac" rev="2.13.0" conf="maven-plugin->default" />
<dependency org="org.codehaus.plexus" name="plexus-container-default" rev="2.1.1" conf="maven-plugin->default" />
<dependency org="dev.gradleplugins" name="gradle-api" rev="8.3" conf="gradle-plugin->default" />

<!-- test deps -->
<dependency org="junit" name="junit" rev="4.13.2" conf="test->default; sources" />
Expand Down
3 changes: 2 additions & 1 deletion buildScripts/setup.ant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,15 @@ This buildfile is part of projectlombok.org. It sets up the build itself.
</macrodef>

<target name="deps" depends="ivy.config, deps.jdk-runtime" description="Downloads all dependencies needed for common tasks">
<ivy:resolve file="buildScripts/ivy.xml" refresh="true" conf="javac6,javac8,ecj8,build,ant-plugin,maven-plugin,eclipse-oxygen,mapstruct,sources,stripe,buildtools,test" />
<ivy:resolve file="buildScripts/ivy.xml" refresh="true" conf="javac6,javac8,ecj8,build,ant-plugin,maven-plugin,gradle-plugin,eclipse-oxygen,mapstruct,sources,stripe,buildtools,test" />
<ivy:retrieve symlink="true" />
<ivy:cachepath pathid="cp.javac6" conf="javac6" />
<ivy:cachepath pathid="cp.javac8" conf="javac8" />
<ivy:cachepath pathid="cp.ecj8" conf="ecj8" />
<ivy:cachepath pathid="cp.build" conf="build" />
<ivy:cachepath pathid="cp.ant-plugin" conf="ant-plugin" />
<ivy:cachepath pathid="cp.maven-plugin" conf="maven-plugin" />
<ivy:cachepath pathid="cp.gradle-plugin" conf="gradle-plugin" />
<ivy:cachepath pathid="cp.eclipse-oxygen" conf="eclipse-oxygen" />
<ivy:cachepath pathid="cp.mapstruct" conf="mapstruct" />
<ivy:cachepath pathid="cp.stripe" conf="stripe" />
Expand Down
37 changes: 37 additions & 0 deletions src/gradle-plugin/lombok/gradleplugin/LombokPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package lombok.gradleplugin;

import java.util.Arrays;
import java.util.List;

import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.tasks.compile.JavaCompile;

public class LombokPlugin implements Plugin<Project> {
private static final List<String> OPENS = Arrays.asList(
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
);

public void apply(Project target) {
target.getTasks().withType(JavaCompile.class).configureEach(new Action<JavaCompile>() {
public void execute(final JavaCompile compileJava) {
compileJava.doFirst("Opens modules for lombok", new Action<Task>() {
public void execute(Task t) {
compileJava.getOptions().setFork(true);
compileJava.getOptions().getForkOptions().getJvmArgs().addAll(OPENS);
}
});
}
});
}
}

0 comments on commit 825c4f2

Please sign in to comment.