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
35 changes: 35 additions & 0 deletions commons/doc-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,41 @@ the overall configuration requires at least these arguments:

Other features are described in this README.

## Antora documentation list

Available in an upcoming release (unreleased).

The `antora` goal generates `ROOT/partials/documentation-list.adoc` from
`<documents>` and includes it in the product's index page. Another component
can include the same list, for example:

include::opendj:ROOT:partial$documentation-list.adoc[]

Here `opendj` is the component name: `<antoraComponent>` when set, otherwise
the lowercased `<projectName>`. Set `<antoraComponent>` to match the component
name on the site when it differs from the default; otherwise, guide links on
the product's own index may not resolve. Set `<javadocUrl>` to include an API
reference in the list; the URL is omitted when this option is not set. For
example:

<antoraComponent>directory-service</antoraComponent>
<javadocUrl>/opendj/apidocs/index.html</javadocUrl>

Links on a product page target that page's own version. Links from another
component target the latest version. The Javadoc URL is written into the list
without surrounding whitespace and is not adjusted for the documentation
version. Use a root-relative or absolute URL: a page-relative URL resolves
against the page that includes the list.

The goal fails if the sources already contain
`partials/documentation-list.adoc`.

Before adding the include to the site, publish the generated partial and ensure
that every branch which can publish this product's documentation either provides
the partial or cannot overwrite the published modules. In particular, an older
sustaining branch may otherwise remove the partial on its next deployment.
Check the build's Java requirements before upgrading the plugin on such a branch.


## Plugin Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2024 3A Systems LLC.
* Copyright 2024-2026 3A Systems, LLC.
*/

