Skip to content

Commit

Permalink
Add an PathType.UNRESOLVED value for allowing plugins to log warnin…
Browse files Browse the repository at this point in the history
…g to users when a dependency cannot be placed on any path.
  • Loading branch information
desruisseaux committed Mar 1, 2024
1 parent 22f8366 commit 75d8e88
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> option() {
return Optional.empty();
}

@Override
public String option(Iterable<? extends Path> 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"}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void addDependency(Node node, Dependency dep, Predicate<PathType> 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,12 @@ void testResolveArtifactCoordinateDependencies() {
coord, PathScope.TEST_COMPILE, Arrays.asList(JavaPathType.CLASSES, JavaPathType.MODULES));
List<Path> classes = dispatched.get(JavaPathType.CLASSES);
List<Path> modules = dispatched.get(JavaPathType.MODULES);
assertEquals(2, dispatched.size());
assertEquals(8, classes.size()); // "pluxus.pom" and "junit.jar" are excluded.
List<Path> 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));
Expand All @@ -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
Expand Down

0 comments on commit 75d8e88

Please sign in to comment.