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

Apply add dependency correctly, taking aggregating poms into account #4590

Merged
merged 16 commits into from
Oct 26, 2024

Conversation

Laurens-W
Copy link
Contributor

What's changed?

Introduce a mechanism to know which modules an aggregating pom applies to in order to prevent unnecessarily adding dependencies to aggregating poms

Anyone you would like to review specifically?

@timtebeek @sambsnyd

Any additional context

An aggregating pom could be a parent, when it's not there's no point in adding a dependency to it

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 Oct 18, 2024
@Laurens-W Laurens-W added the enhancement New feature or request label Oct 18, 2024
@Laurens-W
Copy link
Contributor Author

The naming between getResolutionResult().getModules() and getResolutionResult().getPom().getModules() is a bit ambiguous.
getResolutionResult().getModules() are child poms that we've determined within the project
getResolutionResult().getPom().getModules() refers to the modules element inside a pom

Not sure which one to refactor is any

@@ -115,6 +115,9 @@ public static int getModelVersion() {
@Builder.Default
List<Plugin> pluginManagement = emptyList();

@Builder.Default
List<String> modules = emptyList();
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid confusion & future changes, perhaps it helps to already adopt the Maven 4 convention of calling these subprojects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, that takes away the ambiguity!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've taken both modules and subProjects into account for the RawPom and named it subProjects anywhere beyond there

@Laurens-W
Copy link
Contributor Author

Perhaps some additions to the RawPomTest would be justified here

Comment on lines 245 to 247
if (!getResolutionResult().getPom().getSubprojects().isEmpty()
&& (getResolutionResult().getModules().isEmpty()
|| getResolutionResult().getModules().stream().map(MavenResolutionResult::getPom).map(ResolvedPom::getGav).map(ResolvedGroupArtifactVersion::getArtifactId).noneMatch(art -> getResolutionResult().getPom().getSubprojects().contains(art))
Copy link
Contributor

Choose a reason for hiding this comment

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

The bot wants you to place the && and || on the previous line, in case that wasn't clear before.

Any why the use of Streams API in one of our most used recipes? Does it help to extract the condition into a properly named method such that you can do an early return from a loop there?

@Laurens-W Laurens-W marked this pull request as ready for review October 22, 2024 10:16
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • rewrite-core/src/test/java/org/openrewrite/RecipeLifecycleTest.java
    • lines 142-142

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.

Great to see; I've reworded the conditionals to make it easier to grasp what was added and why; hope you agree! :)

@timtebeek timtebeek merged commit 8b44a1d into main Oct 26, 2024
2 checks passed
@timtebeek timtebeek deleted the add-dependency-to-parent-pom branch October 26, 2024 20:12
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
Development

Successfully merging this pull request may close these issues.

3 participants