Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MJAVADOC-775] Option 'taglets/taglet/tagletpath' ignored when pointing to a JAR #255

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading