diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/PathType.java b/api/maven-api-core/src/main/java/org/apache/maven/api/PathType.java index 7a558081af1d..e7f80cf4a97e 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/PathType.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/PathType.java @@ -37,6 +37,35 @@ */ @Experimental public interface PathType { + /** + * The type for all paths that could not be placed in any of the types requested by a caller. + * This type can appear in the return value of a call to + * {@link Session#resolveDependencies resolveDependencies(...)} when at least one dependency + * cannot be associated to any type specified in the {@code desiredTypes} argument. + * Plugins can choose to report a warning to users when unresolved paths exist. + */ + PathType UNRESOLVED = new PathType() { + @Override + public String name() { + return "UNRESOLVED"; + } + + @Override + public String id() { + return "UNRESOLVED"; + } + + @Override + public Optional option() { + return Optional.empty(); + } + + @Override + public String option(Iterable paths) { + return ""; + } + }; + /** * Returns the unique name of this path type, including the module to patch if any. * For example, if this type is {@link JavaPathType#MODULES}, then this method returns {@code "MODULES"}. diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultDependencyResolverResult.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultDependencyResolverResult.java index 6ba6cf96b5f0..0214ae4c69dc 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultDependencyResolverResult.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultDependencyResolverResult.java @@ -266,7 +266,7 @@ void addDependency(Node node, Dependency dep, Predicate filter, Path p return; // Dependency added, we are done. } } - cache.selectPathType(pathTypes, filter, path).ifPresent((type) -> addPathElement(type, path)); + addPathElement(cache.selectPathType(pathTypes, filter, path).orElse(PathType.UNRESOLVED), path); } /** diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/PathModularizationCache.java b/maven-core/src/main/java/org/apache/maven/internal/impl/PathModularizationCache.java index 215c2172bafa..e542fed68e0a 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/PathModularizationCache.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/PathModularizationCache.java @@ -90,7 +90,7 @@ private PathType getPathType(Path path) throws IOException { /** * Selects the type of path where to place the given dependency. - * This method returns one of the values specified in the given array. + * This method returns one of the values specified in the given collection. * This method does not handle the patch-module paths, because the patches * depend on which modules have been previously added on the module-paths. * diff --git a/maven-core/src/test/java/org/apache/maven/internal/impl/TestApi.java b/maven-core/src/test/java/org/apache/maven/internal/impl/TestApi.java index ef654feca23b..7e69ecd5dac7 100644 --- a/maven-core/src/test/java/org/apache/maven/internal/impl/TestApi.java +++ b/maven-core/src/test/java/org/apache/maven/internal/impl/TestApi.java @@ -185,9 +185,12 @@ void testResolveArtifactCoordinateDependencies() { coord, PathScope.TEST_COMPILE, Arrays.asList(JavaPathType.CLASSES, JavaPathType.MODULES)); List classes = dispatched.get(JavaPathType.CLASSES); List modules = dispatched.get(JavaPathType.MODULES); - assertEquals(2, dispatched.size()); - assertEquals(8, classes.size()); // "pluxus.pom" and "junit.jar" are excluded. + List unresolved = dispatched.get(PathType.UNRESOLVED); + assertEquals(3, dispatched.size()); + assertEquals(1, unresolved.size()); + assertEquals(8, classes.size()); // "plexus.pom" and "junit.jar" are excluded. assertEquals(1, modules.size()); + assertEquals("plexus-1.0.11.pom", unresolved.get(0).getFileName().toString()); assertEquals("test-extension-1.jar", classes.get(0).getFileName().toString()); assertEquals("junit-4.13.1.jar", modules.get(0).getFileName().toString()); assertTrue(paths.containsAll(classes)); @@ -197,10 +200,13 @@ void testResolveArtifactCoordinateDependencies() { dispatched = session.resolveDependencies(coord, PathScope.TEST_COMPILE, Arrays.asList(JavaPathType.CLASSES)); classes = dispatched.get(JavaPathType.CLASSES); modules = dispatched.get(JavaPathType.MODULES); - assertEquals(1, dispatched.size()); + unresolved = dispatched.get(PathType.UNRESOLVED); + assertEquals(2, dispatched.size()); + assertEquals(1, unresolved.size()); assertEquals(9, classes.size()); assertNull(modules); assertTrue(paths.containsAll(classes)); + assertEquals("plexus-1.0.11.pom", unresolved.get(0).getFileName().toString()); } @Test