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

Use maven-metadata-local.xml for file:// paths #4512

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

timtebeek
Copy link
Contributor

What's changed?

Use maven-metadata-local.xml when accessing file:// URIs, as documented on

What's your motivation?

Improve odds of picking up an existing local file, as opposed to downloading metadata remotely.

Anything in particular you'd like reviewers to focus on?

Presumably the local metadata might be outdated; should we guard against that somehow?

Anyone you would like to review specifically?

@DidierLoiseau

Have you considered any alternatives or workarounds?

Locally I also see maven-metadata-central.xml as well as a few other repo-ids; Should we account for those?

Any additional context

@timtebeek timtebeek added the enhancement New feature or request label Sep 21, 2024
@timtebeek timtebeek self-assigned this Sep 21, 2024

if ("file".equals(scheme)) {
// A maven repository can be expressed as a URI with a file scheme
Path path = Paths.get(URI.create(uri));
Path path = Paths.get(URI.create(baseUri + "maven-metadata-local.xml"));
Copy link
Contributor

Choose a reason for hiding this comment

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

In theory it should be maven-metadata-<repo-id>.xml, and the <localRepository>’s id is local.

I don’t know if it’s very common to have another local repository though. Maybe when people are running CI on the same server as the Maven repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes my main goal here was to have a better chance of matching an existing file, while not yet perfect. I'd say this is better than falling through to deriving that information needlessly further down.

@@ -256,23 +256,22 @@ public MavenMetadata downloadMetadata(GroupArtifactVersion gav, @Nullable Resolv
boolean cacheEmptyResult = false;
try {
String scheme = URI.create(repo.getUri()).getScheme();
String uri = repo.getUri() + (repo.getUri().endsWith("/") ? "" : "/") +
String baseUri = repo.getUri() + (repo.getUri().endsWith("/") ? "" : "/") +
requireNonNull(gav.getGroupId()).replace('.', '/') + '/' +
gav.getArtifactId() + '/' +
Copy link
Contributor

Choose a reason for hiding this comment

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

This bit is duplicated at lines 259-261 and 538-540. I wonder if the URI building logic (and possibly more) wouldn’t be better suited in the MavenRepository class itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand & appreciate the suggestion; in general we try to keep the classes under .tree. free of logic; they are intended mostly as a representation of the underlying source, with anything operating on those classes typically extracted elsewhere, like traits or in helper classes like this one. Since we only use this pattern twice (so far) I'd opt to for now keep that bit as-is. But definitely something to keep in mind if it repeats more often or elsewhere, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

I wanted to mean that it was duplicated 3 times. The third time is actually at lines 356-358.

@DidierLoiseau
Copy link
Contributor

Presumably the local metadata might be outdated; should we guard against that somehow?

I didn’t check the whole thing, but the metadata is per-repository. The local repository keeps track of some remote repository metadata which might be outdated indeed, but I think the code doesn’t use it since it always fetches the metadata from the remote repository. Since it downloads the metadata from all repositories and then merges it, I guess it’s fine? (assuming the merge is correct)

@timtebeek
Copy link
Contributor Author

Thanks for helping think through the options here! Indeed we merge the metadata as also seen on this PR

With that I think we should be safe to merge this as an improvement for a commonly expected case.

@timtebeek timtebeek merged commit 3b20292 into main Sep 23, 2024
2 checks passed
@timtebeek timtebeek deleted the metadata-local-file-path branch September 23, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants