Skip to content
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 @@ -27,6 +27,7 @@

import org.apache.maven.doxia.markup.Markup;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.sink.SinkEventAttributes;
import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
import org.apache.maven.shared.utils.StringUtils;

Expand Down Expand Up @@ -343,7 +344,10 @@ protected void text(String text) {
* @see Sink#verbatim_()
*/
protected void verbatimText(String text) {
sink.verbatim();
// Sink.verbatim() only exists since Doxia 2, while report plugins always run against the Doxia
// provided by the Maven Site Plugin in use, which may still be Doxia 1. Only the attribute
// taking overload exists in both, so stick to it (MPIR issue 103).
sink.verbatim((SinkEventAttributes) null);

text(text);

Expand All @@ -364,7 +368,8 @@ protected void verbatimLink(String text, String href) {
if (href == null || href.isEmpty()) {
verbatimText(text);
} else {
sink.verbatim();
// see verbatimText(String) for why the attribute taking overload is used here
sink.verbatim((SinkEventAttributes) null);

link(href, text);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.maven.doxia.sink.Sink;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -125,4 +128,43 @@ void applyPattern() throws Throwable {
"http://www.apache.org/licenses/LICENSE-1.1"
});
}

/**
* Report plugins always run against the Doxia provided by the Maven Site Plugin in use, which may still be
* Doxia 1, where {@code Sink.verbatim()} does not exist yet. A dynamic proxy is used instead of a
* {@code SinkAdapter} subclass because {@code AbstractSink.verbatim()} is final and delegates to the
* attribute taking overload, which would hide the distinction this test is about.
*/
@Test
void verbatimOnlyUsesTheOverloadCommonToDoxia1And2() {
AtomicInteger verbatimCalls = new AtomicInteger();
Sink sink = (Sink) Proxy.newProxyInstance(
getClass().getClassLoader(), new Class<?>[] {Sink.class}, (proxy, method, args) -> {
if ("verbatim".equals(method.getName())) {
assertEquals(
1,
method.getParameterCount(),
"Sink.verbatim() does not exist in Doxia 1 and must not be called");
verbatimCalls.incrementAndGet();
}
return null;
});

AbstractMavenReportRenderer renderer = new AbstractMavenReportRenderer(sink) {
@Override
public String getTitle() {
return "title";
}

@Override
protected void renderBody() {
verbatimText("text");
verbatimLink("text", "https://maven.apache.org/");
}
};

renderer.render();

assertEquals(2, verbatimCalls.get());
}
}
Loading