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

Gradle bump strategy #33453

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

Conversation

ldt-fweichert
Copy link

Changes

  • added support for the bump strategy for gradle versioning using the maven style range syntax
  • added support for maven style range syntax to the gradle manager

WIP!

This pr is not yet ready to merge, it does already exists for the purpose of getting feedback and input from discussions. Reviews welcome.
Todos: (for me)

  • Sign the CLA
  • Fix last failling test
  • Do code //TODO 's
  • Get feedback on the implementation
  • Add docs

Context

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@ldt-fweichert ldt-fweichert changed the title Gradle version ranges Gradle bump strategy Jan 7, 2025
@rarkins rarkins requested a review from Churro January 8, 2025 09:19
Copy link
Collaborator

@Churro Churro left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. Looks promising but can benefit from some refinement:

  • Please add a reproduction repo so that your changes can be tested against, incl a dep with regular maven based range and one with a range + strict version enforcement.
  • Run prettier and undo changes unrelated to the bump strategy.
  • Keep dep extraction to the minimum, it's not the place to decide what part to bump

Most importantly: To reduce the complexity of your changes, it would be great if you could limit this PR to the already supported Maven range syntax, for now ignoring gradle's strict version notation. This should allow you to reuse the existing maven range parsing, it should work without changes to the parser and, unless I missed something, only require a few adaptations in the gradle versioning

const updatablePart = mavenStyleRange.upperBound ?? mavenStyleRange.lowerBound;
return {
depName: `${groupId}:${artifactId}`,
currentValue: updatablePart,
Copy link
Collaborator

Choose a reason for hiding this comment

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

currentValue is supposed to include the version value found for the dependency that is extracted. It's not the right place to decide whether to update the lower or upper bound. I think updating the lower bound is a bit pointless overall. Such a check can be done later while comparing update candidates with the full range (and the comparison logic in the versioning).

The only thing that may need adaptation here is the addition of ! and a space to the version regex.

for (const line of input.split(newlineRegex)) {
const lineMatch = propRegex.exec(line);
if (lineMatch?.groups) {
const { key, value, leftPart } = lineMatch.groups;
// TODO: we dont need to check isDependency, the parseDependency does this by itself
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's correct but please keep your changes strictly limited to what's relevant for the functionality you'd like to add. Refactoring can be done separately.

@@ -44,6 +53,11 @@ export function isDependencyString(input: string): boolean {
return false;
}

const mavenStyleRange = parseMavenStyleRange(tempVersionPart);
if (mavenStyleRange) {
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is wrong as it bypasses all subsequent checks

@@ -44,6 +53,11 @@ export function isDependencyString(input: string): boolean {
return false;
}

const mavenStyleRange = parseMavenStyleRange(tempVersionPart);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see no need for this here. Should be enough to have versionLikeSubstring match ranges, which it already can except for those containing ! and spaces.

);

const versionLikeRegex = regEx('^(?<version>[-_.\\[\\](),a-zA-Z0-9+]+)');
const versionLikeRegex = regEx('^(?<version>[-_.\\[\\](),a-zA-Z0-9+! ]*[-_.\\[\\](),a-zA-Z0-9+])');
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the intention here? Is it an attempt to add ! and a space to the list of allowed characters? If yes, this can be done simpler


const mavenStyleRangeRegex = regEx(/^(?<openingBracket>[[\](])(?<lowerBound>[-._+a-zA-Z0-9]+)?(?<seperator>\s*,\s*)(?<upperBound>[-._+a-zA-Z0-9]+)?(?<closingBracket>[[\])])(?:!!(?<preferredVersion>[-._+a-zA-Z0-9]+))?$/)

export function parseMavenStyleRange(input: string): MavenStyleRange | null {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There already is mavenBasedRangeRegex and parseMavenBasedRange, which does quite the same, except that it lacks support for preferred versions. What speaks against extending the existing implementation instead of reinventing maven style range parsing as a whole?

@@ -128,30 +131,31 @@ const matches = (a: string, b: string): boolean => {
return equals(x, y);
}

const mavenBasedRange = parseMavenBasedRange(b);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks wrong to me. It seems you're trying to replace parseMavenBasedRange() with your implementation, while it's still used e.g. in isValid().

const mavenBasedRange = parseMavenBasedRange(b);
if (!mavenBasedRange) {
const mavenStyleRange = parseMavenStyleRange(b);
// we can not update an exclusive lower bound as we don't know
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you mean (1.0,) for example? If so, this should be reflected in a test too


const mavenStyleRange = parseMavenStyleRange(fullValue);
if (mavenStyleRange) {
const updatablePart = mavenStyleRange.upperBound ?? mavenStyleRange.lowerBound;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess ?? mavenStyleRange.lowerBound can never hapepns since parseMavenStyleRange returns null if not both lower and upper are provided?!

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

Successfully merging this pull request may close these issues.

3 participants