According to RFC 3986 both variants are valid.
For instance, URL fragments for methods with parameters for Java <=9 look like:
https://docs.oracle.com/javase/9/docs/api/java/lang/Object.html#equals-java.lang.Object-
and for Java 10–17 they look like:
https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html#equals(java.lang.Object)
If you {@link ...}
to the Javadoc of a library that used a different tool to create its Javadoc than you do (or used a different version of the same tool) you're out of luck for the moment.
If we really do not find an according option at the Javadoc tool(s) (and I think we won't because why should external links be handled differently than internal ones) the first that comes into my mind is the Maven Resources Plugin. It has the feature of resource filtering (which is bad naming, since in fact it's string interpolation) and perhaps this could be used to replace the characters accordingly.
If that doesn't work there are other options, like running an external program, e.g. sed
, during a build. Let me think a while and try some things. I'm confident that I can come up with a working solution. However, please be patient. It's 4:30 a.m. here now and I think I need some hours of sleep soon. If someone comes up with a solution in the meantime, the better (though I don't think so but who knows... :)
Approach #1 – --release
option
There's javadoc
's --release
option:
The following core javadoc
options are equivalent to corresponding javac
options. See Standard Options for the detailed descriptions of using these options:
javac
's --release
:
[Well, that's funny...well, no, it's embarassing: The deep links to --release
and its Note: ...
dont' work in the end because centiseconds after jumping to them apparently a JS (AJAX?) comes into play and the page finally lands at its top. I want Sun Microsystems back!]
--release release
Compiles against the public, supported and documented API for a specific VM version. Supported release
targets are 6
, 7
, 8
, 9
, 10
, and 11
.
If this javadoc --release
solves your problem we dont' have to think further for a handmade solution.
Update: The --release
/<release>
option doesn't solve the problem. It's just to specify the link target version as in https://docs.oracle.com/javase/<version>/docs/api/...
. The docs above aren't too helpful in this regard and the maven-javadoc-plugin
doc isn't either: "<release> Provide source compatibility with specified release". At least it's documented here now. ;)
Approach #2 – Maven resource filtering
Maven's resource filtering doesn't help either since in Javadoc comments method references for methods with just one parameter can look like:
/**
* <p>Link to {@link Logger#info}</p>
* <p>Link to {@link Object#equals}</p>
*/
and for string interpolation we would need ${...}
(or the not well-known and unusual @...@
) definitions.
It would work (in theory) with the explicit form:
/**
* <p>"${(}" and "${)}" replaced by '-', if the additional '{' and '}' don't conflict with Javadoc comment's tags – but it seems they do</p>
* <p>Link to {@link Logger#info${(}String${)}}</p>
* <p>Link to {@link Object#equals${(}Object${)}}</p>
*
* <p> "@(@" and "@)@" replaced by '-'</p>, if the additional '@'s don't conflict with Javadoc comment's tags – but it seems they do</p>
* <p>Link to {@link Logger#info@(@String@)@}</p>
* <p>Link to {@link Object#equals@(@Object@)@}</p>
*/
I don't know (yet) whether these "reserved characters" can be escaped and if yes, how this could be done. I found How do you escape curly braces in javadoc inline tags, such as the {@code} tag but nothing from there works with {@link ...}
(yet).
UPDATE
Approach #3 – Maven XML Plugin's xml:transform
Doesn't work since the Javadoc HTMLs contain non-X(HT)ML-conformant unclosed <meta ... >
s and <link ... >
s.
Approach #4 a) – Groovy script via the GMavenPlus Plugin
Using FileVisitor, XPath – if that works with the non-X(HT)ML-conformant HTML – or whatever works then.
XPath doesn't work: [Fatal Error] :18:3: The element type "link" must be terminated by the matching end-tag "</link>".
... add a goal javascript:execute
and use a JS script with its CSS selectors and DOM manipulation.