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

Adding latest and release fields to MavenMetadata, using them in AddDependency #5082

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

greg-at-moderne
Copy link
Contributor

@greg-at-moderne greg-at-moderne commented Feb 21, 2025

What's changed?

Two things:

  1. Adding new fields to MavenMetadata "record" - latest and release
<metadata modelVersion="1.1.0">
  <groupId>commons-io</groupId>
  <artifactId>commons-io</artifactId>
  <versioning>
    <latest>2.18.0</latest>   <---------------
    <release>2.18.0</release> <---------------
    <versions>
      <version>2.17.0</version>
      <version>2.18.0</version>
    </versions>
    <lastUpdated>20241119205217</lastUpdated>
  </versioning>
</metadata>
  1. Using them in AddDependency recipe, so that it honors input set to latest.release as taking the value from the top-level release field.

What's your motivation?

Address feedback from one of the OpenRewrite users.

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

Yes!

  1. Does the way MavenMetadata changes are handled provide compatibility?
  2. The change in the version resolution logic is local to this single recipe (AddDependency) as I read this is the intent in the project. All recipes seem to have their own version matching logic.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@greg-at-moderne greg-at-moderne self-assigned this Feb 21, 2025
@greg-at-moderne greg-at-moderne marked this pull request as ready for review February 21, 2025 15:11
Comment on lines +78 to +79
@Nullable String latest,
@Nullable String release,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it not make more sense to add these at the end of the argument list, such that we can switch back to (implied) AllArgsConstructor later?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this test class at all? Seems to be covered by MavenMetadataTest already, and then I'd rather not maintain the constructor call here if we can avoid it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tend to agree, (small) integration tests over unit tests (unless the unit has very nasty code you really need to test to be sure it works correctly).

@Nullable
String latest;

public Versioning(
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps good to already deprecate this one, to nudge folks to move over.

Suggested change
public Versioning(
@Deprecated
public Versioning(

@jevanlingen jevanlingen changed the title Adding latest and release fields to MavenMetadata, using them in AddD… Adding latest and release fields to MavenMetadata, using them in AddDependency Feb 24, 2025
Co-authored-by: Tim te Beek <tim@moderne.io>
}

// VisibleForTesting
static String findVersionToUse(@Nullable VersionComparator versionComparator, String defaultVersion, MavenMetadataSupplier mavenMetadataSupplier,
Copy link
Contributor

Choose a reason for hiding this comment

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

To be honest, I don't like this architectural change (I also discussed this with @Laurens-W). I think it is better for both component isolation and your mental model to keep helper methods in its own class. So in this case the findVersionToUse should stay in the InsertDependencyInOrder visitor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants