You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/10/09 21:41:12 UTC
(maven-doxia-sitetools) branch master updated (c064e04 -> 6e18c2a)
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git
from c064e04 Simplify GH PR template boilerplate
new 3468c0c Expose MultiPageSinkFactory so reports can render subpages outside the site
new 5d045ce Strip the extension from the subpage file name, not the whole path
new 6e18c2a Take and return Path in the new multipage sink API
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../siterenderer/sink/MultiPageSinkFactory.java | 139 +++++++++++++++++++++
.../doxia/siterenderer/sink/MultiPageSubSink.java | 61 +++++++++
.../sink/MultiPageSinkFactoryTest.java | 104 +++++++++++++++
3 files changed, 304 insertions(+)
create mode 100644 doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactory.java
create mode 100644 doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSubSink.java
create mode 100644 doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactoryTest.java
(maven-doxia-sitetools) 03/03: Take and return Path in the new multipage sink API
Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git
commit 6e18c2abdc318ad622af861c546e43c753725e49
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Fri Oct 9 19:58:42 2026 +0200
Take and return Path in the new multipage sink API
createSink(File, String) stays, since SinkFactory declares it.
---
.../siterenderer/sink/MultiPageSinkFactory.java | 27 ++++++++++++++++------
.../doxia/siterenderer/sink/MultiPageSubSink.java | 7 +++---
.../sink/MultiPageSinkFactoryTest.java | 4 ++--
3 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactory.java b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactory.java
index 8ed70fc..579f2a3 100644
--- a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactory.java
+++ b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactory.java
@@ -20,6 +20,7 @@ package org.apache.maven.doxia.siterenderer.sink;
import java.io.File;
import java.io.OutputStream;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -27,7 +28,6 @@ import java.util.List;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.sink.SinkFactory;
import org.apache.maven.doxia.siterenderer.DocumentRenderingContext;
-import org.codehaus.plexus.util.PathTool;
/**
* The sink factory to hand to a report that generates more than one page, so that each page it asks for is
@@ -52,7 +52,7 @@ public class MultiPageSinkFactory implements SinkFactory {
/**
* The directory the report writes its pages to, which subpage paths are relative to
*/
- private final File reportOutputDirectory;
+ private final Path reportOutputDirectory;
/**
* The main DocumentRenderingContext, which is the base for the DocumentRenderingContext of subpages
@@ -69,8 +69,8 @@ public class MultiPageSinkFactory implements SinkFactory {
* <code>MavenReport.getReportOutputDirectory()</code>
* @param docRenderingContext the rendering context of the report's main page
*/
- public MultiPageSinkFactory(File reportOutputDirectory, DocumentRenderingContext docRenderingContext) {
- this.reportOutputDirectory = reportOutputDirectory;
+ public MultiPageSinkFactory(Path reportOutputDirectory, DocumentRenderingContext docRenderingContext) {
+ this.reportOutputDirectory = reportOutputDirectory.toAbsolutePath().normalize();
this.docRenderingContext = docRenderingContext;
}
@@ -84,14 +84,15 @@ public class MultiPageSinkFactory implements SinkFactory {
if (extensionStart >= 0) {
documentName = documentName.substring(0, extensionStart);
}
- String document = PathTool.getRelativeFilePath(
- reportOutputDirectory.getPath(), new File(outputDirectory, documentName).getPath());
+ Path subpage =
+ outputDirectory.toPath().resolve(documentName).toAbsolutePath().normalize();
+ String document = toDocumentName(reportOutputDirectory.relativize(subpage));
DocumentRenderingContext subSinkContext = new DocumentRenderingContext(
docRenderingContext.getBasedir(), document, docRenderingContext.getGenerator());
// Create a sink for this subpage, based on this new document rendering context
- MultiPageSubSink sink = new MultiPageSubSink(outputDirectory, outputName, subSinkContext);
+ MultiPageSubSink sink = new MultiPageSubSink(outputDirectory.toPath(), outputName, subSinkContext);
// Add it to the list of sinks associated to this report
sinks.add(sink);
@@ -115,6 +116,18 @@ public class MultiPageSinkFactory implements SinkFactory {
throw new UnsupportedOperationException(UNSUPPORTED_MESSAGE + " OutputStream based sinks are not supported.");
}
+ private static String toDocumentName(Path relativePath) {
+ // Document names use '/' whatever the platform's separator is
+ StringBuilder document = new StringBuilder();
+ for (Path element : relativePath) {
+ if (document.length() > 0) {
+ document.append('/');
+ }
+ document.append(element);
+ }
+ return document.toString();
+ }
+
/**
* Get the subpage sinks handed out so far, in the order the report asked for them.
*
diff --git a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSubSink.java b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSubSink.java
index e148bac..c12e538 100644
--- a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSubSink.java
+++ b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSubSink.java
@@ -19,6 +19,7 @@
package org.apache.maven.doxia.siterenderer.sink;
import java.io.File;
+import java.nio.file.Path;
import org.apache.maven.doxia.siterenderer.DocumentRenderingContext;
@@ -30,11 +31,11 @@ import org.apache.maven.doxia.siterenderer.DocumentRenderingContext;
* @since 2.2.0
*/
public class MultiPageSubSink extends SiteRendererSink {
- private final File outputDirectory;
+ private final Path outputDirectory;
private final String outputName;
- MultiPageSubSink(File outputDirectory, String outputName, DocumentRenderingContext docRenderingContext) {
+ MultiPageSubSink(Path outputDirectory, String outputName, DocumentRenderingContext docRenderingContext) {
super(docRenderingContext);
this.outputDirectory = outputDirectory;
this.outputName = outputName;
@@ -54,7 +55,7 @@ public class MultiPageSubSink extends SiteRendererSink {
*
* @return the directory, as the report passed it to {@link MultiPageSinkFactory#createSink(File, String)}
*/
- public File getOutputDirectory() {
+ public Path getOutputDirectory() {
return outputDirectory;
}
}
diff --git a/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactoryTest.java b/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactoryTest.java
index c59c1da..1def1df 100644
--- a/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactoryTest.java
+++ b/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactoryTest.java
@@ -35,7 +35,7 @@ class MultiPageSinkFactoryTest {
private MultiPageSinkFactory newSinkFactory() {
DocumentRenderingContext mainContext = new DocumentRenderingContext(BASEDIR, "main-page", "generator");
- return new MultiPageSinkFactory(REPORT_OUTPUT_DIRECTORY, mainContext);
+ return new MultiPageSinkFactory(REPORT_OUTPUT_DIRECTORY.toPath(), mainContext);
}
@Test
@@ -51,7 +51,7 @@ class MultiPageSinkFactoryTest {
assertEquals(1, sinkFactory.getSinks().size());
MultiPageSubSink subSink = sinkFactory.getSinks().get(0);
- assertEquals(REPORT_OUTPUT_DIRECTORY, subSink.getOutputDirectory());
+ assertEquals(REPORT_OUTPUT_DIRECTORY.toPath(), subSink.getOutputDirectory());
assertEquals("subpage.html", subSink.getOutputName());
}
(maven-doxia-sitetools) 02/03: Strip the extension from the subpage file name, not the whole path
Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git
commit 5d045cea7b14443ad7bc9d421ecf5b01b18e2e1f
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Fri Oct 9 18:06:55 2026 +0200
Strip the extension from the subpage file name, not the whole path
lastIndexOf('.') on the relative path cut "api.v2/subpage" down to
"api", so a subpage in a dotted directory got the wrong document name.
---
.../maven/doxia/siterenderer/sink/MultiPageSinkFactory.java | 12 +++++++-----
.../doxia/siterenderer/sink/MultiPageSinkFactoryTest.java | 11 +++++++++++
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactory.java b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactory.java
index c050f17..8ed70fc 100644
--- a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactory.java
+++ b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactory.java
@@ -77,13 +77,15 @@ public class MultiPageSinkFactory implements SinkFactory {
@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(
- reportOutputDirectory.getPath(), new File(outputDirectory, outputName).getPath());
- // Remove the .html suffix since we know that we are in Site Renderer context
- int extensionStart = document.lastIndexOf('.');
+ // Remove the .html suffix since we know that we are in Site Renderer context; strip it from the file name
+ // only, so that a dot in a directory name is not mistaken for one
+ String documentName = outputName;
+ int extensionStart = documentName.lastIndexOf('.');
if (extensionStart >= 0) {
- document = document.substring(0, extensionStart);
+ documentName = documentName.substring(0, extensionStart);
}
+ String document = PathTool.getRelativeFilePath(
+ reportOutputDirectory.getPath(), new File(outputDirectory, documentName).getPath());
DocumentRenderingContext subSinkContext = new DocumentRenderingContext(
docRenderingContext.getBasedir(), document, docRenderingContext.getGenerator());
diff --git a/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactoryTest.java b/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactoryTest.java
index c1ea5d1..c59c1da 100644
--- a/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactoryTest.java
+++ b/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactoryTest.java
@@ -77,6 +77,17 @@ class MultiPageSinkFactoryTest {
sinkFactory.getSinks().get(0).getRenderingContext().getOutputPath());
}
+ @Test
+ void subpageInADirectoryWithADotKeepsTheDirectory() {
+ MultiPageSinkFactory sinkFactory = newSinkFactory();
+
+ sinkFactory.createSink(new File(REPORT_OUTPUT_DIRECTORY, "api.v2"), "subpage");
+
+ assertEquals(
+ "api.v2/subpage.html",
+ sinkFactory.getSinks().get(0).getRenderingContext().getOutputPath());
+ }
+
@Test
void onlyTheFileBasedFactoryMethodIsSupported() {
MultiPageSinkFactory sinkFactory = newSinkFactory();
(maven-doxia-sitetools) 01/03: Expose MultiPageSinkFactory so reports can render subpages outside the site
Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git
commit 3468c0c5dec82721e71a96fa629ce616f420c28c
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Fri Aug 14 22:57:04 2026 +0200
Expose MultiPageSinkFactory so reports can render subpages outside the site
Maven Site Plugin's ReportDocumentRenderer keeps this factory and its
sub-sink as private nested classes, so maven-reporting-impl had to copy
both verbatim to make a multipage report work when its goal is invoked
directly rather than through the site.
The public copy takes the report output directory rather than a
MavenReport, so that doxia-site-renderer needs no dependency on Maven
Reporting API.
An outputName carrying no filename extension no longer throws
StringIndexOutOfBoundsException; it is taken as the document name as-is.
---
.../siterenderer/sink/MultiPageSinkFactory.java | 124 +++++++++++++++++++++
.../doxia/siterenderer/sink/MultiPageSubSink.java | 60 ++++++++++
.../sink/MultiPageSinkFactoryTest.java | 93 ++++++++++++++++
3 files changed, 277 insertions(+)
diff --git a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactory.java b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactory.java
new file mode 100644
index 0000000..c050f17
--- /dev/null
+++ b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactory.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.doxia.siterenderer.sink;
+
+import java.io.File;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.SinkFactory;
+import org.apache.maven.doxia.siterenderer.DocumentRenderingContext;
+import org.codehaus.plexus.util.PathTool;
+
+/**
+ * The sink factory to hand to a report that generates more than one page, so that each page it asks for is
+ * rendered into the site the same way the report's main page is.
+ * <p>
+ * Every {@link #createSink(File, String)} call derives a {@link DocumentRenderingContext} from the main one and
+ * records the resulting {@link MultiPageSubSink}. Once the report has run, the caller merges the main sink into
+ * the site and then does the same for each sink in {@link #getSinks()}, writing it to its own
+ * {@link MultiPageSubSink#getOutputDirectory() output directory} and
+ * {@link MultiPageSubSink#getOutputName() output name}.
+ * <p>
+ * The document name of a subpage is its path relative to the report output directory, with the filename extension
+ * removed, since the site renderer appends <code>.html</code> itself. A name carrying no extension is taken as-is.
+ *
+ * @see MultiPageSubSink
+ * @since 2.2.0
+ */
+public class MultiPageSinkFactory implements SinkFactory {
+ private static final String UNSUPPORTED_MESSAGE =
+ "Only createSink(File, String) is supported by MultiPageSinkFactory.";
+
+ /**
+ * The directory the report writes its pages to, which subpage paths are relative to
+ */
+ private final File reportOutputDirectory;
+
+ /**
+ * 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<>();
+
+ /**
+ * @param reportOutputDirectory the directory the report writes its pages to, in general
+ * <code>MavenReport.getReportOutputDirectory()</code>
+ * @param docRenderingContext the rendering context of the report's main page
+ */
+ public MultiPageSinkFactory(File reportOutputDirectory, DocumentRenderingContext docRenderingContext) {
+ this.reportOutputDirectory = reportOutputDirectory;
+ 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(
+ reportOutputDirectory.getPath(), new File(outputDirectory, outputName).getPath());
+ // Remove the .html suffix since we know that we are in Site Renderer context
+ int extensionStart = document.lastIndexOf('.');
+ if (extensionStart >= 0) {
+ document = document.substring(0, extensionStart);
+ }
+
+ DocumentRenderingContext subSinkContext = new DocumentRenderingContext(
+ docRenderingContext.getBasedir(), document, docRenderingContext.getGenerator());
+
+ // Create a sink for this subpage, based on this new document rendering context
+ MultiPageSubSink sink = new MultiPageSubSink(outputDirectory, outputName, subSinkContext);
+
+ // Add it to the list of sinks associated to this report
+ sinks.add(sink);
+
+ return sink;
+ }
+
+ @Override
+ public Sink createSink(File outputDir, String outputName, String encoding) {
+ throw new UnsupportedOperationException(
+ UNSUPPORTED_MESSAGE + " The encoding is always determined by the site rendering context.");
+ }
+
+ @Override
+ public Sink createSink(OutputStream out) {
+ throw new UnsupportedOperationException(UNSUPPORTED_MESSAGE + " OutputStream based sinks are not supported.");
+ }
+
+ @Override
+ public Sink createSink(OutputStream out, String encoding) {
+ throw new UnsupportedOperationException(UNSUPPORTED_MESSAGE + " OutputStream based sinks are not supported.");
+ }
+
+ /**
+ * Get the subpage sinks handed out so far, in the order the report asked for them.
+ *
+ * @return the sinks, empty if the report turned out to produce a single page only
+ */
+ public List<MultiPageSubSink> getSinks() {
+ return Collections.unmodifiableList(sinks);
+ }
+}
diff --git a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSubSink.java b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSubSink.java
new file mode 100644
index 0000000..e148bac
--- /dev/null
+++ b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSubSink.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.doxia.siterenderer.sink;
+
+import java.io.File;
+
+import org.apache.maven.doxia.siterenderer.DocumentRenderingContext;
+
+/**
+ * A sink for one subpage of a multipage report, remembering where the subpage is meant to be written to.
+ * Instances are handed out by {@link MultiPageSinkFactory}, which is also the only thing that creates them.
+ *
+ * @see MultiPageSinkFactory
+ * @since 2.2.0
+ */
+public 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;
+ }
+
+ /**
+ * Get the file name the subpage is to be written to, relative to {@link #getOutputDirectory()}.
+ *
+ * @return the file name, as the report passed it to {@link MultiPageSinkFactory#createSink(File, String)}
+ */
+ public String getOutputName() {
+ return outputName;
+ }
+
+ /**
+ * Get the directory the subpage is to be written to. It need not exist yet.
+ *
+ * @return the directory, as the report passed it to {@link MultiPageSinkFactory#createSink(File, String)}
+ */
+ public File getOutputDirectory() {
+ return outputDirectory;
+ }
+}
diff --git a/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactoryTest.java b/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactoryTest.java
new file mode 100644
index 0000000..c1ea5d1
--- /dev/null
+++ b/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/sink/MultiPageSinkFactoryTest.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.doxia.siterenderer.sink;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+import org.apache.maven.doxia.siterenderer.DocumentRenderingContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class MultiPageSinkFactoryTest {
+ private static final File BASEDIR = new File("target/test-basedir");
+
+ private static final File REPORT_OUTPUT_DIRECTORY = new File(BASEDIR, "site");
+
+ private MultiPageSinkFactory newSinkFactory() {
+ DocumentRenderingContext mainContext = new DocumentRenderingContext(BASEDIR, "main-page", "generator");
+ return new MultiPageSinkFactory(REPORT_OUTPUT_DIRECTORY, mainContext);
+ }
+
+ @Test
+ void noSubpagesUntilTheReportAsksForOne() {
+ assertTrue(newSinkFactory().getSinks().isEmpty());
+ }
+
+ @Test
+ void subpageKeepsWhereItIsToBeWritten() {
+ MultiPageSinkFactory sinkFactory = newSinkFactory();
+
+ sinkFactory.createSink(REPORT_OUTPUT_DIRECTORY, "subpage.html");
+
+ assertEquals(1, sinkFactory.getSinks().size());
+ MultiPageSubSink subSink = sinkFactory.getSinks().get(0);
+ assertEquals(REPORT_OUTPUT_DIRECTORY, subSink.getOutputDirectory());
+ assertEquals("subpage.html", subSink.getOutputName());
+ }
+
+ @Test
+ void subpageDocumentIsRelativeToTheReportOutputDirectory() {
+ MultiPageSinkFactory sinkFactory = newSinkFactory();
+
+ sinkFactory.createSink(new File(REPORT_OUTPUT_DIRECTORY, "nested"), "subpage.html");
+
+ assertEquals(
+ "nested/subpage.html",
+ sinkFactory.getSinks().get(0).getRenderingContext().getOutputPath());
+ }
+
+ @Test
+ void subpageWithoutAnExtensionIsTakenAsIs() {
+ MultiPageSinkFactory sinkFactory = newSinkFactory();
+
+ sinkFactory.createSink(REPORT_OUTPUT_DIRECTORY, "subpage");
+
+ assertEquals(
+ "subpage.html",
+ sinkFactory.getSinks().get(0).getRenderingContext().getOutputPath());
+ }
+
+ @Test
+ void onlyTheFileBasedFactoryMethodIsSupported() {
+ MultiPageSinkFactory sinkFactory = newSinkFactory();
+
+ assertThrows(
+ UnsupportedOperationException.class,
+ () -> sinkFactory.createSink(REPORT_OUTPUT_DIRECTORY, "subpage.html", "UTF-8"));
+ assertThrows(UnsupportedOperationException.class, () -> sinkFactory.createSink(new ByteArrayOutputStream()));
+ assertThrows(
+ UnsupportedOperationException.class,
+ () -> sinkFactory.createSink(new ByteArrayOutputStream(), "UTF-8"));
+ assertTrue(sinkFactory.getSinks().isEmpty());
+ }
+}