gnodet commented on code in PR #13159:
URL: https://github.com/apache/maven/pull/13159#discussion_r4036612526
##########
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultNode.java:
##########
@@ -72,8 +74,15 @@ 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 de30160241: changed to `Optional.ofNullable(result).map(...)` chain
so a null `find()` result is handled gracefully. Added a dedicated test
`testGetRepositoryReturnsEmptyWhenLrmReturnsNull` to cover this path.
##########
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultNodeTest.java:
##########
@@ -66,4 +80,91 @@ void testAsString() {
defaultNode = new DefaultNode(session, node, true);
assertEquals("(org.example:myapp:jar:1.0:compile - omitted for
conflict with 2.0)", defaultNode.asString());
}
+
+ @Test
+ void testGetRepositoryReturnsPresentWhenFoundInLocalRepo() {
+ // Set up a dependency node with an artifact and one candidate remote
repository
+ org.eclipse.aether.repository.RemoteRepository aetherRepo =
+ new org.eclipse.aether.repository.RemoteRepository.Builder(
+ "central", "default",
"https://repo1.maven.org/maven2")
+ .build();
+ DefaultArtifact artifact = new
DefaultArtifact("org.example:myapp:1.0");
+ DefaultDependencyNode node = new DefaultDependencyNode(artifact);
+ node.setRepositories(Collections.singletonList(aetherRepo));
+
+ // LocalArtifactResult reports the artifact was fetched from aetherRepo
+ LocalArtifactResult localResult = mock(LocalArtifactResult.class);
+ when(localResult.getRepository()).thenReturn(aetherRepo);
+
+ LocalRepositoryManager lrm = mock(LocalRepositoryManager.class);
+ when(lrm.find(any(RepositorySystemSession.class),
any(LocalArtifactRequest.class)))
+ .thenReturn(localResult);
Review Comment:
Fixed in de30160241: both tests now use
`ArgumentCaptor<LocalArtifactRequest>` and assert that the captured request
carries the correct artifact and repositories list.
--
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]