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

feat(maven): lookup parent homepage/scm information from pom #9722

Merged
merged 22 commits into from Jun 25, 2021

Conversation

twendelmuth
Copy link
Contributor

@twendelmuth twendelmuth commented Apr 25, 2021

Changes:

Changed the way maven is looking up sourceUrl & homepage. It will now also traverse up to the parents to look for this information if not given in the original dependency.
Also updated sbt to make use of the maven dependency lookup instead of trying it's own implementation.
This also led to me taking over the sbt parts of sourceUrl escaping for the maven implementation:

        const sourceUrl = pomXml.valueWithPath('scm.url');
        if (sourceUrl) {
          result.sourceUrl = sourceUrl
            .replace(/^scm:/, '')
            .replace(/^git:/, '')
            .replace(/^git@github.com:/, 'https://github.com/')
            .replace(/\.git$/, '');
        }

This has been extended to also support <url>git://github.com/child-scm/child</url> vs previously only supported <url>git://github.com:child-scm/child</url>. I had seen this in some poms and thought it makes sense to include this (reference poms are commented in the test poms)

Context:

In the java world parent dependency declarations are quiet common. A maven pom.xml will always inherit it's parents properties if they're not overridden in the original pom.xml. Since this is the case we're losing information by not parsing this information from the given parents.
The downside I see for this is, that we could end up with sourceUrl/homepage of an external framework if that's used as parent and no own scm-url/url information was provided in the pom.xml - spring-boot-starter-parent comes to mind here. I'd however assume that this is mainly an issue that internal libaries might be facing and can easily be mitigated by declaring correct properties for scm-url/url.

I wasn't able to test how the gradle implementation handles this since I didn't manage to get this running locally :-/

Closes #6742

PR comparisons

dependency: current code pr -> new code pr (potential comment)

Simple build tool
scala: twendelmuth/twendelmuth-testing-sbt-vanilla#6 -> twendelmuth/twendelmuth-testing-sbt#4 (nothing should have changed here)
ro.nextreports: twendelmuth/twendelmuth-testing-sbt-vanilla#5 -> twendelmuth/twendelmuth-testing-sbt#6 (finds correct source url)
xhtmlrenderer: twendelmuth/twendelmuth-testing-sbt-vanilla#3 -> twendelmuth/twendelmuth-testing-sbt#2 (finds correct source url, can parse github release notes)

maven
maven-compiler: twendelmuth/twendelmuth-testing-mvn-vanilla#4 -> twendelmuth/twendelmuth-testing-mvn#3 (nothing has changed here)
ro.nextreports: twendelmuth/twendelmuth-testing-mvn-vanilla#5 -> twendelmuth/twendelmuth-testing-mvn#5 (finds correct source url)
xhtmlrenderer: twendelmuth/twendelmuth-testing-mvn-vanilla#3 -> twendelmuth/twendelmuth-testing-mvn#2 (finds correct source url, can parse github release notes)

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 tick one)

I have verified these changes via:

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

