Skip to content

Commit

Permalink
Merge pull request #35479 from gsmet/downstream-doc-default-pipeline
Browse files Browse the repository at this point in the history
Include assembling the downstream doc in the default doc pipeline
  • Loading branch information
gsmet committed Aug 23, 2023
2 parents a6fdffa + b1915f0 commit 28de988
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
19 changes: 19 additions & 0 deletions docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3054,6 +3054,25 @@
</environmentVariables>
</configuration>
</execution>
<execution>
<id>assemble-downstream-doc</id>
<phase>prepare-package</phase>
<goals>
<!-- using the exec goal here so that we can set the workingDirectory properly
as this script has initially be developed to be a standalone JBang script
running at the root of the docs module -->
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>io.quarkus.docs.generation.AssembleDownstreamDocumentation</argument>
</arguments>
<workingDirectory>${project.basedir}</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
//usr/bin/env jbang "$0" "$@" ; exit $?

//DEPS io.quarkus.platform:quarkus-bom:3.2.2.Final@pom
//DEPS io.quarkus:quarkus-picocli
//DEPS io.quarkus:quarkus-jackson
//DEPS com.fasterxml.jackson.dataformat:jackson-dataformat-yaml

//JAVAC_OPTIONS -parameters
//JAVA_OPTIONS -Djava.util.logging.manager=org.jboss.logmanager.LogManager

//Q:CONFIG quarkus.log.level=SEVERE
//Q:CONFIG quarkus.log.category."downstreamdoc".level=INFO
//Q:CONFIG quarkus.banner.enabled=false
package io.quarkus.docs.generation;

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
Expand All @@ -34,12 +22,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import picocli.CommandLine.Command;

@Command(name = "downstreamdoc", mixinStandardHelpOptions = true)
public class downstreamdoc implements Runnable {
public class AssembleDownstreamDocumentation {

private static final Logger LOG = Logger.getLogger(downstreamdoc.class);
private static final Logger LOG = Logger.getLogger(AssembleDownstreamDocumentation.class);

private static final Path SOURCE_DOC_PATH = Path.of("src", "main", "asciidoc");
private static final Path DOC_PATH = Path.of("target", "asciidoc", "sources");
Expand All @@ -52,8 +37,7 @@ public class downstreamdoc implements Runnable {
private static final Path TARGET_GENERATED_DIRECTORY = TARGET_ROOT_DIRECTORY.resolve("_generated");
private static final Path TARGET_LISTING = Path.of("target", "downstream-files.txt");
private static final Set<Path> EXCLUDED_FILES = Set.of(
DOC_PATH.resolve("_attributes-local.adoc")
);
DOC_PATH.resolve("_attributes-local.adoc"));

private static final String ADOC_SUFFIX = ".adoc";
private static final Pattern XREF_PATTERN = Pattern.compile("xref:([^\\.#\\[ ]+)\\" + ADOC_SUFFIX);
Expand Down Expand Up @@ -88,13 +72,13 @@ public class downstreamdoc implements Runnable {
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE),
"* Using Maven:\n+\n--\n[source, bash, subs=attributes+]\n----\n$1----\n$4--");

@Override
public void run() {
public static void main(String[] args) throws Exception {
if (!Files.isDirectory(DOC_PATH)) {
LOG.error("Transformed AsciiDoc sources directory does not exist. Have you built the documentation?");
throw new IllegalStateException(
"Transformed AsciiDoc sources directory does not exist. Have you built the documentation?");
}
if (!Files.isDirectory(GENERATED_FILES_PATH)) {
LOG.error("Generated files directory does not exist. Have you built the documentation?");
throw new IllegalStateException("Generated files directory does not exist. Have you built the documentation?");
}

try {
Expand Down Expand Up @@ -196,13 +180,13 @@ public void run() {
Files.copy(sourceFile, targetFile, StandardCopyOption.REPLACE_EXISTING);
}

Files.writeString(TARGET_LISTING, allResolvedPaths.stream().map(p -> p.toString()).collect(Collectors.joining("\n")));
Files.writeString(TARGET_LISTING,
allResolvedPaths.stream().map(p -> p.toString()).collect(Collectors.joining("\n")));

LOG.info("Downstream documentation tree is available in: " + TARGET_ROOT_DIRECTORY);
LOG.info("Downstream documentation listing is available in: " + TARGET_LISTING);
} catch (IOException e) {
LOG.error("An error occurred while generating the downstream tree", e);
System.exit(1);
throw new UncheckedIOException("An error occurred while generating the downstream tree", e);
}
}

Expand Down Expand Up @@ -278,7 +262,7 @@ private static void deleteDirectory(Path directory) throws IOException {
.forEach(File::delete);
}

private void copyAsciidoc(Path sourceFile, Path targetFile, Set<String> downstreamGuides) throws IOException {
private static void copyAsciidoc(Path sourceFile, Path targetFile, Set<String> downstreamGuides) throws IOException {
List<String> guideLines = Files.readAllLines(sourceFile);

StringBuilder rewrittenGuide = new StringBuilder();
Expand Down Expand Up @@ -336,13 +320,14 @@ private void copyAsciidoc(Path sourceFile, Path targetFile, Set<String> downstre
String rewrittenGuideWithoutTabs = rewrittenGuide.toString().trim();

for (Entry<Pattern, String> tabReplacement : TABS_REPLACEMENTS.entrySet()) {
rewrittenGuideWithoutTabs = tabReplacement.getKey().matcher(rewrittenGuideWithoutTabs).replaceAll(tabReplacement.getValue());
rewrittenGuideWithoutTabs = tabReplacement.getKey().matcher(rewrittenGuideWithoutTabs)
.replaceAll(tabReplacement.getValue());
}

Files.writeString(targetFile, rewrittenGuideWithoutTabs.trim());
}

private String rewriteLinks(String content, Set<String> downstreamGuides) {
private static String rewriteLinks(String content, Set<String> downstreamGuides) {
content = XREF_PATTERN.matcher(content).replaceAll(mr -> {
if (downstreamGuides.contains(mr.group(1) + ADOC_SUFFIX)) {
return mr.group(0);
Expand Down

0 comments on commit 28de988

Please sign in to comment.