From 40c589ef08ef5836244e3f9b4ac42961428877d8 Mon Sep 17 00:00:00 2001 From: Andrei Shakirin Date: Fri, 22 Nov 2024 15:53:54 +0100 Subject: [PATCH 01/10] feat: Added recipe to comment deprecated and removed properties without alternative Refs: #634 --- .../spring/InlineCommentSpringProperties.java | 51 +++++++++++++++++++ .../InlineCommentSpringPropertiesTest.java | 32 ++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java create mode 100644 src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java diff --git a/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java b/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java new file mode 100644 index 00000000..0f68d58e --- /dev/null +++ b/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java @@ -0,0 +1,51 @@ +package org.openrewrite.java.spring; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.openrewrite.*; + +import java.util.List; + +@EqualsAndHashCode(callSuper = false) +@Value +public class InlineCommentSpringProperties extends Recipe { + + @Override + public @NotNull @NlsRewrite.DisplayName String getDisplayName() { + return "Comment spring properties"; + } + + @Override + public @NotNull @NlsRewrite.Description String getDescription() { + return "Add inline comments to specified spring properties."; + } + + @Option(displayName = "Property keys list", + description = "The list of names of the property keys to comment.", + example = "management.metrics.binders.files.enabled") + List propertyKeys; + + @Option(displayName = "Inline comment", + description = "Inline comment to be inserted", + example = "this property is deprecated and no longer applicable starting from Spring Boot 3.0.x") + String comment; + + @Override + public @NotNull TreeVisitor getVisitor() { + String inlineComment = " # " + comment; + return new TreeVisitor() { + @Override + public @Nullable Tree visit(@Nullable Tree tree, @NotNull ExecutionContext ctx) { + Tree processingTree = tree; + for (String key : propertyKeys) { + String regex = "(? spec.recipe(new InlineCommentSpringProperties(List.of("test.propertyKey1", "test.propertyKey2"), "my comment")), + yaml(""" + test.propertyKey1: xxx + test.propertyKey2: yyy""", + """ + test.propertyKey1: xxx # my comment + test.propertyKey2: yyy # my comment""", + spec -> spec.path("application.yaml")), + properties(""" + test.propertyKey1: xxx + test.propertyKey2: yyy""", + """ + test.propertyKey1: xxx # my comment + test.propertyKey2: yyy # my comment""", + spec -> spec.path("application.properties"))); + } +} From e4ddc8f3811194bf21d47035c715bbb212d2983c Mon Sep 17 00:00:00 2001 From: Andrei Shakirin Date: Fri, 22 Nov 2024 16:06:21 +0100 Subject: [PATCH 02/10] feat: Added licences in recipe and test files Refs: #634 --- .../spring/InlineCommentSpringProperties.java | 15 +++++++++++++++ .../spring/InlineCommentSpringPropertiesTest.java | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java b/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java index 0f68d58e..52ebc6cf 100644 --- a/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java +++ b/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java @@ -1,3 +1,18 @@ +/* + * Copyright 2021 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.spring; import lombok.EqualsAndHashCode; diff --git a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java index ab8cfb6b..bfcd95fb 100644 --- a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java +++ b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2021 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.spring; import org.junit.jupiter.api.Test; From 1c62a5dcaedcf7ed1ecee19142a61e1c4752bdc3 Mon Sep 17 00:00:00 2001 From: Andrei Shakirin Date: Fri, 22 Nov 2024 16:10:08 +0100 Subject: [PATCH 03/10] feat: Removed NotNull annotations Refs: #634 --- .../java/spring/InlineCommentSpringProperties.java | 6 +++--- .../java/spring/InlineCommentSpringPropertiesTest.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java b/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java index 52ebc6cf..32b68664 100644 --- a/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java +++ b/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java @@ -28,12 +28,12 @@ public class InlineCommentSpringProperties extends Recipe { @Override - public @NotNull @NlsRewrite.DisplayName String getDisplayName() { + public String getDisplayName() { return "Comment spring properties"; } @Override - public @NotNull @NlsRewrite.Description String getDescription() { + public String getDescription() { return "Add inline comments to specified spring properties."; } @@ -48,7 +48,7 @@ public class InlineCommentSpringProperties extends Recipe { String comment; @Override - public @NotNull TreeVisitor getVisitor() { + public TreeVisitor getVisitor() { String inlineComment = " # " + comment; return new TreeVisitor() { @Override diff --git a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java index bfcd95fb..242bc229 100644 --- a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java +++ b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java @@ -23,7 +23,7 @@ import static org.openrewrite.properties.Assertions.properties; import static org.openrewrite.yaml.Assertions.yaml; -public class InlineCommentSpringPropertiesTest implements RewriteTest { +class InlineCommentSpringPropertiesTest implements RewriteTest { @Test void shouldInsertInlineCommentsIntoProperties() { From a41cc367a015e6d7a97cc20579d675c17d8ac300 Mon Sep 17 00:00:00 2001 From: ashakirin <2254222+ashakirin@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:24:08 +0100 Subject: [PATCH 04/10] Update src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../java/spring/InlineCommentSpringPropertiesTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java index 242bc229..97c6fc80 100644 --- a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java +++ b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java @@ -25,6 +25,7 @@ class InlineCommentSpringPropertiesTest implements RewriteTest { + @DocumentExample @Test void shouldInsertInlineCommentsIntoProperties() { rewriteRun( From ac59ef7f7ac65df63540fa122b522c0710c056fd Mon Sep 17 00:00:00 2001 From: ashakirin <2254222+ashakirin@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:24:23 +0100 Subject: [PATCH 05/10] Update src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../java/spring/InlineCommentSpringPropertiesTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java index 97c6fc80..eff17a21 100644 --- a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java +++ b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java @@ -16,6 +16,7 @@ package org.openrewrite.java.spring; import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; import org.openrewrite.test.RewriteTest; import java.util.List; From fffdff681be6865afec1cac554aab01127a297da Mon Sep 17 00:00:00 2001 From: ashakirin <2254222+ashakirin@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:24:35 +0100 Subject: [PATCH 06/10] Update src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../openrewrite/java/spring/InlineCommentSpringProperties.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java b/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java index 32b68664..659dd893 100644 --- a/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java +++ b/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java @@ -52,7 +52,7 @@ public TreeVisitor getVisitor() { String inlineComment = " # " + comment; return new TreeVisitor() { @Override - public @Nullable Tree visit(@Nullable Tree tree, @NotNull ExecutionContext ctx) { + public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) { Tree processingTree = tree; for (String key : propertyKeys) { String regex = "(? Date: Fri, 22 Nov 2024 16:24:46 +0100 Subject: [PATCH 07/10] Update src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../openrewrite/java/spring/InlineCommentSpringProperties.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java b/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java index 659dd893..3fd1ebb1 100644 --- a/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java +++ b/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java @@ -17,7 +17,6 @@ import lombok.EqualsAndHashCode; import lombok.Value; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.openrewrite.*; From 28f58cf3b1c30e665d6626bafb9391942bcfc33e Mon Sep 17 00:00:00 2001 From: ashakirin <2254222+ashakirin@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:24:57 +0100 Subject: [PATCH 08/10] Update src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../java/spring/InlineCommentSpringPropertiesTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java index eff17a21..8a890fc3 100644 --- a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java +++ b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; +import org.openrewrite.DocumentExample; import org.openrewrite.test.RewriteTest; import java.util.List; From 08431f47ca91f5b4802a674450a8aadb1632b615 Mon Sep 17 00:00:00 2001 From: Andrei Shakirin Date: Fri, 22 Nov 2024 16:26:55 +0100 Subject: [PATCH 09/10] feat: Removed doubled import Refs: #634 --- .../java/spring/InlineCommentSpringPropertiesTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java index 8a890fc3..eff17a21 100644 --- a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java +++ b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java @@ -17,7 +17,6 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; -import org.openrewrite.DocumentExample; import org.openrewrite.test.RewriteTest; import java.util.List; From 357c95f2c0c8d2205f5ce2b6783b7b76c727d488 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 23 Nov 2024 16:35:43 +0100 Subject: [PATCH 10/10] Minor polish already ahead of review --- .../spring/InlineCommentSpringProperties.java | 6 +-- .../InlineCommentSpringPropertiesTest.java | 37 +++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java b/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java index 3fd1ebb1..b19c9c6d 100644 --- a/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java +++ b/src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 the original author or authors. + * Copyright 2024 the original author or authors. *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ public class InlineCommentSpringProperties extends Recipe { @Override public String getDisplayName() { - return "Comment spring properties"; + return "Comment Spring properties"; } @Override @@ -43,7 +43,7 @@ public String getDescription() { @Option(displayName = "Inline comment", description = "Inline comment to be inserted", - example = "this property is deprecated and no longer applicable starting from Spring Boot 3.0.x") + example = "This property is deprecated and no longer applicable starting from Spring Boot 3.0.x") String comment; @Override diff --git a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java index eff17a21..0d0a7d08 100644 --- a/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java +++ b/src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 the original author or authors. + * Copyright 2024 the original author or authors. *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,19 +31,34 @@ class InlineCommentSpringPropertiesTest implements RewriteTest { void shouldInsertInlineCommentsIntoProperties() { rewriteRun( spec -> spec.recipe(new InlineCommentSpringProperties(List.of("test.propertyKey1", "test.propertyKey2"), "my comment")), - yaml(""" + //language=yaml + yaml( + """ test.propertyKey1: xxx - test.propertyKey2: yyy""", + test.propertyKey2: yyy + test.propertyKey3: zzz + """, """ test.propertyKey1: xxx # my comment - test.propertyKey2: yyy # my comment""", - spec -> spec.path("application.yaml")), - properties(""" - test.propertyKey1: xxx - test.propertyKey2: yyy""", + test.propertyKey2: yyy # my comment + test.propertyKey3: zzz + """, + spec -> spec.path("application.yaml") + ), + //language=properties + properties( + """ + test.propertyKey1=xxx + test.propertyKey2=yyy + test.propertyKey3=zzz + """, """ - test.propertyKey1: xxx # my comment - test.propertyKey2: yyy # my comment""", - spec -> spec.path("application.properties"))); + test.propertyKey1=xxx # my comment + test.propertyKey2=yyy # my comment + test.propertyKey3=zzz + """, + spec -> spec.path("application.properties") + ) + ); } }