This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-doxia.git
The following commit(s) were added to refs/heads/master by this push:
new bf89e0b8 Warn again about ambiguous links in APT documents
bf89e0b8 is described below
commit bf89e0b8621e18245846dc0092d88990303244de
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Tue Nov 17 21:39:39 2026 +0000
Warn again about ambiguous links in APT documents
Doxia 1.x warned when an APT link to a .html target lacked ./; the move to
SLF4J in 2.0.0-M1 made it a debug message, so such links turn into same-page
anchors without any notice. The warning names the document and the line where
the block starts, skips literal #anchors, and is not repeated on the second
parse done by the toc macro.
---
.../apache/maven/doxia/module/apt/AptParser.java | 11 ++++++++--
.../maven/doxia/module/apt/AptParserTest.java | 25 ++++++++++++++++++++++
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git
a/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
b/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
index 1c6e76c8..a28a05fb 100644
---
a/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
+++
b/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
@@ -429,8 +429,15 @@ public class AptParser extends AbstractTextParser
implements AptMarkup {
if (hashIndex != -1 &&
!AptUtils.isExternalLink(linkAnchor)) {
String hash = linkAnchor.substring(hashIndex +
1);
- if (hash.endsWith(".html") &&
!hash.startsWith("./")) {
- LOGGER.debug("Ambiguous link '{}'. If this
is a local link, prepend \"./\"!", hash);
+ if (hash.endsWith(".html")
+ && !hash.startsWith("./")
+ && !hash.startsWith("#")
+ && !isSecondParsing()) {
+ LOGGER.warn(
+ "{}, line {}: Ambiguous link '{}'.
If this is a local link, prepend \"./\"!",
+ blockFileName != null ?
blockFileName : "Unknown source",
+ blockLineNumber,
+ hash);
}
// link##anchor means literal
diff --git
a/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java
b/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java
index 5c9be52c..2d386a3e 100644
---
a/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java
+++
b/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java
@@ -20,8 +20,11 @@ package org.apache.maven.doxia.module.apt;
import javax.inject.Inject;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.PrintStream;
import java.io.Reader;
+import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Iterator;
@@ -599,4 +602,26 @@ class AptParserTest extends AbstractParserTest {
protected String getVerbatimCodeSource() {
return "+--" + EOL + "<>{}=#*" + EOL + "+--" + EOL;
}
+
+ @Test
+ void ambiguousLinkIsReportedWithItsLocation() throws Exception {
+ String source = "Title" + EOL + EOL + " See {{{doxia-apt.html}one}},
{{{./other.html}two}}" + EOL
+ + " and {{{#literal.html}three}}." + EOL + EOL + " Next
paragraph." + EOL;
+
+ PrintStream originalErr = System.err;
+ ByteArrayOutputStream err = new ByteArrayOutputStream();
+ System.setErr(new PrintStream(err, true, "UTF-8"));
+ try {
+ createParser().parse(new StringReader(source), new
SinkEventTestingSink(), "index.apt");
+ } finally {
+ System.setErr(originalErr);
+ }
+
+ String log = err.toString("UTF-8");
+ assertTrue(
+ log.contains("WARN") && log.contains("index.apt, line 3:
Ambiguous link 'doxia-apt.html'"),
+ "expected a warning with the location, got: " + log);
+ assertFalse(log.contains("other.html"), "a link starting with ./ must
not be reported: " + log);
+ assertFalse(log.contains("literal.html"), "a literal anchor must not
be reported: " + log);
+ }
}