Skip to content

Maven: implement parent snapshot lookup#5924

Merged
jakecoffman merged 6 commits intomainfrom
jakecoffman/maven-parent-snapshots
Oct 19, 2022
Merged

Maven: implement parent snapshot lookup#5924
jakecoffman merged 6 commits intomainfrom
jakecoffman/maven-parent-snapshots

Conversation

@jakecoffman
Copy link
Copy Markdown
Member

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.

@jakecoffman jakecoffman requested a review from a team as a code owner October 18, 2022 20:33
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
Copy link
Copy Markdown
Member Author

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.

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
Copy link
Copy Markdown
Member Author

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.

@jakecoffman jakecoffman force-pushed the jakecoffman/maven-parent-snapshots branch from d67958a to ba56381 Compare October 18, 2022 21:01
@jakecoffman
Copy link
Copy Markdown
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.

Copy link
Copy Markdown
Contributor

@brrygrdn brrygrdn left a 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),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💯

jakecoffman and others added 2 commits October 19, 2022 10:16
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.

4 participants