-
Notifications
You must be signed in to change notification settings - Fork 106
Add ScanningRecipe for migrate Hooks.enableAutomaticContextPropagation()
to Spring property
#772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
78803d0
8837cb8
7a1df6b
2d02f11
def6acb
c85c43d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,123 @@ | ||||||||||||||
/* | ||||||||||||||
* Copyright 2024 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.spring.boot3; | ||||||||||||||
|
||||||||||||||
import org.jspecify.annotations.Nullable; | ||||||||||||||
import org.openrewrite.*; | ||||||||||||||
import org.openrewrite.java.JavaIsoVisitor; | ||||||||||||||
import org.openrewrite.java.MethodMatcher; | ||||||||||||||
import org.openrewrite.java.search.UsesType; | ||||||||||||||
import org.openrewrite.java.spring.AddSpringProperty; | ||||||||||||||
import org.openrewrite.java.tree.J; | ||||||||||||||
import org.openrewrite.properties.tree.Properties; | ||||||||||||||
import org.openrewrite.yaml.tree.Yaml; | ||||||||||||||
|
||||||||||||||
import java.util.concurrent.atomic.AtomicBoolean; | ||||||||||||||
|
||||||||||||||
import static org.openrewrite.Preconditions.and; | ||||||||||||||
timtebeek marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
|
||||||||||||||
public class MigrateHooksToReactorContextProperty extends ScanningRecipe<AtomicBoolean> { | ||||||||||||||
|
||||||||||||||
@Override | ||||||||||||||
public String getDisplayName() { | ||||||||||||||
return "Use `spring.reactor.context-propagation` property"; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
@Override | ||||||||||||||
public String getDescription() { | ||||||||||||||
return "Replace `Hooks.enableAutomaticContextPropagation()` with `spring.reactor.context-propagation=true`."; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
@Override | ||||||||||||||
public AtomicBoolean getInitialValue(ExecutionContext ctx) { | ||||||||||||||
return new AtomicBoolean(false); | ||||||||||||||
|
@Data | |
static class JavaProjects { | |
Set<JavaProject> applicableProjects = new HashSet<>(); | |
Set<JavaProject> processedProjects = new HashSet<>(); | |
Map<JavaProject, Path> sourceToCommentByProject = new HashMap<>(); | |
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2024 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.spring.boot3; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.DocumentExample; | ||
import org.openrewrite.test.RecipeSpec; | ||
import org.openrewrite.test.RewriteTest; | ||
|
||
import static org.openrewrite.java.Assertions.java; | ||
import static org.openrewrite.properties.Assertions.properties; | ||
|
||
class MigrateHooksToReactorContextPropertyTest implements RewriteTest { | ||
|
||
@Override | ||
public void defaults(RecipeSpec spec) { | ||
spec.recipe(new MigrateHooksToReactorContextProperty()); | ||
} | ||
|
||
@DocumentExample | ||
@Test | ||
void replaceMethodCallWithProperty() { | ||
rewriteRun( | ||
spec -> spec.recipe(new MigrateHooksToReactorContextProperty()), | ||
java( | ||
""" | ||
package org.springframework.boot.autoconfigure; | ||
public @interface SpringBootApplication {} | ||
""" | ||
), | ||
java( | ||
""" | ||
package org.springframework.boot; | ||
public class SpringApplication { | ||
public static void run(Class<?> cls, String[] args) {} | ||
} | ||
""" | ||
), | ||
java( | ||
""" | ||
package reactor.core.publisher; | ||
public class Hooks { | ||
public static void enableAutomaticContextPropagation() {} | ||
} | ||
""" | ||
), | ||
java( | ||
""" | ||
import reactor.core.publisher.Hooks; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class MyApplication { | ||
public static void main(String[] args) { | ||
Hooks.enableAutomaticContextPropagation(); | ||
SpringApplication.run(MyApplication.class, args); | ||
} | ||
} | ||
""", | ||
""" | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class MyApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(MyApplication.class, args); | ||
} | ||
} | ||
""" | ||
), | ||
properties( | ||
"", | ||
"spring.reactor.context-propagation=true", | ||
spec -> spec.path("application.properties") | ||
) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.