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

Remove SolrAutoConfiguration from @SpringBootApplication exclusions #577

Merged
merged 6 commits into from
Aug 15, 2024

Conversation

Laurens-W
Copy link
Contributor

What's changed?

Added recipe to specifically remove the SolrAutoConfiguration from a @SpringBootApplication exclusions element

What's your motivation?

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

Anyone you would like to review specifically?

@timtebeek

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@Laurens-W Laurens-W self-assigned this Aug 15, 2024
@timtebeek timtebeek self-requested a review August 15, 2024 14:50
@timtebeek timtebeek added enhancement New feature or request boot-3.0 labels Aug 15, 2024
@timtebeek timtebeek marked this pull request as ready for review August 15, 2024 18:10
}
maybeRemoveImport(SOLR_AUTOCONFIGURATION_FQN);

return a.withArguments(ListUtils.map(a.getArguments(), it -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Laurens-W Notice how I'm unconditionally calling ListUtils.map; that has an optimization in it to not create a new list unless changes are made to the list. That then in turn helps keep our recipe implementation clear of conditionals like the AtomicBoolean you had before, and the if/else checking of values.

if (newInitializer.isEmpty()) {
return null;
}
return maybeAutoFormat(it, as.withAssignment(array.withInitializer(newInitializer)), ctx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Laurens-W This quick method allows you to apply the detected style to a code element, such that you need not worry about carrying over a specific space here or there.


private boolean isSolrAutoConfigurationClassReference(Expression expr) {
return expr instanceof J.FieldAccess &&
TypeUtils.isAssignableTo(SOLR_AUTOCONFIGURATION_FQN, ((J.FieldAccess) expr).getTarget().getType());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Laurens-W A pattern I've seen you use a couple times now is to compare with .equals("SomeString"). Try to use TypeUtils where you can for type safe comparisons instead, as that then also handles the FQN case as seen in the added unit test.

Comment on lines +158 to +159
@Nested
class NoChange {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the number of test cases grows, I like to group them logically for the ones that ought not make any changes. That quickly shows the invariants and makes it logical what to add where.

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for implementing most of this! Please go over the changes I made and comments I've left such that the next PR will be even better. :)

@timtebeek timtebeek merged commit 11aa47d into main Aug 15, 2024
2 checks passed
@timtebeek timtebeek deleted the remove-solr-autoconfiguration branch August 15, 2024 18:20
@timtebeek
Copy link
Contributor

Also: always try to hook your new recipe into a larger upgrade where that makes sense. In this case it's a required upgrade for Spring Boot 3:
dbb3c88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
boot-3.0 enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants