Maven: implement parent snapshot lookup#5924
Merged
jakecoffman merged 6 commits intomainfrom Oct 19, 2022
Merged
Conversation
jakecoffman
commented
Oct 18, 2022
Comment on lines
+82
to
+105
| def remote_pom_snapshot_url(group_id, artifact_id, version, snapshot_version, base_repo_url) | ||
| "#{base_repo_url}/" \ | ||
| "#{group_id.tr('.', '/')}/#{artifact_id}/#{version}/" \ | ||
| "#{artifact_id}-#{snapshot_version}.pom" | ||
| end | ||
|
|
||
| def remote_pom_snapshot_metadata_url(group_id, artifact_id, version, base_repo_url) | ||
| "#{base_repo_url}/" \ | ||
| "#{group_id.tr('.', '/')}/#{artifact_id}/#{version}/" \ | ||
| "maven-metadata.xml" | ||
| end | ||
|
|
||
| def fetch_snapshot_pom_url(group_id, artifact_id, version, base_url) | ||
| url = remote_pom_snapshot_metadata_url(group_id, artifact_id, version, base_url) | ||
| response = fetch(url) | ||
| return nil unless response.status == 200 | ||
|
|
||
| snapshot = Nokogiri::XML(response.body). | ||
| css("snapshotVersion"). | ||
| find { |node| node.at_css("extension").content == "pom" }. | ||
| at_css("value").content | ||
|
|
||
| remote_pom_snapshot_url(group_id, artifact_id, version, snapshot, base_url) | ||
| end |
Member
Author
There was a problem hiding this comment.
This is the new snapshot fetching logic.
jakecoffman
commented
Oct 18, 2022
Comment on lines
+47
to
+51
| if version.include?("SNAPSHOT") | ||
| fetch_snapshot_pom_url(group_id, artifact_id, version, base_url) | ||
| else | ||
| remote_pom_url(group_id, artifact_id, version, base_url) | ||
| end |
Member
Author
There was a problem hiding this comment.
This is the new detection of snapshots.
d67958a to
ba56381
Compare
Member
Author
|
In ba56381 I found a few places where credentials were not being passed in, so this mitigates the issue I was seeing that I mentioned above. If the repositories are specified in dependabot.yml things should now work. |
brrygrdn
reviewed
Oct 19, 2022
Contributor
brrygrdn
left a comment
There was a problem hiding this comment.
I just have one thing I wasn't sure about, otherwise this change makes sense to me, thanks for fixing this!
| def repository_finder | ||
| @repository_finder ||= | ||
| Maven::FileParser::RepositoriesFinder.new( | ||
| pom_fetcher: Maven::FileParser::PomFetcher.new(dependency_files: dependency_files), |
mattt
reviewed
Oct 19, 2022
Co-authored-by: Mattt <mattt@github.com>
pavera
approved these changes
Oct 19, 2022
This was referenced Oct 19, 2022
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
In Maven, a snapshot is a prerelease version. So 1.0-SNAPSHOT is like 1.0-alpha, for example, but there can be many of these produced and usually they have timestamps as filenames.
Since there are multiple snapshots, Maven maintains a maven-metadata.xml file that points to the current version of several files including the POM.
Solution
In this PR I've implemented detection of a snapshot version by checking to see if "SNAPSHOT" is present, and if so try to get the metadata file to find the current snapshot pom file.
There was also a lot of duplication between PropertyValueFinder and RepositoriesFinder, and I was adding more to it. So I split out a new class which encapsulates the fetching of the POM files. This has the added benefit of now those two classes share the same POM cache, before they did not.
Ongoing
I'm still hunting down one issue where when using a private registry, when a parent pom has a parent itself, Dependabot stops using the private registry and tries to use central.