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 @@ -386,7 +386,11 @@ protected void verbatimLink(String text, String href) {
* @see Sink#verbatim_()
*/
protected void verbatimSource(String source) {
sink.verbatim(SinkEventAttributeSet.SOURCE);
// not SinkEventAttributeSet.SOURCE: that constant only exists since Doxia 2, where it replaced BOXED,
// and report plugins run against the Doxia the Maven Site Plugin provides, which may still be Doxia 1.
// Building the same attribute set by hand keeps this a plain verbatim block there instead of a
// NoSuchFieldError (MPIR issue 103 was the same problem one method over).
sink.verbatim(new SinkEventAttributeSet(SinkEventAttributes.DECORATION, "source"));

text(source);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.fail;

/**
Expand Down Expand Up @@ -167,4 +171,44 @@ protected void renderBody() {

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

/**
* Same reasoning for {@code verbatimSource}, one level down: the attribute set has to be built rather than
* read off {@code SinkEventAttributeSet.SOURCE}, which is only there since Doxia 2. Asserting the identity
* rather than only the content is what makes this fail if the constant is used again, since the constant
* carries exactly the same attribute.
*/
@Test
void verbatimSourceBuildsTheAttributeSetRatherThanReadingTheDoxia2Constant() {
List<SinkEventAttributes> verbatimAttributes = new ArrayList<>();
Sink sink = (Sink) Proxy.newProxyInstance(
getClass().getClassLoader(), new Class<?>[] {Sink.class}, (proxy, method, args) -> {
if ("verbatim".equals(method.getName()) && method.getParameterCount() == 1) {
verbatimAttributes.add((SinkEventAttributes) args[0]);
}
return null;
});

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

@Override
protected void renderBody() {
verbatimSource("var code = true;");
}
};

renderer.render();

assertEquals(1, verbatimAttributes.size());
SinkEventAttributes attributes = verbatimAttributes.get(0);
assertEquals("source", attributes.getAttribute(SinkEventAttributes.DECORATION));
assertNotSame(
SinkEventAttributeSet.SOURCE,
attributes,
"SinkEventAttributeSet.SOURCE does not exist in Doxia 1 and must not be read");
}
}
Loading