Copilot commented on code in PR #244:
URL: 
https://github.com/apache/maven-reporting-impl/pull/244#discussion_r3740858228


##########
src/main/java/org/apache/maven/reporting/AbstractMavenReport.java:
##########
@@ -302,6 +327,97 @@ private void reportToSite() throws MojoExecutionException {
         }
     }
 
+    /**
+     * A sink for one subpage of a multipage report, remembering where it is 
meant to be written to.
+     */
+    private static class MultiPageSubSink extends SiteRendererSink {
+        private final File outputDirectory;
+
+        private final String outputName;
+
+        MultiPageSubSink(File outputDirectory, String outputName, 
DocumentRenderingContext docRenderingContext) {
+            super(docRenderingContext);
+            this.outputDirectory = outputDirectory;
+            this.outputName = outputName;
+        }
+
+        String getOutputName() {
+            return outputName;
+        }
+
+        File getOutputDirectory() {
+            return outputDirectory;
+        }
+    }
+
+    /**
+     * The sink factory handed to {@link #generate(Sink, SinkFactory, 
Locale)}, mirroring what Maven Site Plugin
+     * provides so that a multipage report behaves the same when its goal is 
invoked directly.
+     */
+    private static class MultiPageSinkFactory implements SinkFactory {
+        /**
+         * The report that is (maybe) generating multiple pages
+         */
+        private final MavenReport report;
+
+        /**
+         * The main DocumentRenderingContext, which is the base for the 
DocumentRenderingContext of subpages
+         */
+        private final DocumentRenderingContext docRenderingContext;
+
+        /**
+         * List of sinks (subpages) associated to this report
+         */
+        private final List<MultiPageSubSink> sinks = new ArrayList<>();
+
+        MultiPageSinkFactory(MavenReport report, DocumentRenderingContext 
docRenderingContext) {
+            this.report = report;
+            this.docRenderingContext = docRenderingContext;
+        }
+
+        @Override
+        public Sink createSink(File outputDirectory, String outputName) {
+            // Create a new document rendering context, similar to the main 
one, but with a different output name
+            String document = PathTool.getRelativeFilePath(
+                    report.getReportOutputDirectory().getPath(), new 
File(outputDirectory, outputName).getPath());
+            // Remove .html suffix since we know that we are in Site Renderer 
context
+            document = document.substring(0, document.lastIndexOf('.'));
+

Review Comment:
   `createSink(File, String)` strips the extension via `document.substring(0, 
document.lastIndexOf('.'))`, which will throw `StringIndexOutOfBoundsException` 
when `outputName` has no dot (e.g., a report passes `"page2"` instead of 
`"page2.html"`). Since `SinkFactory` is part of the report API, it’s safer to 
handle names without an extension gracefully.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to