Skip to content

Commit

Permalink
Add LombokBestPractices
Browse files Browse the repository at this point in the history
Fixes #658
  • Loading branch information
timtebeek committed Jan 12, 2025
1 parent a7d8d37 commit 8f4253e
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main/resources/META-INF/rewrite/lombok.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.lombok.LombokBestPractices
displayName: Lombok Best Practices
description: >-
Applies all recipes that enforce best practices for using Lombok.
recipeList:
- org.openrewrite.java.migrate.lombok.UpdateLombokToJava11
- org.openrewrite.java.migrate.lombok.log.UseLombokLogAnnotations
- org.openrewrite.java.migrate.lombok.UseLombokGetter
- org.openrewrite.java.migrate.lombok.UseLombokSetter
- org.openrewrite.java.migrate.lombok.UseNoArgsConstructor
- org.openrewrite.maven.ChangeDependencyScope:
groupId: org.projectlombok
artifactId: lombok
newScope: provided
- org.openrewrite.maven.ChangeDependencyScope:
groupId: org.projectlombok
artifactId: lombok-mapstruct-binding
newScope: provided
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.lombok.UpdateLombokToJava11
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2025 the original author or authors.
* <p>
* Licensed under the Moderne Source Available License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://docs.moderne.io/licensing/moderne-source-available-license
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.java.migrate.lombok;

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.maven.Assertions.pomXml;

class LombokBestPracticesTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec.recipeFromResource("/META-INF/rewrite/lombok.yml",
"org.openrewrite.java.migrate.lombok.LombokBestPractices");
}

@DocumentExample
@Test
void providedScope() {
rewriteRun(
pomXml(
//language=xml
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</dependency>
</dependencies>
</project>
""",
spec -> spec.after(pom -> {
Matcher version = Pattern.compile("1.[1-9]\\d+(.\\d+)?").matcher(pom);
assertThat(version.find()).isTrue();
//language=xml
return """
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>%s</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
""".formatted(version.group(0));
})
)
);
}
}

0 comments on commit 8f4253e

Please sign in to comment.