…ation from poms, made sbt use this implementation
@twendelmuth twendelmuth changed the title (#6742) added support to lookup parent homepage/scm information from pom, made sbt use this implementation feat: (#6742) added support to lookup parent homepage/scm information from pom, made sbt use this implementation Apr 25, 2021
@twendelmuth twendelmuth changed the title feat: (#6742) added support to lookup parent homepage/scm information from pom, made sbt use this implementation feat: #6742 added support to lookup parent homepage/scm information from pom, made sbt use this implementation Apr 25, 2021
@twendelmuth twendelmuth changed the title feat: #6742 added support to lookup parent homepage/scm information from pom, made sbt use this implementation feat(maven,sbt): #6742 added support to lookup parent homepage/scm information from pom, made sbt use this implementation Apr 25, 2021
@rarkins rarkins requested a review from zharinov April 26, 2021 05:22
@zharinov
Copy link
Collaborator

How I see the roadmap for this PR:

  • I refactor Maven datasource tests to be more clear and use HTTP mocks instead of file protocol
  • Resolve conflicts and merge Maven-related part
  • Merge SBT-related changes in the separate PR

@twendelmuth What do you think?

@twendelmuth
Copy link
Contributor Author

How I see the roadmap for this PR:

  • I refactor Maven datasource tests to be more clear and use HTTP mocks instead of file protocol
  • Resolve conflicts and merge Maven-related part
  • Merge SBT-related changes in the separate PR

@twendelmuth What do you think?

Works for me.
I used the file protocol base mainly as convience because I'm still struggling to work productively in the IDE I'm using for typescript 👼 I guess it would make sense to introduce to rework that setup a bit to make it easier to add new dependencies (like nocking head & get, maven-metadata.xml and the directory setup).

I tried to touch the SBT related changes as little as possible - so that they also gain the same approach without potentially breaking their functionality. In general I think at least parts of the logic could also make sense in the maven-utils part - however that would have made my changeset even bigger and less readable. The main goal was to be able to pass the repoRoot to the maven-utils function and actually using this (so we don't deviate in handling of maven.poms like we do today).
I could have done this also purely in the maven-util part by starting to split off things of the repoUrl if applicable but that felt more hackish.
(The issue is that SBT would pass https://repo.maven.apache.org/maven2/org/elasticsearch/ as it's root and I'm potentially needing to looku org/elasticsearch/parent and therefore needing to get rid of org/elasticsearch from the root).

The whole logic of trying different directory structures seem to be a fallback to deal with mistakes that have been made in uploading the maven artifacts. In the public repos usually you'd find a "normal" version anyway though but obviously I cannot speak for internally hosted maven repositories.

Examples of this:
https://repo.maven.apache.org/maven2/org/elasticsearch/client/rest/5.0.0-beta1/
https://repo.maven.apache.org/maven2/org.elasticsearch.client/rest/5.0.0-beta1/

Anyway. I'd for now split off the commits for sbt and put them in a different branch (if you haven't done that already 😄)

@zharinov
Copy link
Collaborator

Okay, just don't spend too much effort on tests for now :)

@twendelmuth
Copy link
Contributor Author

So I've split the things off:
https://github.com/twendelmuth/renovate/tree/feat/feature_6742_mvn_lookup_parents
https://github.com/twendelmuth/renovate/tree/feat/sbt_lookup_parents

With the sbt one based on the mvn lookup things. How do you want me to proceed?
I explicitly didn't want to push to the branch with the PR already open - but could do so 😄

@zharinov
Copy link
Collaborator

Thanks, okay let's wait until my refactoring is in main branch, then let's see what's next.

@HonkingGoose HonkingGoose added the status:blocked Issue is blocked by another issue or external requirement label Apr 28, 2021
@HonkingGoose

This comment has been minimized.

@twendelmuth
Copy link
Contributor Author

twendelmuth commented Apr 28, 2021

@HonkingGoose the refactorings are in. I now need to adapt the tests to run with the new setup, blocking is okay I guess. I could also revert to a draft PR 👼

(#9745)

@HonkingGoose HonkingGoose removed the status:blocked Issue is blocked by another issue or external requirement label Apr 28, 2021
@HonkingGoose
Copy link
Collaborator

@HonkingGoose the refactorings are in. I now need to adapt the tests to run with the new setup, blocking is okay I guess. I could also revert to a draft PR 👼

I've removed the "blocked" label.

I think it's a good idea to mark this PR as a draft again, that way it's clear that more work is still needed before it's in a ready-to-merge state again.

@twendelmuth twendelmuth marked this pull request as draft April 28, 2021 12:46
@zharinov
Copy link
Collaborator

Hi @twendelmuth, I'm about to adapt your tests for recent test refactoring right now. Once done, we only need to split Maven/Sbt parts

@twendelmuth twendelmuth changed the title feat(maven,sbt): #6742 added support to lookup parent homepage/scm information from pom, made sbt use this implementation feat(maven): #6742 added support to lookup parent homepage/scm information from pom, made sbt use this implementation May 3, 2021
@twendelmuth
Copy link
Contributor Author

@zharinov I've removed the sbt parts - we can add them in a different PR imo.

@twendelmuth twendelmuth marked this pull request as ready for review May 5, 2021 08:06
@twendelmuth
Copy link
Contributor Author

Anything that is missing here?
Anyway I can help to bring this live? :-)

@zharinov
Copy link
Collaborator

Hi @twendelmuth, sorry for the long delay. Let's do this!
Please, merge my PR with null guards before recursion: twendelmuth#4

lib/datasource/maven/index.spec.ts Show resolved Hide resolved
const parentDisplayId = `${parentGroupId}:${parentArtifactId}`;
const parentDependency = getDependencyParts(parentDisplayId);

const parentInformation = await getDependencyInfo(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @twendelmuth, thanks for merging my changes. Finally, we need to limit the recursion depth and test it on self-referencing pomfile. I would limit to 5, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

5 sounds reasonable - I could see certain projects might go a bit deeper than that but it's a good starting point imo.

Regarding the self-reference:
I guess you're referring to circular dependencies like POM1 -> POM2 -> POM1? A POM is not allowed to be it's own parent.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I was a bit lazy for creating circle with 2 participants 🙃

@rarkins rarkins changed the title feat(maven): #6742 added support to lookup parent homepage/scm information from pom, made sbt use this implementation feat(maven): lookup parent homepage/scm information from pom Jun 1, 2021
@rarkins rarkins marked this pull request as draft June 1, 2021 18:51
zharinov
zharinov previously approved these changes Jun 8, 2021
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

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

needs deconflicting

@zharinov zharinov self-requested a review June 23, 2021 05:10
@rarkins rarkins marked this pull request as ready for review June 23, 2021 09:32
@rarkins rarkins requested a review from viceice June 25, 2021 11:38
@rarkins rarkins enabled auto-merge (squash) June 25, 2021 12:30
@rarkins rarkins merged commit 7fd1e2f into renovatebot:main Jun 25, 2021
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 25.51.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@twendelmuth twendelmuth deleted the feature_6742_mvn_lookup_parents branch June 25, 2021 14:49
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Renovate doesn't look up parent pom for scm links.
6 participants