Skip to content

Commit

Permalink
[MJAVADOC-775] Option 'taglets/taglet/tagletpath' ignored when pointi…
Browse files Browse the repository at this point in the history
…ng to a JAR

New method JavadocUtil::prunePaths takes care of pruning classpath elements
correctly, the existing JavadocUtil::pruneDirs is now just a special
case delegating to prunePaths.

This closes #255
  • Loading branch information
kriegaex authored and michael-o committed Jul 14, 2024
1 parent be2fa20 commit 91369fa
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down
37 changes: 26 additions & 11 deletions src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,32 +118,47 @@ public class JavadocUtil {
+ "environment variable using -Xms:<size> and -Xmx:<size>.";

/**
* Method that removes the invalid directories in the specified directories. <b>Note</b>: All elements in
* <code>dirs</code> could be an absolute or relative against the project's base directory <code>String</code> path.
* Method that removes invalid classpath elements in the specified paths.
* <b>Note</b>: 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 <code>String</code> directories path that will be validated.
* @return a List of valid <code>String</code> 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<Path> pruneDirs(MavenProject project, Collection<String> dirs) {
public static Collection<Path> prunePaths(MavenProject project, Collection<String> paths, boolean includeFiles) {
final Path projectBasedir = project.getBasedir().toPath();

Set<Path> pruned = new LinkedHashSet<>(dirs.size());
for (String dir : dirs) {
if (dir == null) {
Set<Path> 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.
* <b>Note</b>: 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<Path> pruneDirs(MavenProject project, Collection<String> dirs) {
return prunePaths(project, dirs, false);
}

/**
* Method that removes the invalid files in the specified files. <b>Note</b>: All elements in <code>files</code>
* should be an absolute <code>String</code> path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -582,18 +584,45 @@ public void testCopyJavadocResources() throws Exception {
*/
public void testPruneDirs() {
List<String> 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<Path> expected = Collections.singleton(Paths.get(getBasedir(), "target/classes"));
Set<Path> expected = Collections.singleton(Paths.get(classesDir));

MavenProjectStub project = new MavenProjectStub();
project.setFile(new File(getBasedir(), "pom.xml"));

assertEquals(expected, JavadocUtil.pruneDirs(project, list));
}

/**
* Method to test prunePaths()
*
*/
public void testPrunePaths() {
List<String> 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<Path> expectedNoJar = Collections.singleton(Paths.get(classesDir));
Set<Path> 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()
*
Expand Down

0 comments on commit 91369fa

Please sign in to comment.