Migrating to the docs.spring.io

This commit is contained in:
Marcin Grzejszczak
2020-06-04 13:11:04 +02:00
parent 9fc5902087
commit d4fefdcd77
7 changed files with 524 additions and 376 deletions

View File

@@ -4,6 +4,7 @@ Manual changes to this file will be lost when it is generated again.
Edit the files in the src/main/asciidoc/ directory instead.
////
image:https://circleci.com/gh/spring-cloud/spring-cloud-build.svg?style=svg[link="https://travis-ci.org/spring-cloud/spring-cloud-build"]
Spring Cloud Build is a common utility project for Spring Cloud
@@ -254,38 +255,38 @@ approach of generating documentation just add these plugins to your `docs` modul
[source,xml]
----
<profiles>
<profile>
<id>docs</id>
<build>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId> <1>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId> <2>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId> <3>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId> <4>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId> <5>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId> <6>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<profile>
<id>docs</id>
<build>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId> <1>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId> <2>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId> <3>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId> <4>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId> <5>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId> <6>
</plugin>
</plugins>
</build>
</profile>
</profiles>
----
<2> This plugin downloads sets up all the git information of the project
<2> This plugin downloads the resources of the `spring-cloud-build-docs` module
@@ -305,42 +306,42 @@ Spring Cloud Build Docs comes with a set of attributes for asciidoctor that you
[source,xml]
----
<attributes>
<docinfo>shared</docinfo>
<allow-uri-read>true</allow-uri-read>
<nofooter/>
<toc>left</toc>
<toc-levels>4</toc-levels>
<sectlinks>true</sectlinks>
<sources-root>${project.basedir}/src@</sources-root>
<asciidoc-sources-root>${project.basedir}/src/main/asciidoc@</asciidoc-sources-root>
<generated-resources-root>${project.basedir}/target/generated-resources@
</generated-resources-root>
<!-- Use this attribute the reference code from another module -->
<!-- Note the @ at the end, lowering the precedence of the attribute -->
<project-root>${maven.multiModuleProjectDirectory}@</project-root>
<!-- It's mandatory for you to pass the docs.main property -->
<github-repo>${docs.main}@</github-repo>
<github-raw>
https://raw.githubusercontent.com/spring-cloud/${docs.main}/${github-tag}@
</github-raw>
<github-code>https://github.com/spring-cloud/${docs.main}/tree/${github-tag}@
</github-code>
<github-issues>https://github.com/spring-cloud/${docs.main}/issues/@</github-issues>
<github-wiki>https://github.com/spring-cloud/${docs.main}/wiki@</github-wiki>
<github-master-code>https://github.com/spring-cloud/${docs.main}/tree/master@
</github-master-code>
<index-link>${index-link}@</index-link>
<docinfo>shared</docinfo>
<allow-uri-read>true</allow-uri-read>
<nofooter/>
<toc>left</toc>
<toc-levels>4</toc-levels>
<sectlinks>true</sectlinks>
<sources-root>${project.basedir}/src@</sources-root>
<asciidoc-sources-root>${project.basedir}/src/main/asciidoc@</asciidoc-sources-root>
<generated-resources-root>${project.basedir}/target/generated-resources@
</generated-resources-root>
<!-- Use this attribute the reference code from another module -->
<!-- Note the @ at the end, lowering the precedence of the attribute -->
<project-root>${maven.multiModuleProjectDirectory}@</project-root>
<!-- It's mandatory for you to pass the docs.main property -->
<github-repo>${docs.main}@</github-repo>
<github-raw>
https://raw.githubusercontent.com/spring-cloud/${docs.main}/${github-tag}@
</github-raw>
<github-code>https://github.com/spring-cloud/${docs.main}/tree/${github-tag}@
</github-code>
<github-issues>https://github.com/spring-cloud/${docs.main}/issues/@</github-issues>
<github-wiki>https://github.com/spring-cloud/${docs.main}/wiki@</github-wiki>
<github-master-code>https://github.com/spring-cloud/${docs.main}/tree/master@
</github-master-code>
<index-link>${index-link}@</index-link>
<!-- Spring Cloud specific -->
<!-- for backward compatibility -->
<spring-cloud-version>${project.version}@</spring-cloud-version>
<project-version>${project.version}@</project-version>
<github-tag>${github-tag}@</github-tag>
<version-type>${version-type}@</version-type>
<docs-url>https://docs.spring.io/${docs.main}/docs/${project.version}@</docs-url>
<raw-docs-url>${github-raw}@</raw-docs-url>
<project-version>${project.version}@</project-version>
<project-name>${docs.main}@</project-name>
<!-- Spring Cloud specific -->
<!-- for backward compatibility -->
<spring-cloud-version>${project.version}@</spring-cloud-version>
<project-version>${project.version}@</project-version>
<github-tag>${github-tag}@</github-tag>
<version-type>${version-type}@</version-type>
<docs-url>https://docs.spring.io/${docs.main}/docs/${project.version}@</docs-url>
<raw-docs-url>${github-raw}@</raw-docs-url>
<project-version>${project.version}@</project-version>
<project-name>${docs.main}@</project-name>
</attributes>
----
@@ -373,4 +374,4 @@ what will happen is that for GA project versions, we will clone `gs-guide1`, `gs
You can skip this by either not adding the `guides` profile, or passing the `-DskipGuides` system property when the profile is turned on.
You can configure the project version passed to guides via the `guides-project.version` (defaults to `${project.version}`). The phase at which guides get updated can be configured by `guides-update.phase` (defaults to `deploy`).
You can configure the project version passed to guides via the `guides-project.version` (defaults to `${project.version}`). The phase at which guides get updated can be configured by `guides-update.phase` (defaults to `deploy`).

View File

@@ -14,16 +14,14 @@
</parent>
<properties>
<docs.main>spring-cloud-build</docs.main>
<!-- Comma separated list of whitelisted branches -->
<docs.whitelisted.branches>2.1.x,2.2.x</docs.whitelisted.branches>
<main.basedir>${basedir}/..</main.basedir>
<gmavenplus-plugin.version>1.8.1</gmavenplus-plugin.version>
<groovy.version>2.5.10</groovy.version>
<!-- For the Groovy plugin -->
<groovyVersion>${groovy.version}</groovyVersion>
<!-- We don't want to downloaded sources of our own project-->
<maven-dependency-plugin-for-docs.phase>none</maven-dependency-plugin-for-docs.phase>
<maven-dependency-plugin-for-docs-classes.phase>none</maven-dependency-plugin-for-docs-classes.phase>
<docs.resources.dir>${project.basedir}/src/main/</docs.resources.dir>
<upload-docs-zip.phase>deploy</upload-docs-zip.phase>
<!-- We don't want to reference plugin classpath of ourselves -->
<readme.class.path>maven.compile.classpath</readme.class.path>
</properties>
<dependencies>
<!-- Script -->
@@ -39,63 +37,15 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>${groovy.version}</version>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>compile</scope>
</dependency>
<!-- Asciidoctor -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-xml</artifactId>
<version>${groovy.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-datetime</artifactId>
<version>${groovy.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-nio</artifactId>
<version>${groovy.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
<version>${groovy.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-jsr223</artifactId>
<version>${groovy.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-macro</artifactId>
<version>${groovy.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-sql</artifactId>
<version>${groovy.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-swing</artifactId>
<version>${groovy.version}</version>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<version>${asciidoctorj.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -109,42 +59,26 @@
<resource>
<directory>src/main</directory>
<excludes>
<exclude>groovy/**/*.*</exclude>
<exclude>java/**/*.*</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/groovy</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>${gmavenplus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>addSources</goal>
<goal>generateStubs</goal>
<goal>generateTestStubs</goal>
<goal>groovydoc-jar</goal>
<goal>single</goal>
</goals>
</execution>
</executions>
@@ -184,35 +118,12 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>unix</id>
<activation>
<os>
<family>unix</family>
<name>Linux</name>
</os>
</activation>
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Run tests</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<skip>${skipTests}</skip>
<executable>${basedir}/src/test/bash/run-bats.sh</executable>
</configuration>
</execution>
</executions>
<artifactId>maven-deploy-plugin</artifactId>
<goals>
<goal>deploy</goal>
<goal>deploy-file</goal>
</goals>
</plugin>
</plugins>
</build>

View File

@@ -1,112 +0,0 @@
package org.springframework.cloud.internal
import java.util.regex.Pattern
import groovy.json.JsonSlurper
import groovy.transform.CompileStatic
import org.springframework.core.io.Resource
import org.springframework.core.io.support.PathMatchingResourcePatternResolver
/**
* @author Marcin Grzejszczak
*/
class Main {
@CompileStatic
static void main(String... args) {
String outputFile = args[0]
String inclusionPattern = args.length > 1 ? args[1] : ".*"
File parent = new File(outputFile).parentFile
if (!parent.exists()) {
println "No parent directory [${parent.toString()}] found. Won't generate the configuration properties file"
return
}
new Generator().generate(outputFile, inclusionPattern)
}
static class Generator {
void generate(String outputFile, String inclusionPattern) {
println "Parsing all configuration metadata"
Resource[] resources = getResources()
println "Found [${resources.length}] configuration metadata jsons"
TreeSet names = new TreeSet()
def descriptions = [:]
int count = 0
int matchingPropertyCount = 0
int propertyCount = 0
Pattern pattern = Pattern.compile(inclusionPattern)
resources.each { Resource resource ->
if (resourceNameContainsPattern(resource)) {
count++
def slurper = new JsonSlurper()
slurper.parseText(resource.inputStream.text).properties.each { val ->
propertyCount++
if (!pattern.matcher(val.name).matches()) {
return
}
matchingPropertyCount++
names.add val.name
descriptions[val.name] = new ConfigValue(val.name, val.description, val.defaultValue)
}
}
}
println "Found [${count}] Cloud projects configuration metadata jsons. [${matchingPropertyCount}/${propertyCount}] were matching the pattern [${inclusionPattern}]"
println "Successfully built the description table"
if (names.empty) {
println("Will not update the table, since no configuration properties were found!")
return
}
new File(outputFile).text = """\
|===
|Name | Default | Description
${names.collect { it -> return descriptions[it] }.join("\n")}
|===
"""
println "Successfully stored the output file"
}
protected boolean resourceNameContainsPattern(Resource resource) {
try {
return resource.getURL().toString().contains("cloud")
}
catch (Exception e) {
println("Exception [${e}] for resource [${resource}] occurred while trying to retrieve its URL")
return false
}
}
protected Resource[] getResources() {
return new PathMatchingResourcePatternResolver()
.getResources("classpath*:/META-INF/spring-configuration-metadata.json")
}
}
@CompileStatic
static class ConfigValue {
String name
String description
Object defaultValue
ConfigValue() {}
ConfigValue(String name, String description, Object defaultValue) {
this.name = name
this.description = escapedValue(description)
this.defaultValue = escapedValue(defaultValue)
}
private String escapedValue(Object value) {
return value != null ?
value.toString().replaceAll('\\|', '\\\\|') : ''
}
String toString() {
"|${name} | ${defaultValue} | ${description}"
}
}
}

View File

@@ -0,0 +1,151 @@
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.cloud.internal;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.util.StreamUtils;
/**
* @author Marcin Grzejszczak
*/
public class Main {
public static void main(String... args) {
String outputFile = args[0];
String inclusionPattern = args.length > 1 ? args[1] : ".*";
File parent = new File(outputFile).getParentFile();
if (!parent.exists()) {
System.out.println("No parent directory [" + parent.toString()
+ "] found. Will not generate the configuration properties file");
return;
}
new Generator().generate(outputFile, inclusionPattern);
}
static class Generator {
void generate(String outputFile, String inclusionPattern) {
try {
System.out.println("Parsing all configuration metadata");
Resource[] resources = getResources();
System.out.println("Found [" + resources.length + "] configuration metadata jsons");
TreeSet<String> names = new TreeSet<>();
Map<String, ConfigValue> descriptions = new HashMap<>();
final AtomicInteger count = new AtomicInteger();
final AtomicInteger matchingPropertyCount = new AtomicInteger();
final AtomicInteger propertyCount = new AtomicInteger();
Pattern pattern = Pattern.compile(inclusionPattern);
for (Resource resource : resources) {
if (resourceNameContainsPattern(resource)) {
count.incrementAndGet();
byte[] bytes = StreamUtils.copyToByteArray(resource.getInputStream());
Map<String, Object> response = new ObjectMapper().readValue(bytes, HashMap.class);
List<Map<String, Object>> properties = (List<Map<String, Object>>) response.get("properties");
properties.forEach(val -> {
propertyCount.incrementAndGet();
String name = String.valueOf(val.get("name"));
if (!pattern.matcher(name).matches()) {
return;
}
String description = String.valueOf(val.get("description"));
Object defaultValue = val.get("defaultValue");
matchingPropertyCount.incrementAndGet();
names.add(name);
descriptions.put(name, new ConfigValue(name, description, defaultValue));
});
}
}
System.out.println(
"Found [" + count + "] Cloud projects configuration metadata jsons. [" + matchingPropertyCount
+ "/" + propertyCount + "] were matching the pattern [" + inclusionPattern + "]");
System.out.println("Successfully built the description table");
if (names.isEmpty()) {
System.out.println("Will not update the table, since no configuration properties were found!");
return;
}
Files.write(new File(outputFile).toPath(),
("|===\n"
+ "|Name | Default | Description\n\n" + names.stream()
.map(it -> descriptions.get(it).toString()).collect(Collectors.joining("\n"))
+ "\n\n" + "|===").getBytes());
System.out.println("Successfully stored the output file");
}
catch (IOException e) {
throw new IllegalStateException(e);
}
}
protected boolean resourceNameContainsPattern(Resource resource) {
try {
return resource.getURL().toString().contains("cloud");
}
catch (Exception e) {
System.out.println("Exception [" + e + "] for resource [" + resource
+ "] occurred while trying to retrieve its URL");
return false;
}
}
protected Resource[] getResources() throws IOException {
return new PathMatchingResourcePatternResolver()
.getResources("classpath*:/META-INF/spring-configuration-metadata.json");
}
}
static class ConfigValue {
public String name;
public String description;
public Object defaultValue;
ConfigValue() {
}
ConfigValue(String name, String description, Object defaultValue) {
this.name = name;
this.description = escapedValue(description);
this.defaultValue = escapedValue(defaultValue);
}
private String escapedValue(Object value) {
return value != null ? value.toString().replaceAll("\\|", "\\\\|") : "";
}
public String toString() {
return "|" + name + " | " + defaultValue + " | " + description;
}
}
}

View File

@@ -0,0 +1,126 @@
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.cloud.internal.asciidoctor;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import org.asciidoctor.ast.Document;
import org.asciidoctor.extension.Preprocessor;
import org.asciidoctor.extension.PreprocessorReader;
// taken from https://github.com/hibernate/hibernate-asciidoctor-extensions/blob/1.0.3.Final/src/main/java/org/hibernate/infra/asciidoctor/extensions/savepreprocessed/SavePreprocessedOutputPreprocessor.java
/**
* Preprocessor used to save the preprocessed output of the asciidoctor conversion. It allows to generate a single file
* integrating all the includes.
*
* @author Guillaume Smet
*/
class CoalescerPreprocessor extends Preprocessor {
private final File outputFile;
private static final List<String> FILTER_LICENSE_MARKERS = Arrays.asList("[preface]", "<<<");
private static final String COMMENT_MARKER = "//";
private static final String SOURCE_MARKER = "[source";
private static final List<String> SECTION_MARKERS = Arrays.asList("----", "....");
private static final String HEADER = "////\n" + "DO NOT EDIT THIS FILE. IT WAS GENERATED.\n"
+ "Manual changes to this file will be lost when it is generated again.\n"
+ "Edit the files in the src/main/asciidoc/ directory instead.\n" + "////\n\n";
CoalescerPreprocessor(File output_file) {
outputFile = output_file;
}
@Override
public void process(Document document, PreprocessorReader preprocessorReader) {
try {
LinkedList<String> filteredLines = filterLines(preprocessorReader.readLines());
filteredLines.addFirst(HEADER);
Files.write(outputFile.toPath(), filteredLines);
}
catch (IOException e) {
throw new IllegalStateException("Unable to write the preprocessed file " + outputFile, e);
}
}
/**
* This is used to filter out the license headers that are just after the markers
* defined. It also reindents the source code with spaces to be consistent with the
* 1.1 spec.
*/
private LinkedList<String> filterLines(List<String> lines) {
LinkedList<String> filteredLines = new LinkedList<>();
ParsingState state = ParsingState.NORMAL;
int counter = 0;
for (String line : lines) {
counter++;
switch (state) {
case NORMAL:
if (FILTER_LICENSE_MARKERS.contains(line)) {
state = ParsingState.FILTER_LICENSE;
}
else if (line.startsWith(SOURCE_MARKER)) {
state = ParsingState.SOURCE;
}
break;
case SOURCE:
if (SECTION_MARKERS.contains(line)) {
state = ParsingState.SOURCE_CONTENT;
}
else {
System.err.println("[source] requires to be followed by a section marker and line number [" + counter + "] with content [" + line + "] doesn't have it");
}
break;
case SOURCE_CONTENT:
if (SECTION_MARKERS.contains(line)) {
state = ParsingState.NORMAL;
}
else {
filteredLines.add(line.replaceAll("\t", " "));
continue;
}
break;
case FILTER_LICENSE:
if (line.startsWith(COMMENT_MARKER)) {
continue;
}
else {
state = ParsingState.NORMAL;
}
break;
}
filteredLines.add(line);
}
return filteredLines;
}
private enum ParsingState {
NORMAL, FILTER_LICENSE, SOURCE, SOURCE_CONTENT,
}
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.cloud.internal.asciidoctor;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.asciidoctor.Asciidoctor;
import org.asciidoctor.Attributes;
import org.asciidoctor.Options;
import org.asciidoctor.SafeMode;
public class ReadmeMain {
public static void main(String... args) {
File inputFile = new File(args[0]);
File outputFile = new File(args[1]);
System.out.println("Will do the Readme conversion from [" + inputFile + "] to [" + outputFile + "]");
new ReadmeMain().convert(inputFile, outputFile);
}
void convert(File input, File output) {
Asciidoctor asciidoctor = Asciidoctor.Factory.create();
asciidoctor.javaExtensionRegistry().preprocessor(new CoalescerPreprocessor(output));
Options options = options(input, output);
try {
String fileAsString = new String(Files.readAllBytes(input.toPath()));
asciidoctor.convert(fileAsString, options);
System.out.println("Successfully converted the Readme file!\n");
} catch (IOException ex) {
throw new IllegalStateException("Failed to convert the file", ex);
}
}
private Options options(File input, File output) {
Attributes attributes = new Attributes();
attributes.setAllowUriRead(true);
attributes.setAttribute("project-root", output.getParent());
Options options = new Options();
options.setSourceDir(input.getParent());
options.setBaseDir(input.getParent());
options.setAttributes(attributes);
options.setSafe(SafeMode.UNSAFE);
options.setParseHeaderOnly(true);
return options;
}
}

170
pom.xml
View File

@@ -31,16 +31,17 @@
<spring-boot.version>2.3.0.RELEASE</spring-boot.version>
<spring-cloud-build.version>2.3.1.BUILD-SNAPSHOT</spring-cloud-build.version>
<docs.resources.dir>${project.build.directory}/build-docs</docs.resources.dir>
<docs.classes.dir>${project.build.directory}/build-docs-classes</docs.classes.dir>
<refdocs.build.directory>${project.build.directory}/refdocs/</refdocs.build.directory>
<spring-doc-resources.version>0.2.1.RELEASE</spring-doc-resources.version>
<spring-asciidoctor-extensions.version>0.1.3.RELEASE
<spring-doc-resources.version>0.2.2.RELEASE</spring-doc-resources.version>
<spring-asciidoctor-extensions.version>0.2.0.RELEASE
</spring-asciidoctor-extensions.version>
<asciidoctorj-pdf.version>1.5.0-alpha.18</asciidoctorj-pdf.version>
<asciidoctorj-diagram.version>1.5.18</asciidoctorj-diagram.version>
<asciidoctorj-diagram.version>2.0.2</asciidoctorj-diagram.version>
<guides-project.version>${project.version}</guides-project.version>
<guides-update.phase>deploy</guides-update.phase>
<revision>${project.version}</revision>
<asciidoctorj.version>1.5.8</asciidoctorj.version>
<asciidoctorj.version>2.1.0</asciidoctorj.version>
<jruby-complete.version>9.2.7.0</jruby-complete.version>
<!-- Sonar -->
@@ -71,7 +72,7 @@
<maven-enforcer-plugin.version>3.0.0-M2</maven-enforcer-plugin.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version>
<asciidoctor-maven-plugin.version>1.5.8</asciidoctor-maven-plugin.version>
<asciidoctor-maven-plugin.version>1.6.0</asciidoctor-maven-plugin.version>
<build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
<artifactory-maven-plugin.version>2.2.1</artifactory-maven-plugin.version>
<license-maven-plugin.version>1.16</license-maven-plugin.version>
@@ -101,10 +102,17 @@
<configprops.path>${project.basedir}/src/main/asciidoc/_configprops.adoc</configprops.path>
<configprops.inclusionPattern>.*</configprops.inclusionPattern>
<maven-dependency-plugin-for-docs.phase>generate-resources</maven-dependency-plugin-for-docs.phase>
<maven-dependency-plugin-for-docs-classes.phase>generate-resources</maven-dependency-plugin-for-docs-classes.phase>
<maven-dependency-plugin-for-guides.phase>generate-resources</maven-dependency-plugin-for-guides.phase>
<generated-docs-multipage-output.dir>${project.build.directory}/generated-docs/reference/html</generated-docs-multipage-output.dir>
<generated-docs-singlepage-output.dir>${project.build.directory}/generated-docs/reference/htmlsingle</generated-docs-singlepage-output.dir>
<generated-docs-pdf-output.dir>${project.build.directory}/generated-docs/reference/pdf</generated-docs-pdf-output.dir>
<maven-deploy-plugin.version>2.7</maven-deploy-plugin.version>
<maven-deploy-plugin.deployZipRepositoryId>repo.spring.io</maven-deploy-plugin.deployZipRepositoryId>
<maven-deploy-plugin.deployZipUrl>https://repo.spring.io/libs-snapshot-local</maven-deploy-plugin.deployZipUrl>
<upload-docs-zip.phase>none</upload-docs-zip.phase>
<readme.main.classpath>${docs.classes.dir}</readme.main.classpath>
<readme.class.path>readme.class.path</readme.class.path>
</properties>
<dependencyManagement>
<dependencies>
@@ -437,7 +445,6 @@
checkstyle.additional.suppressions.file=${checkstyle.additional.suppressions.file}
</propertyExpansion>
<consoleOutput>true</consoleOutput>
<!-- TODO: Start fixing the errors -->
<includeTestSourceDirectory>
${maven-checkstyle-plugin.includeTestSourceDirectory}
</includeTestSourceDirectory>
@@ -487,6 +494,7 @@
${project.build.outputDirectory}/git.properties
</generateGitPropertiesFilename>
<skipPoms>false</skipPoms>
<useNativeGit>true</useNativeGit>
</configuration>
</plugin>
<!-- Support our own plugin -->
@@ -752,6 +760,9 @@
<url>https://repo.spring.io/libs-milestone-local</url>
</repository>
</distributionManagement>
<properties>
<maven-deploy-plugin.deployZipUrl>https://repo.spring.io/libs-milestone-local</maven-deploy-plugin.deployZipUrl>
</properties>
</profile>
<profile>
<id>bintray</id>
@@ -785,6 +796,9 @@
</plugin>
</plugins>
</build>
<properties>
<maven-deploy-plugin.deployZipUrl>https://repo.spring.io/libs-release-local</maven-deploy-plugin.deployZipUrl>
</properties>
</profile>
<profile>
<id>guides</id>
@@ -962,6 +976,30 @@
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpack-classes</id>
<phase>${maven-dependency-plugin-for-docs-classes.phase}</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.springframework.cloud
</groupId>
<artifactId>spring-cloud-build-docs
</artifactId>
<version>${spring-cloud-build.version}
</version>
<classifier>jar-with-dependencies</classifier>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${docs.classes.dir}
</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpack-docs-resources</id>
<phase>generate-resources</phase>
@@ -1107,8 +1145,8 @@
<project-version>${project.version}@</project-version>
<github-tag>${github-tag}@</github-tag>
<version-type>${version-type}@</version-type>
<docs-url>${docs-url}@</docs-url>
<raw-docs-url>${raw-docs-url}@</raw-docs-url>
<docs-url>https://docs.spring.io/${docs.main}/docs/${project.version}@</docs-url>
<raw-docs-url>${github-raw}@</raw-docs-url>
<project-version>${project.version}@</project-version>
<project-name>${docs.main}@</project-name>
</attributes>
@@ -1135,13 +1173,14 @@
<sourceHighlighter>highlight.js</sourceHighlighter>
<doctype>book</doctype>
<attributes>
<highlightjsdir>js/highlight</highlightjsdir>
<highlightjs-theme>atom-one-dark-reasonable</highlightjs-theme>
<linkcss>true</linkcss>
<imagesdir>./images</imagesdir>
<icons>font</icons>
<docinfo>shared</docinfo>
<stylesdir>css/</stylesdir>
<stylesheet>spring.css</stylesheet>
<linkcss>true</linkcss>
<icons>font</icons>
<highlightjsdir>js/highlight</highlightjsdir>
<highlightjs-theme>github</highlightjs-theme>
<imagesdir>./images</imagesdir>
<attribute-missing>warn</attribute-missing>
</attributes>
<logHandler>
@@ -1169,13 +1208,14 @@
<sourceHighlighter>highlight.js</sourceHighlighter>
<doctype>book</doctype>
<attributes>
<highlightjsdir>js/highlight</highlightjsdir>
<highlightjs-theme>atom-one-dark-reasonable</highlightjs-theme>
<linkcss>true</linkcss>
<imagesdir>./images</imagesdir>
<icons>font</icons>
<docinfo>shared</docinfo>
<stylesdir>css/</stylesdir>
<stylesheet>spring.css</stylesheet>
<linkcss>true</linkcss>
<icons>font</icons>
<highlightjsdir>js/highlight</highlightjsdir>
<highlightjs-theme>github</highlightjs-theme>
<imagesdir>./images</imagesdir>
</attributes>
</configuration>
</execution>
@@ -1244,16 +1284,20 @@
<executions>
<execution>
<id>readme</id>
<phase>process-resources</phase>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<java classname="org.jruby.Main"
failonerror="yes">
<arg value="${docs.resources.dir}/ruby/generate_readme.sh"/>
<arg value="-o"/>
<path id="readme.class.path">
<pathelement location="${readme.main.classpath}"/>
</path>
<java classname="org.springframework.cloud.internal.asciidoctor.ReadmeMain"
failonerror="yes" classpathref="${readme.class.path}">
<!-- Input -->
<arg value="${project.basedir}/src/main/asciidoc/README.adoc"/>
<!-- Output -->
<arg value="${main.basedir}/README.adoc"/>
</java>
</target>
@@ -1329,68 +1373,11 @@
input="${git.branch}" regexp="origin/(.*)"
replace="\1"/>
<var name="github-tag" value="${git.branch}"/>
<condition property="docs-url"
value="https://cloud.spring.io/${docs.main}">
<and>
<equals arg1="${version-type}" arg2="SNAPSHOT"/>
<or>
<equals arg1="${git.branch}" arg2="master"/>
<equals arg1="${git.branch}" arg2="origin/master"/>
</or>
</and>
</condition>
<condition property="docs-url"
value="https://cloud.spring.io/${docs.main}/${git.branch}">
<and>
<equals arg1="${version-type}" arg2="SNAPSHOT"/>
<not>
<or>
<equals arg1="${git.branch}" arg2="master"/>
<equals arg1="${git.branch}" arg2="origin/master"/>
</or>
</not>
</and>
</condition>
<condition property="docs-url"
value="https://cloud.spring.io/spring-cloud-static/${docs.main}/${project.version}">
<and>
<not>
<equals arg1="${version-type}" arg2="SNAPSHOT"/>
</not>
</and>
</condition>
<propertyregex property="raw-docs-url" override="true"
input="${docs-url}" regexp="https://cloud.spring.io/(.*)"
replace="https://raw.githubusercontent.com/\1"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<inherited>false</inherited>
<executions>
<execution>
<id>attach-zip</id>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>
${project.build.directory}/${project.artifactId}-${project.version}.zip
</file>
<type>zip</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jfrog.buildinfo</groupId>
<artifactId>artifactory-maven-plugin</artifactId>
@@ -1417,6 +1404,29 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven-deploy-plugin.version}</version>
<executions>
<execution>
<id>upload-docs-zip</id>
<phase>${upload-docs-zip.phase}</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<generatePom>false</generatePom>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<repositoryId>${maven-deploy-plugin.deployZipRepositoryId}</repositoryId>
<url>${maven-deploy-plugin.deployZipUrl}</url>
<file>${project.build.directory}/${project.artifactId}-${project.version}.zip</file>
<packaging>zip;zip.type=docs;zip.deployed=false;</packaging>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>