Skip to content

Commit 167d9ce

Browse files
ashakirinsambsnydtimtebeekshanman190TeamModerne
authored
Generate comments for deprecated properties (#639)
* Add relevant context to description of AddSpringDependencyManagementPlugin * Adopt RemoveMethodInvocations from rewrite-java * Remove now-defunct rewrite-templating dependency * refactor: Update Gradle wrapper Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.gradle.UpdateGradleWrapper?organizationId=T3BlblJld3JpdGU%3D#defaults=W3sibmFtZSI6ImFkZElmTWlzc2luZyIsInZhbHVlIjoiRmFsc2UifV0= Co-authored-by: Moderne <[email protected]> * Fix method type following openrewrite/rewrite#4688 * Update method type as well when removing arguments * Fix incorrect path computation for Spring API endpoints (#632) * Fix incorrect path computation for Spring API endpoints The current logic did not cover the case where a `RequestMapping` with a path was defined on the Controller class, and no paths were defined in the `*Mapping` at the method level. * Do not disable the FindApiEndpointsTest * Simplify FindApiEndpoints and SpringRequestMapping * Add for now failing unit test * AnnotationMatcher does not support wildcards --------- Co-authored-by: Tim te Beek <[email protected]> * Add commons codec dependency upgrade * feat: Added recipe to comment deprecated and removed properties without alternative Refs: #634 * feat: Added licences in recipe and test files Refs: #634 * feat: Removed NotNull annotations Refs: #634 * Update src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/main/java/org/openrewrite/java/spring/InlineCommentSpringProperties.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/test/java/org/openrewrite/java/spring/InlineCommentSpringPropertiesTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * feat: Removed doubled import Refs: #634 * feat: Generated comment recipes for deprecated properties without replacement Refs: #634 * feat: Updated comment recipes with the reason Refs: #634 * Update src/test/java/org/openrewrite/java/spring/internal/GeneratePropertiesMigratorConfiguration.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Remove unused import in GeneratePropertiesMigratorConfiguration * Update assertions to ensure yaml comments are modeled as such * fixing SpringFoxToSpringDoc to use 1.x-appropriate springdoc artifact helps with #638 * ChangeSpringPropertyKey does not yet fully support glob * RenameBean Scanning Recipe Refactor (#630) * Refactored the RenameBean recipe into a scanning recipe to allow renaming usages that occur outside the file where the bean is defined. * Add missing language hints * Remove unused `fromDeclaration` methods --------- Co-authored-by: Hudson, Ryan <[email protected]> Co-authored-by: Tim te Beek <[email protected]> * Add MigrateSpringdocCommon recipe (#633) * Add MigrateSpringdocCommon recipe * Apply suggestions from bot Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Fix syntax messed up by bot * Add MigrateSpringdocCommon recipe * Apply suggestions from bot Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Fix syntax messed up by bot * Fix build fail on SpringBoot_1_5 * Fix rebase error * Move to Spring Boot 2.6 tests, to match inclusion in `spring-boot-26.yml` --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tim te Beek <[email protected]> * Add ChangeMethodParameter for modify parameters in Spring Batch method declaration (#631) * Add ChangeMethodParameter for modify parameters in method declaration Signed-off-by: Kun Chang <[email protected]> * Minor polish * Add correct year * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Add UpgradeSkipPolicyParameterType for Spring Batch Signed-off-by: Kun Chang <[email protected]> * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Fix tests * Also show ability to change interface methods --------- Signed-off-by: Kun Chang <[email protected]> Co-authored-by: Tim te Beek <[email protected]> Co-authored-by: Tim te Beek <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Reuse recipe that comments out Yaml properties * Move try into getDeprecations * Limit comment wrangling to `CommentOutSpringPropertyKey` * Rename test to match renamed class * Generate removed property migrations * Regenerated properties for older Spring Boot version * Fix invalid property values --------- Signed-off-by: Kun Chang <[email protected]> Co-authored-by: Sam Snyder <[email protected]> Co-authored-by: Tim te Beek <[email protected]> Co-authored-by: Shannon Pamperl <[email protected]> Co-authored-by: Moderne <[email protected]> Co-authored-by: Adrien Loison <[email protected]> Co-authored-by: Andrei Shakirin <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nick McKinney <[email protected]> Co-authored-by: Ryan Hudson <[email protected]> Co-authored-by: Hudson, Ryan <[email protected]> Co-authored-by: SiBorea <[email protected]> Co-authored-by: Curtis <[email protected]> Co-authored-by: Tim te Beek <[email protected]>
1 parent d870f3e commit 167d9ce

18 files changed

+1457
-298
lines changed

src/main/java/org/openrewrite/java/spring/ChangeSpringPropertyValue.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.jspecify.annotations.Nullable;
2121
import org.openrewrite.*;
2222
import org.openrewrite.internal.StringUtils;
23-
import org.openrewrite.properties.ChangePropertyValue;
2423
import org.openrewrite.properties.tree.Properties;
2524
import org.openrewrite.yaml.tree.Yaml;
2625

@@ -63,7 +62,7 @@ public String getDescription() {
6362

6463
@Option(displayName = "Use relaxed binding",
6564
description = "Whether to match the `propertyKey` using [relaxed binding](https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding) " +
66-
"rules. Default is `true`. Set to `false` to use exact matching.",
65+
"rules. Default is `true`. Set to `false` to use exact matching.",
6766
required = false)
6867
@Nullable
6968
Boolean relaxedBinding;
@@ -77,10 +76,8 @@ public Validated validate() {
7776

7877
@Override
7978
public TreeVisitor<?, ExecutionContext> getVisitor() {
80-
ChangePropertyValue changeProperties = new ChangePropertyValue(propertyKey, newValue, oldValue, regex, relaxedBinding);
81-
org.openrewrite.yaml.ChangePropertyValue changeYaml =
82-
new org.openrewrite.yaml.ChangePropertyValue(propertyKey, newValue, oldValue, regex, relaxedBinding, null);
83-
79+
Recipe changeProperties = new org.openrewrite.properties.ChangePropertyValue(propertyKey, newValue, oldValue, regex, relaxedBinding);
80+
Recipe changeYaml = new org.openrewrite.yaml.ChangePropertyValue(propertyKey, newValue, oldValue, regex, relaxedBinding, null);
8481
return new TreeVisitor<Tree, ExecutionContext>() {
8582
@Override
8683
public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.java.spring;
17+
18+
import lombok.EqualsAndHashCode;
19+
import lombok.Value;
20+
import org.jspecify.annotations.NonNull;
21+
import org.jspecify.annotations.Nullable;
22+
import org.openrewrite.*;
23+
import org.openrewrite.properties.tree.Properties;
24+
import org.openrewrite.yaml.tree.Yaml;
25+
26+
@EqualsAndHashCode(callSuper = false)
27+
@Value
28+
public class CommentOutSpringPropertyKey extends Recipe {
29+
30+
@Override
31+
public String getDisplayName() {
32+
return "Comment out Spring properties";
33+
}
34+
35+
@Override
36+
public String getDescription() {
37+
return "Add comment to specified Spring properties, and comment out the property.";
38+
}
39+
40+
@Option(displayName = "Property key",
41+
description = "The name of the property key to comment out.",
42+
example = "management.metrics.binders.files.enabled")
43+
String propertyKey;
44+
45+
@Option(displayName = "Comment",
46+
description = "Comment to replace the property key.",
47+
example = "This property is deprecated and no longer applicable starting from Spring Boot 3.0.x")
48+
String comment;
49+
50+
@Override
51+
public TreeVisitor<?, ExecutionContext> getVisitor() {
52+
String inlineComment = " # " + comment;
53+
String regex = "(?<!" + inlineComment + ")$";
54+
Recipe changeProperties = new org.openrewrite.properties.ChangePropertyValue(propertyKey, inlineComment, regex, true, null);
55+
Recipe changeYaml = new org.openrewrite.yaml.CommentOutProperty(propertyKey, comment) ;
56+
return new TreeVisitor<Tree, ExecutionContext>() {
57+
@Override
58+
public @Nullable Tree preVisit(@NonNull Tree tree, ExecutionContext ctx) {
59+
stopAfterPreVisit();
60+
if (tree instanceof Properties.File) {
61+
return changeProperties.getVisitor().visit(tree, ctx);
62+
} else if (tree instanceof Yaml.Documents) {
63+
return changeYaml.getVisitor().visit(tree, ctx);
64+
}
65+
return tree;
66+
}
67+
};
68+
}
69+
}

0 commit comments

Comments
 (0)