package org.openidentityplatform.doc.maven;
Expand All @@ -28,6 +28,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -52,6 +53,15 @@ public abstract class AbstractAsciidocMojo extends AbstractMojo {
@Parameter(property = "projectName", required = true)
protected String projectName;

/** Antora component name; defaults to the lowercased project name. */
@Parameter(property = "antoraComponent")
private String antoraComponent;

protected String getAntoraComponent() {
String component = antoraComponent == null ? "" : antoraComponent.trim();
return component.isEmpty() ? projectName.toLowerCase(Locale.ROOT) : component;
}

/**
* Project version.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2024 3A Systems LLC.
* Portions Copyright 2026 3A Systems, LLC.
* Copyright 2024-2026 3A Systems, LLC.
*/

package org.openidentityplatform.doc.maven;
Expand All @@ -24,6 +23,7 @@
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;
import java.io.IOException;
Expand All @@ -41,6 +41,10 @@
@Mojo(name = "antora", defaultPhase = LifecyclePhase.SITE)
public class AntoraMojo extends AbstractAsciidocMojo {

/** Optional URL of the product's API reference. */
@Parameter(property = "javadocUrl")
private String javadocUrl;

Set<String> copyToRootFolders = new HashSet<>();
public AntoraMojo() {
copyToRootFolders.add("images");
Expand Down Expand Up @@ -196,16 +200,40 @@ private void createIndexForRoot() throws IOException, MojoExecutionException {
if(!Files.exists(pagesPath)) {
Files.createDirectory(pagesPath);
}
Path indexFilePath = Paths.get(pagesPath.toString(), "index.adoc");
Path partialsPath = rootPath.resolve("partials");
Files.createDirectories(partialsPath);
String component = getAntoraComponent();
TextStringBuilder builder = new TextStringBuilder();
builder.append("= ").append(projectName).appendln(" Documentation");
builder.appendNewLine();
// An explicit component selects its latest version, even on an older version's page.
// Omit it on pages of this component so their links stay within the current version.
builder.append(":generated-documentation-component: ").append(component).appendln(":");
builder.append("ifeval::[\"{page-component-name}\" == \"").append(component).appendln("\"]");
builder.appendln(":generated-documentation-component:");
builder.appendln("endif::[]");
builder.appendNewLine();
for(String doc : getDocuments()) {
builder.append("* xref:").append(doc).appendln(":index.adoc[]");
builder.append("* xref:{generated-documentation-component}").append(doc).appendln(":index.adoc[]");
}
String url = javadocUrl == null ? "" : javadocUrl.trim();
if (!url.isEmpty()) {
builder.append("* link:").append(url).appendln("[API Reference (Javadoc)]");
}
builder.appendNewLine();
builder.appendln(":generated-documentation-component!:");
Path listPath = partialsPath.resolve("documentation-list.adoc");
if (Files.exists(listPath)) {
throw new MojoExecutionException("Cannot generate documentation-list.adoc: a source partial already uses this name");
}
FileUtils.writeStringToFile(listPath.toFile(), builder.toString(), StandardCharsets.UTF_8);

builder = new TextStringBuilder();
builder.append("= ").append(projectName).appendln(" Documentation");
builder.appendNewLine();
builder.appendln("include::partial$documentation-list.adoc[]");
builder.appendNewLine();

FileUtils.writeStringToFile(indexFilePath.toFile(), builder.toString(), StandardCharsets.UTF_8);
FileUtils.writeStringToFile(pagesPath.resolve("index.adoc").toFile(), builder.toString(), StandardCharsets.UTF_8);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -70,16 +69,6 @@ public AsciidocToPdfMojo() {
@Parameter(property = "siteUrl", defaultValue = "https://doc.openidentityplatform.org")
private String siteUrl;

/**
* Antora component of this project on the documentation site, such as {@code openidm}.
*
* <br>
*
* Default: {@code projectName} in lower case.
*/
@Parameter(property = "antoraComponent")
private String antoraComponent;

/**
* Site version path for this component, such as {@code 15.2}. Empty means the
* unversioned current documentation. This is independent of the Maven project version.
Expand All @@ -106,8 +95,7 @@ public File getPdfSourceDirectory() {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
String pdfPath = getPdfOutputDirectory().getPath();
String component = antoraComponent != null && !antoraComponent.isEmpty()
? antoraComponent : projectName.toLowerCase(Locale.ROOT);
String component = getAntoraComponent();
try {
preparePdfSource(getAsciidocBuildSourceDirectory(), getPdfSourceDirectory(), siteUrl, component,
docVersion, componentDocVersions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,34 @@
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2024 3A Systems LLC.
* Portions Copyright 2026 3A Systems, LLC.
* Copyright 2024-2026 3A Systems, LLC.
*/

package org.openidentityplatform.doc.maven;

import org.apache.maven.plugin.logging.SystemStreamLog;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class AntoraMojoTest extends AbstractMojoTestCase {

Expand All @@ -52,6 +63,142 @@ public void testExecute() throws Exception {
this.getVariablesAndValuesFromObject(antoraMojo);
}

@Test
public void testGeneratedRootPageUsesReusableDocumentList() throws Exception {
AntoraMojo mojo = (AntoraMojo) lookupMojo("antora", getTestFile("src/test/resources/antora/pom.xml"));
configureMojo(mojo, "doc-maven-plugin", getTestFile("src/test/resources/antora/pom.xml"));
Path build = Files.createTempDirectory("antora-index-test");
try {
FileUtils.copyDirectory(getTestFile("src/test/resources/asciidoc"), build.resolve("source").toFile());
Files.writeString(build.resolve("source/reference/index.adoc"), "= Reference\n\ninclude::./chapter.adoc[]\n");
Files.writeString(build.resolve("source/admin-guide/index.adoc"), "= Administration\n\ninclude::./chapter.adoc[]\n");
mojo.buildDirectory = build.toFile();
mojo.projectName = "OpenDJ";
mojo.execute();

Path root = build.resolve("antora/modules/ROOT");
assertThat(Files.readString(root.resolve("pages/index.adoc"), StandardCharsets.UTF_8)
.replace("\r\n", "\n"))
.isEqualTo("= OpenDJ Documentation\n\ninclude::partial$documentation-list.adoc[]\n\n");
assertThat(Files.readString(root.resolve("partials/documentation-list.adoc"), StandardCharsets.UTF_8)
.replace("\r\n", "\n"))
.isEqualTo("\n:generated-documentation-component: opendj:\n"
+ "ifeval::[\"{page-component-name}\" == \"opendj\"]\n"
+ ":generated-documentation-component:\nendif::[]\n\n"
+ "* xref:{generated-documentation-component}reference:index.adoc[]\n"
+ "* xref:{generated-documentation-component}admin-guide:index.adoc[]\n\n"
+ ":generated-documentation-component!:\n");

setVariableValueToObject(mojo, "antoraComponent", " directory-service ");
setVariableValueToObject(mojo, "javadocUrl", " /opendj/apidocs/index.html ");
mojo.execute();
assertThat(Files.readString(root.resolve("partials/documentation-list.adoc"), StandardCharsets.UTF_8)
.replace("\r\n", "\n"))
.isEqualTo("\n:generated-documentation-component: directory-service:\n"
+ "ifeval::[\"{page-component-name}\" == \"directory-service\"]\n"
+ ":generated-documentation-component:\nendif::[]\n\n"
+ "* xref:{generated-documentation-component}reference:index.adoc[]\n"
+ "* xref:{generated-documentation-component}admin-guide:index.adoc[]\n"
+ "* link:/opendj/apidocs/index.html[API Reference (Javadoc)]\n\n"
+ ":generated-documentation-component!:\n");

setVariableValueToObject(mojo, "antoraComponent", " ");
setVariableValueToObject(mojo, "javadocUrl", " ");
mojo.projectName = "OpenIDM";
Locale previous = Locale.getDefault();
try {
Locale.setDefault(Locale.forLanguageTag("tr-TR"));
mojo.execute();
} finally {
Locale.setDefault(previous);
}
assertThat(Files.readString(root.resolve("partials/documentation-list.adoc"), StandardCharsets.UTF_8))
.contains(":generated-documentation-component: openidm:")
.doesNotContain("API Reference");

Path sourcePartials = build.resolve("source/partials");
Files.createDirectories(sourcePartials);
Files.writeString(sourcePartials.resolve("documentation-list.adoc"), "Existing content");
assertThatThrownBy(mojo::execute).isInstanceOf(MojoExecutionException.class)
.hasMessageContaining("documentation-list.adoc");
} finally {
FileUtils.deleteDirectory(build.toFile());
}
}

@Test
public void testMavenUserPropertiesConfigureDocumentationList() throws Exception {
File pom = getTestFile("src/test/resources/antora/pom.xml");
MavenProject project;
try (Reader reader = Files.newBufferedReader(pom.toPath(), StandardCharsets.UTF_8)) {
project = new MavenProject(new MavenXpp3Reader().read(reader));
}
project.setFile(pom);
MavenSession session = newMavenSession(project);
session.getUserProperties().setProperty("antoraComponent", " directory-service ");
session.getUserProperties().setProperty("javadocUrl", " /api/index.html ");
AntoraMojo mojo = (AntoraMojo) lookupConfiguredMojo(session, newMojoExecution("antora"));
Path build = Files.createTempDirectory("antora-properties-test");
try {
FileUtils.copyDirectory(getTestFile("src/test/resources/asciidoc"), build.resolve("source").toFile());
mojo.buildDirectory = build.toFile();
Files.writeString(build.resolve("source/reference/index.adoc"), "= Reference\n\ninclude::./chapter.adoc[]\n");
Files.writeString(build.resolve("source/admin-guide/index.adoc"), "= Administration\n\ninclude::./chapter.adoc[]\n");
mojo.projectName = "OpenDJ";
setVariableValueToObject(mojo, "documents", List.of("reference", "admin-guide"));
mojo.execute();
assertThat(Files.readString(build.resolve("antora/modules/ROOT/partials/documentation-list.adoc")))
.contains(":generated-documentation-component: directory-service:",
"link:/api/index.html[API Reference (Javadoc)]");
} finally {
FileUtils.deleteDirectory(build.toFile());
}
}

@Test
public void testPomOptionsConfigureDocumentationList() throws Exception {
File pom = getTestFile("src/test/resources/antora/pom.xml");
MavenProject project;
try (Reader reader = Files.newBufferedReader(pom.toPath(), StandardCharsets.UTF_8)) {
project = new MavenProject(new MavenXpp3Reader().read(reader));
}
project.setFile(pom);
project.getBuildPlugins().get(0).setGroupId("org.openidentityplatform.commons");
Xpp3Dom configuration = (Xpp3Dom) project.getBuildPlugins().get(0).getConfiguration();
Xpp3Dom component = new Xpp3Dom("antoraComponent");
component.setValue(" directory-service ");
configuration.addChild(component);
Xpp3Dom url = new Xpp3Dom("javadocUrl");
url.setValue(" /api/index.html ");
configuration.addChild(url);
AntoraMojo mojo = (AntoraMojo) lookupConfiguredMojo(project, "antora");
Path build = Files.createTempDirectory("antora-properties-test");
try {
FileUtils.copyDirectory(getTestFile("src/test/resources/asciidoc"), build.resolve("source").toFile());
mojo.buildDirectory = build.toFile();
Files.writeString(build.resolve("source/reference/index.adoc"), "= Reference\n\ninclude::./chapter.adoc[]\n");
Files.writeString(build.resolve("source/admin-guide/index.adoc"), "= Administration\n\ninclude::./chapter.adoc[]\n");
mojo.projectName = "OpenDJ";
setVariableValueToObject(mojo, "documents", List.of("reference", "admin-guide"));
mojo.execute();
assertThat(Files.readString(build.resolve("antora/modules/ROOT/partials/documentation-list.adoc")))
.contains(":generated-documentation-component: directory-service:",
"link:/api/index.html[API Reference (Javadoc)]");
} finally {
FileUtils.deleteDirectory(build.toFile());
}
}

@Test
public void testDocumentationListOptionsAreDescriptorParameters() throws Exception {
assertThat(newMojoExecution("antora").getMojoDescriptor().getParameterMap().get("antoraComponent")
.getExpression()).isEqualTo("${antoraComponent}");
assertThat(newMojoExecution("antora").getMojoDescriptor().getParameterMap().get("javadocUrl")
.getExpression()).isEqualTo("${javadocUrl}");
assertThat(newMojoExecution("asciidoc-to-pdf").getMojoDescriptor().getParameterMap().get("antoraComponent")
.getExpression()).isEqualTo("${antoraComponent}");
}

@Test
public void testConvertXrefWithCurrentDirPrefix() {
assertThat(AntoraMojo.convertXrefsToAntora(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ public void testMavenUserPropertySelectsHistoricalVersion() throws Exception {
assertPreparedLinks(mojo, "15.2/");
}

public void testPomComponentIsUsedInPdfLinks() throws Exception {
MavenProject project = readProject();
Xpp3Dom configuration = (Xpp3Dom) project.getBuildPlugins().get(0).getConfiguration();
Xpp3Dom component = new Xpp3Dom("antoraComponent");
component.setValue(" directory-service ");
configuration.addChild(component);
AsciidocToPdfMojo mojo = (AsciidocToPdfMojo) lookupConfiguredMojo(project, "asciidoc-to-pdf");
FileUtils.writeStringToFile(new File(mojo.getAsciidocBuildSourceDirectory(), "how-to/page.adoc"),
"xref:reference:page.adoc[A]", StandardCharsets.UTF_8);
mojo.execute();
assertThat(new File(mojo.getPdfSourceDirectory(), "how-to/page.adoc"))
.hasContent("link:https://doc.openidentityplatform.org/directory-service/15.2/reference/page.html[A]");
}

public void testComponentDocVersionsIsADescriptorParameter() throws Exception {
assertTrue(newMojoExecution("asciidoc-to-pdf").getMojoDescriptor()
.getParameterMap().containsKey("componentDocVersions"));
Expand Down
Loading