-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Maven: implement parent snapshot lookup #5924
Conversation
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new snapshot fetching logic.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new detection of snapshots.
d67958a
to
ba56381
Compare
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
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.