Skip to content
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

RewriteTest / YamlResourceLoader Enhancements #3517

Merged
merged 8 commits into from
Aug 31, 2023

Conversation

nmck257
Copy link
Collaborator

@nmck257 nmck257 commented Aug 30, 2023

What's changed?

Anything in particular you'd like reviewers to focus on?

  • In ClasspathScanningLoader, the constructor overloads were starting to get diverse in functionality, so I opted for a factory method for this new scenario. Open to changing it
  • In ClasspathScanningLoader, there's this comment, which I'm not sure is accurate today; I think the new case RecipeLifecycleTest::declarativeRecipeChainFromResourcesIncludesImperativeRecipesInDescriptors disproves it
    /**
    * This must be called _after_ scanClasses or the descriptors of declarative recipes will be missing any
    * non-declarative recipes they depend on that would be discovered by scanClasses
    */
    private void scanYaml(ClassGraph classGraph, Properties properties, Collection<? extends ResourceLoader> dependencyResourceLoaders, @Nullable ClassLoader classLoader) {
  • I considered removing the reflective attempt to instantiate the recipe and only using jackson, but that led to a regression with recipes like this, because jackson (for some reason) picked the 1-arg constructor (passing a null value) instead of the annotated zero-arg constructor (which would have set the required field by default) https://github.com/openrewrite/rewrite-migrate-java/blame/main/src/main/java/org/openrewrite/java/migrate/UseJavaUtilBase64.java

Anyone you would like to review specifically?

@sambsnyd

Have you considered any alternatives or workarounds?

  • Scanning the full runtime classpath when you're just looking for Yaml files is slow and doesn't seem beneficial
  • You can also explicitly list the yamls you care about when defining your RecipeSpec, but with recursive validation, if you're testing a recipe which chains to many recipes across many files, then that becomes painful to maintain

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've added the license header to any new files through ./gradlew licenseFormat
  • I've used the IntelliJ IDEA auto-formatter on affected files
  • I've updated the documentation (if applicable)

…recipes with zero args if basic reflection fails. And, reverted change to RecipeSpec which made it scanRuntimeClasspath unnecessarily for yaml recipes. Fixes #3414
…rewrite yamls on classpath (ignoring classes)

fixes #3096
@nmck257 nmck257 requested a review from sambsnyd August 30, 2023 14:26
@timtebeek timtebeek added the enhancement New feature or request label Aug 30, 2023
@nmck257
Copy link
Collaborator Author

nmck257 commented Aug 30, 2023

looking at the failing test, it was actually failing for the "wrong" reason before: "recipe 'org.openrewrite.text.ChangeText' does not exist."

now, it's passing, because the single toText field on ChangeText isn't actually annotated as non-nullable so validation doesn't consider it to be required.

I'm thinking we fix it by adjusting NullUtils::findNonNullFields to include fields annotated with Option and not explicitly setting required=false ? Will draft that commit now and add to the PR

edit done

@sambsnyd sambsnyd merged commit d5071a5 into main Aug 31, 2023
@sambsnyd sambsnyd deleted the feature/rewrite-test-yaml-resource-loader-enhancements branch August 31, 2023 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
3 participants