Skip to content

Commit 2388f91

Browse files
authored
Add EnableLombokAnnotationProcessor to LombokBestPractices (#1052)
Closes #866
1 parent fecaa2e commit 2388f91

3 files changed

Lines changed: 36 additions & 56 deletions

File tree

src/main/resources/META-INF/rewrite/lombok.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ recipeList:
4040
- org.openrewrite.maven.ExcludeDependency:
4141
groupId: org.projectlombok
4242
artifactId: lombok
43+
- org.openrewrite.java.migrate.EnableLombokAnnotationProcessor
4344
---
4445
type: specs.openrewrite.org/v1beta/recipe
4546
name: org.openrewrite.java.migrate.lombok.UpdateLombokToJava11

src/main/resources/META-INF/rewrite/recipes.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.l
337337
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lang.MigrateRuntimeVersionMajorToFeature,Use `Runtime.Version#feature()`,Use `Runtime.Version#feature()` instead of the deprecated `Runtime.Version#major()` in Java 10 or higher.,2,,`java.lang` APIs,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,
338338
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lang.MigrateRuntimeVersionMinorToInterim,Use `Runtime.Version#interim()`,Use `Runtime.Version#interim()` instead of the deprecated `Runtime.Version#minor()` in Java 10 or higher.,2,,`java.lang` APIs,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,
339339
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lang.MigrateRuntimeVersionSecurityToUpdate,Use `Runtime.Version#update()`,Use `Runtime.Version#update()` instead of the deprecated `Runtime.Version#security()` in Java 10 or higher.,2,,`java.lang` APIs,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,
340-
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lang.UseVar,Use local variable type inference,"Apply local variable type inference (`var`) for primitives and objects. These recipes can cause unused imports, be advised to run `org.openrewrite.java.RemoveUnusedImports afterwards.",5,,`java.lang` APIs,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,
340+
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lang.UseVar,Use local variable type inference,"Apply local variable type inference (`var`) for primitives and objects. These recipes can cause unused imports, be advised to run `org.openrewrite.java.RemoveUnusedImports afterwards.",7,,`java.lang` APIs,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,
341341
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lang.FindVirtualThreadOpportunities,Find Virtual Thread opportunities,Find opportunities to convert existing code to use Virtual Threads.,10,,`java.lang` APIs,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.java.table.MethodCalls"",""displayName"":""Method calls"",""instanceName"":""Method calls"",""description"":""The text of matching method invocations."",""columns"":[{""name"":""sourceFile"",""type"":""String"",""displayName"":""Source file"",""description"":""The source file that the method call occurred in.""},{""name"":""method"",""type"":""String"",""displayName"":""Method call"",""description"":""The text of the method call.""},{""name"":""className"",""type"":""String"",""displayName"":""Class name"",""description"":""The class name of the method call.""},{""name"":""methodName"",""type"":""String"",""displayName"":""Method name"",""description"":""The method name of the method call.""},{""name"":""argumentTypes"",""type"":""String"",""displayName"":""Argument types"",""description"":""The argument types of the method call.""}]}]"
342342
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lang.FindNonVirtualExecutors,Find non-virtual `ExecutorService` creation,Find all places where static `java.util.concurrent.Executors` method creates a non-virtual `java.util.concurrent.ExecutorService`. This recipe can be used to search fro `ExecutorService` that can be replaced by Virtual Thread executor.,7,,`java.lang` APIs,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.java.table.MethodCalls"",""displayName"":""Method calls"",""instanceName"":""Method calls"",""description"":""The text of matching method invocations."",""columns"":[{""name"":""sourceFile"",""type"":""String"",""displayName"":""Source file"",""description"":""The source file that the method call occurred in.""},{""name"":""method"",""type"":""String"",""displayName"":""Method call"",""description"":""The text of the method call.""},{""name"":""className"",""type"":""String"",""displayName"":""Class name"",""description"":""The class name of the method call.""},{""name"":""methodName"",""type"":""String"",""displayName"":""Method name"",""description"":""The method name of the method call.""},{""name"":""argumentTypes"",""type"":""String"",""displayName"":""Argument types"",""description"":""The argument types of the method call.""}]}]"
343343
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lang.var.UseVarForConstructors,Use `var` for constructor call assignments,"Replace explicit type declarations with `var` when the variable is initialized with a constructor call of exactly the same type. Does not transform when declared type differs from constructor type (e.g., interface vs implementation).",1,Var,`java.lang` APIs,Modernize,Java,,,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,
@@ -373,7 +373,7 @@ Limitations:
373373
- Method name swaps or circular renaming within a class cannot be performed because the names block each other.
374374
E.g. `int getFoo() { return ba; } int getBa() { return foo; }` stays as it is.",1,,Lombok,Modernize,Java,,Recipes for working with [Lombok](https://projectlombok.org/).,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,
375375
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lombok.LombokValueToRecord,Convert `@lombok.Value` class to Record,Convert Lombok `@Value` annotated classes to standard Java Records.,1,,Lombok,Modernize,Java,,Recipes for working with [Lombok](https://projectlombok.org/).,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,"[{""name"":""useExactToString"",""type"":""Boolean"",""displayName"":""Add a `toString()` implementation matching Lombok"",""description"":""When set the `toString` format from Lombok is used in the migrated record.""}]",
376-
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lombok.LombokBestPractices,Lombok Best Practices,Applies all recipes that enforce best practices for using Lombok.,24,,Lombok,Modernize,Java,,Recipes for working with [Lombok](https://projectlombok.org/).,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,
376+
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lombok.LombokBestPractices,Lombok Best Practices,Applies all recipes that enforce best practices for using Lombok.,27,,Lombok,Modernize,Java,,Recipes for working with [Lombok](https://projectlombok.org/).,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,"[{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]"
377377
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lombok.UpdateLombokToJava11,Migrate Lombok to a Java 11 compatible version,Update Lombok dependency to a version that is compatible with Java 11 and migrate experimental Lombok types that have been promoted.,9,,Lombok,Modernize,Java,,Recipes for working with [Lombok](https://projectlombok.org/).,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,,
378378
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lombok.log.UseCommonsLog,Use `@CommonsLog` instead of explicit fields,Prefer the lombok annotation `@CommonsLog` over explicitly written out `org.apache.commons.logging.Log` fields.,1,Log,Lombok,Modernize,Java,,Recipes for working with [Lombok](https://projectlombok.org/).,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,"[{""name"":""fieldName"",""type"":""String"",""displayName"":""Name of the log field"",""description"":""Name of the log field to replace. If not specified, the field name is not checked and any field that satisfies the other checks is converted."",""example"":""LOGGER""}]",
379379
maven,org.openrewrite.recipe:rewrite-migrate-java,org.openrewrite.java.migrate.lombok.log.UseJBossLog,Use `@JBossLog` instead of explicit fields,Prefer the lombok annotation `@JBossLog` over explicitly written out `org.jboss.logging.Logger` fields.,1,Log,Lombok,Modernize,Java,,Recipes for working with [Lombok](https://projectlombok.org/).,Modernize your code to best use the project's current JDK version. Take advantage of newly available APIs and reduce the dependency of your code on third party dependencies where there is equivalent functionality in the Java standard library.,Basic building blocks for transforming Java code.,"[{""name"":""fieldName"",""type"":""String"",""displayName"":""Name of the log field"",""description"":""Name of the log field to replace. If not specified, the field name is not checked and any field that satisfies the other checks is converted."",""example"":""LOGGER""}]",

src/test/java/org/openrewrite/java/migrate/lombok/LombokBestPracticesTest.java

Lines changed: 33 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
import org.openrewrite.test.RewriteTest;
2222
import org.openrewrite.test.SourceSpec;
2323

24-
import java.util.regex.Matcher;
25-
import java.util.regex.Pattern;
26-
2724
import static org.assertj.core.api.Assertions.assertThat;
2825
import static org.openrewrite.java.Assertions.mavenProject;
2926
import static org.openrewrite.maven.Assertions.pomXml;
@@ -32,63 +29,45 @@ class LombokBestPracticesTest implements RewriteTest {
3229

3330
@Override
3431
public void defaults(RecipeSpec spec) {
35-
spec.recipeFromResource("/META-INF/rewrite/lombok.yml",
36-
"org.openrewrite.java.migrate.lombok.LombokBestPractices");
32+
spec.recipeFromResources("org.openrewrite.java.migrate.lombok.LombokBestPractices");
3733
}
3834

3935
@DocumentExample
4036
@Test
4137
void providedScope() {
4238
rewriteRun(
43-
pomXml(
44-
//language=xml
45-
"""
46-
<project>
47-
<modelVersion>4.0.0</modelVersion>
48-
<groupId>com.example</groupId>
49-
<artifactId>example</artifactId>
50-
<version>1.0.0</version>
51-
<dependencies>
52-
<dependency>
53-
<groupId>org.projectlombok</groupId>
54-
<artifactId>lombok</artifactId>
55-
<version>1.18.6</version>
56-
</dependency>
57-
<dependency>
58-
<groupId>org.projectlombok</groupId>
59-
<artifactId>lombok-mapstruct-binding</artifactId>
60-
<version>0.2.0</version>
61-
</dependency>
62-
</dependencies>
63-
</project>
64-
""",
65-
spec -> spec.after(pom -> {
66-
Matcher version = Pattern.compile("1.[1-9]\\d+(.\\d+)?").matcher(pom);
67-
assertThat(version.find()).isTrue();
68-
//language=xml
69-
return """
70-
<project>
71-
<modelVersion>4.0.0</modelVersion>
72-
<groupId>com.example</groupId>
73-
<artifactId>example</artifactId>
74-
<version>1.0.0</version>
75-
<dependencies>
76-
<dependency>
77-
<groupId>org.projectlombok</groupId>
78-
<artifactId>lombok</artifactId>
79-
<version>%s</version>
80-
<scope>provided</scope>
81-
</dependency>
82-
<dependency>
83-
<groupId>org.projectlombok</groupId>
84-
<artifactId>lombok-mapstruct-binding</artifactId>
85-
<version>0.2.0</version>
86-
<scope>provided</scope>
87-
</dependency>
88-
</dependencies>
89-
</project>
90-
""".formatted(version.group(0));
91-
})
39+
spec -> spec.expectedCyclesThatMakeChanges(2),
40+
mavenProject("project",
41+
pomXml(
42+
//language=xml
43+
"""
44+
<project>
45+
<modelVersion>4.0.0</modelVersion>
46+
<groupId>com.example</groupId>
47+
<artifactId>example</artifactId>
48+
<version>1.0.0</version>
49+
<dependencies>
50+
<dependency>
51+
<groupId>org.projectlombok</groupId>
52+
<artifactId>lombok</artifactId>
53+
<version>1.18.6</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.projectlombok</groupId>
57+
<artifactId>lombok-mapstruct-binding</artifactId>
58+
<version>0.2.0</version>
59+
</dependency>
60+
</dependencies>
61+
</project>
62+
""",
63+
spec -> spec.after(pom ->
64+
assertThat(pom)
65+
.containsPattern("1.[1-9]\\d+(.\\d+)?")
66+
.containsPattern("<annotationProcessorPaths>(.|\\n)*<path>(.|\\n)*<groupId>org.projectlombok")
67+
.containsPattern("<annotationProcessorPaths>(.|\\n)*<path>(.|\\n)*<artifactId>lombok")
68+
.actual()
69+
)
70+
)
9271
)
9372
);
9473
}

0 commit comments

Comments
 (0)