diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java index 515f4903b..4ec9181be 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -2962,8 +2962,9 @@ private String getTagletPath() throws MavenReportException { && (StringUtils.isNotEmpty(taglet.getTagletArtifact().getVersion()))) { pathParts.addAll(JavadocUtil.pruneFiles(getArtifactsAbsolutePath(taglet.getTagletArtifact()))); } else if (StringUtils.isNotEmpty(taglet.getTagletpath())) { - for (Path dir : JavadocUtil.pruneDirs(project, Collections.singletonList(taglet.getTagletpath()))) { - pathParts.add(dir.toString()); + for (Path path : + JavadocUtil.prunePaths(project, Collections.singletonList(taglet.getTagletpath()), true)) { + pathParts.add(path.toString()); } } } diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java index 11d795b13..5bd3fb7a3 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java @@ -118,32 +118,47 @@ public class JavadocUtil { + "environment variable using -Xms: and -Xmx:."; /** - * Method that removes the invalid directories in the specified directories. Note: All elements in - * dirs could be an absolute or relative against the project's base directory String path. + * Method that removes invalid classpath elements in the specified paths. + * Note: All elements in {@code paths} could be absolute or relative against the project's base directory. + * When pruning classpath elements, you can optionally include files in the result, otherwise only directories are + * permitted. * * @param project the current Maven project not null - * @param dirs the collection of String directories path that will be validated. - * @return a List of valid String directories absolute paths. + * @param paths the collection of paths that will be validated + * @param includeFiles whether to include files in the result as well + * @return a list of valid classpath elements as absolute paths */ - public static Collection pruneDirs(MavenProject project, Collection dirs) { + public static Collection prunePaths(MavenProject project, Collection paths, boolean includeFiles) { final Path projectBasedir = project.getBasedir().toPath(); - Set pruned = new LinkedHashSet<>(dirs.size()); - for (String dir : dirs) { - if (dir == null) { + Set pruned = new LinkedHashSet<>(paths.size()); + for (String path : paths) { + if (path == null) { continue; } - Path directory = projectBasedir.resolve(dir); + Path resolvedPath = projectBasedir.resolve(path); - if (Files.isDirectory(directory)) { - pruned.add(directory.toAbsolutePath()); + if (Files.isDirectory(resolvedPath) || includeFiles && Files.isRegularFile(resolvedPath)) { + pruned.add(resolvedPath.toAbsolutePath()); } } return pruned; } + /** + * Method that removes the invalid classpath directories in the specified directories. + * Note: All elements in {@code dirs} could be absolute or relative against the project's base directory. + * + * @param project the current Maven project not null + * @param dirs the collection of directories that will be validated + * @return a list of valid claspath elements as absolute paths + */ + public static Collection pruneDirs(MavenProject project, Collection dirs) { + return prunePaths(project, dirs, false); + } + /** * Method that removes the invalid files in the specified files. Note: All elements in files * should be an absolute String path. diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java index bf2932226..a421706ff 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java @@ -32,9 +32,11 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -582,11 +584,12 @@ public void testCopyJavadocResources() throws Exception { */ public void testPruneDirs() { List list = new ArrayList<>(); - list.add(getBasedir() + "/target/classes"); - list.add(getBasedir() + "/target/classes"); - list.add(getBasedir() + "/target/classes"); + String classesDir = getBasedir() + "/target/classes"; + list.add(classesDir); + list.add(classesDir); + list.add(classesDir); - Set expected = Collections.singleton(Paths.get(getBasedir(), "target/classes")); + Set expected = Collections.singleton(Paths.get(classesDir)); MavenProjectStub project = new MavenProjectStub(); project.setFile(new File(getBasedir(), "pom.xml")); @@ -594,6 +597,32 @@ public void testPruneDirs() { assertEquals(expected, JavadocUtil.pruneDirs(project, list)); } + /** + * Method to test prunePaths() + * + */ + public void testPrunePaths() { + List list = new ArrayList<>(); + String classesDir = getBasedir() + "/target/classes"; + String tagletJar = getBasedir() + + "/target/test-classes/unit/taglet-test/artifact-taglet/org/tullmann/taglets/1.0/taglets-1.0.jar"; + list.add(classesDir); + list.add(classesDir); + list.add(classesDir); + list.add(tagletJar); + list.add(tagletJar); + list.add(tagletJar); + + Set expectedNoJar = Collections.singleton(Paths.get(classesDir)); + Set expectedWithJar = new HashSet<>(Arrays.asList(Paths.get(classesDir), Paths.get(tagletJar))); + + MavenProjectStub project = new MavenProjectStub(); + project.setFile(new File(getBasedir(), "pom.xml")); + + assertEquals(expectedNoJar, JavadocUtil.prunePaths(project, list, false)); + assertEquals(expectedWithJar, JavadocUtil.prunePaths(project, list, true)); + } + /** * Method to test unifyPathSeparator() *