gnodet commented on code in PR #13159:
URL: https://github.com/apache/maven/pull/13159#discussion_r4036798889
##########
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultNode.java:
##########
@@ -72,8 +74,17 @@ public List<RemoteRepository> getRemoteRepositories() {
@Override
public Optional<RemoteRepository> getRepository() {
- // TODO: v4: implement
- throw new UnsupportedOperationException("Not implemented yet");
+ org.eclipse.aether.artifact.Artifact artifact = node.getArtifact();
+ List<org.eclipse.aether.repository.RemoteRepository> repos =
node.getRepositories();
+ if (artifact == null || repos.isEmpty()) {
+ return Optional.empty();
+ }
+ LocalArtifactRequest request = new LocalArtifactRequest(artifact,
repos, node.getRequestContext());
+ LocalArtifactResult result =
+
session.getSession().getLocalRepositoryManager().find(session.getSession(),
request);
Review Comment:
Fixed in b196590ea6: extended the `@return` Javadoc in `Node.java` to
mention that LRMs which do not track artifact origins (e.g.
`SimpleLocalRepositoryManager`) always return empty.
##########
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultNode.java:
##########
@@ -72,8 +74,17 @@ public List<RemoteRepository> getRemoteRepositories() {
@Override
public Optional<RemoteRepository> getRepository() {
- // TODO: v4: implement
- throw new UnsupportedOperationException("Not implemented yet");
+ org.eclipse.aether.artifact.Artifact artifact = node.getArtifact();
+ List<org.eclipse.aether.repository.RemoteRepository> repos =
node.getRepositories();
+ if (artifact == null || repos.isEmpty()) {
+ return Optional.empty();
+ }
+ LocalArtifactRequest request = new LocalArtifactRequest(artifact,
repos, node.getRequestContext());
+ LocalArtifactResult result =
+
session.getSession().getLocalRepositoryManager().find(session.getSession(),
request);
Review Comment:
Fixed in b196590ea6: added a `cachedRepository` field to `DefaultNode` — the
first call populates it via `Optional.ofNullable(result).map(...)` and
subsequent calls return the cached value without touching disk. Also added
`testGetRepositoryIsCached` to verify LRM is invoked exactly once across
multiple calls.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]