File 0002-Make-the-legacyMode-consistent-and-actually-useful.patch of Package maven-javadoc-plugin
From 1b8355643b694df5dfa3c04d1ae1a26f2a0e023b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fridrich=20=C5=A0trba?= <fridrich.strba@bluewin.ch>
Date: Sat, 12 Jul 2025 09:48:17 +0200
Subject: [PATCH 2/3] Make the legacyMode consistent and actually useful
* Filter out all of the module-info.java files in legacy mode
* Do not use --source-path in legacy mode as not to suck any
of those module-info.java files back
* Generate the javadoc from list of files and not list of
packages, which is not working if --source-path is not
specified
---
.../plugins/javadoc/AbstractJavadocMojo.java | 29 ++++++++++---------
1 file changed, 16 insertions(+), 13 deletions(-)
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 273e1a6e..8a191aef 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -2022,7 +2022,7 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
getLog().warn("sourceFileIncludes and sourceFileExcludes have no effect when subpackages are specified!");
includesExcludesActive = false;
}
- if (!packageNames.isEmpty() && !includesExcludesActive) {
+ if (!packageNames.isEmpty() && !includesExcludesActive && !legacyMode) {
addCommandLinePackages(cmd, javadocOutputDirectory, packageNames);
// ----------------------------------------------------------------------
@@ -2093,23 +2093,26 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
if (subpackages == null || subpackages.isEmpty()) {
Collection<String> excludedPackages = getExcludedPackages();
- final boolean autoExclude;
- if (release != null) {
- autoExclude = JavaVersion.parse(release).isBefore("9");
- } else if (source != null) {
- autoExclude = JavaVersion.parse(source).isBefore("9");
- } else {
- // if legacy mode is active, treat it like pre-Java 9 (exclude module-info),
- // otherwise don't auto-exclude anything.
- autoExclude = legacyMode;
+ // if legacy mode is active, treat it like pre-Java 9 (exclude module-info),
+ // otherwise don't auto-exclude anything. Do this regardless of the release
+ // or source values specified
+ boolean autoExclude = legacyMode;
+ if (!autoExclude) {
+ if (release != null) {
+ autoExclude = JavaVersion.parse(release).isBefore("9");
+ } else if (source != null) {
+ autoExclude = JavaVersion.parse(source).isBefore("9");
+ }
}
for (Path sourcePath : sourcePaths) {
File sourceDirectory = sourcePath.toFile();
- List<String> files = new ArrayList<>(JavadocUtil.getFilesFromSource(
+ ArrayList<String> files = new ArrayList<>(JavadocUtil.getFilesFromSource(
sourceDirectory, sourceFileIncludes, sourceFileExcludes, excludedPackages));
- if (autoExclude && files.remove("module-info.java")) {
+ // in the aggregate goal (and theoretically in others too), there can be
+ // more then one module-info.java. Filter out all of them.
+ if (autoExclude && files.removeIf(s -> s.endsWith("module-info.java"))) {
getLog().debug("Auto exclude module-info.java due to source value");
}
mappedFiles.put(sourcePath, files);
@@ -4603,7 +4606,7 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
}
if (moduleSourceDir == null) {
- if (!disableSourcepathUsage) {
+ if (!disableSourcepathUsage && !legacyMode) {
addArgIfNotEmpty(
arguments,
"-sourcepath",
--
2.50.1