Repository navigation
Support multipage reports when the goal is invoked directly - #244
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a NullPointerException when invoking reporting goals directly for multipage reports by providing a SinkFactory during site rendering, aligning behavior with Maven Site Plugin so multipage reports work consistently in both direct-goal and site modes.
Changes:
- Provide a
MultiPageSinkFactorytogenerate(...)inreportToSite()and render any collected subpage sinks after the main page is merged into the site. - Add internal
MultiPageSubSink/MultiPageSinkFactoryhelpers to track subpage output locations and rendering contexts. - Re-enable and strengthen the existing IT (
use-as-direct-mojo) to verify both multipage outputs exist and contain expected content.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/main/java/org/apache/maven/reporting/AbstractMavenReport.java | Passes a sink factory for multipage sub-sinks during direct-goal site rendering and merges generated subpages into the site output. |
| src/it/use-as-direct-mojo/verify.groovy | Re-enables assertions for multipage output and validates rendered content. |
| src/it/use-as-direct-mojo/invoker.properties | Re-enables the multipage goal in the direct-mojo IT. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Does it make sense to maven the MultiReportSink public instead of duplicating the code? |
|
So what proposal you have? |
Two steps:
|
|
TODO added in 4489b1b, follow-up filed as apache/maven-doxia-sitetools#671 — move |
4489b1b to
5d3f6f2
Compare
reportToSite() passed a null SinkFactory to generate(), so any report that creates sub-sinks for additional pages failed with an NPE as soon as its goal was run from the command line rather than through the site. The maven-plugin-report-plugin report is one such report. Provide the same MultiPageSinkFactory that Maven Site Plugin's ReportDocumentRenderer provides, collect the sub-sinks it hands out and merge each of them into the site next to the main document. The integration test for this was already written and disabled with a pointer to the issue, so it is simply enabled again.
…ugin Generated-by: Claude Opus 5 (1M context)
Both pages were byte-identical, so the ITs could not tell a sub-sink merged with the wrong context from a correct one.
Keeps the copies mechanically diffable against ReportDocumentRenderer until doxia-sitetools#671 replaces both.
5d3f6f2 to
d172e7f
Compare
Fixes #217.
reportToSite()passednullas theSinkFactorytogenerate(Sink, SinkFactory, Locale), with a TODO saying multipage reports would fail with an NPE. They do:Only the site path was affected.
reportToMarkup(), taken whenoutput.formatis set, already builds a sink factory, which is whyuse-as-direct-mojo-markupexercises the multi-page mojo happily whileuse-as-direct-mojocould not.The change
Hand
generate()aMultiPageSinkFactory: eachcreateSink(File, String)builds aDocumentRenderingContextderived from the main one, wraps it in aSiteRendererSinkthat remembers where it belongs, and records it. After the main document is merged into the site, every collected sub-sink is merged the same way.MultiPageSinkFactoryandMultiPageSubSinkare verbatim copies of the private nested classes in Maven Site Plugin'sReportDocumentRenderer, so a report behaves the same whether its goal is invoked directly or through the site, and the two copies stay diffable. apache/maven-doxia-sitetools#671 tracks moving them intodoxia-site-rendereras public API and deleting both copies; the extension-lessoutputNameStringIndexOutOfBoundsExceptionpresent in both is fixed there too.Behaviour change worth a release note:
getSinkFactory()is now non-null on a direct site-mode invocation. A report that usedgetSinkFactory() == nullto detect direct invocation now takes its multipage branch, which is what #217 asks for.Test
The integration test for exactly this was already written and disabled with a pointer to the issue, in
src/it/use-as-direct-mojo. This PR enablesinvoker.goals.4 = custom-reporting:multi-pageagain and asserts the rendered content.The
MultiPageReportfixture now renders a distinct title and body on its second page. Before, both pages were byte-identical, so an assertion onmulti-second.htmlcould not tell a sub-sink merged with the wrong context from a correct one.use-as-direct-mojo,use-as-site-reportanduse-as-direct-mojo-markupall assert that the second page carries the second page's content and not the first page's.Reverting only
AbstractMavenReportand rerunninguse-as-direct-mojoreproduces the reported failure:Verified:
mvn verifyunder JDK 17 → checkstyle, RAT, 3 unit tests and 6 ITs passed; the direct-mojo run logs both pages.I did not rebuild maven-plugin-report-plugin against this branch to re-verify the original report from the issue; the IT covers the same code path with the same API.