Add prefix to appendix property anchor links
Refactor property appendix generator code so that the complete section is generated and anchors follow the expected naming. Closes gh-26375pull/26632/head
parent
86a5c90d20
commit
34b288e5fe
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.boot.build.context.properties;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table entry regrouping a list of configuration properties sharing the same description.
|
|
||||||
*
|
|
||||||
* @author Brian Clozel
|
|
||||||
*/
|
|
||||||
class CompoundConfigurationTableEntry extends ConfigurationTableEntry {
|
|
||||||
|
|
||||||
private final Set<String> configurationKeys;
|
|
||||||
|
|
||||||
private final String description;
|
|
||||||
|
|
||||||
CompoundConfigurationTableEntry(String key, String description) {
|
|
||||||
this.key = key;
|
|
||||||
this.description = description;
|
|
||||||
this.configurationKeys = new TreeSet<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void addConfigurationKeys(ConfigurationProperty... properties) {
|
|
||||||
Stream.of(properties).map(ConfigurationProperty::getName).forEach(this.configurationKeys::add);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void write(AsciidocBuilder builder) {
|
|
||||||
builder.append("|[[" + this.key + "]]<<" + this.key + ",");
|
|
||||||
this.configurationKeys.forEach(builder::appendKey);
|
|
||||||
builder.appendln(">>");
|
|
||||||
builder.newLine().appendln("|").appendln("|+++", this.description, "+++");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2021 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.boot.build.context.properties;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table row regrouping a list of configuration properties sharing the same description.
|
||||||
|
*
|
||||||
|
* @author Brian Clozel
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
class CompoundRow extends Row {
|
||||||
|
|
||||||
|
private final Set<String> propertyNames;
|
||||||
|
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
CompoundRow(Snippet snippet, String prefix, String description) {
|
||||||
|
super(snippet, prefix);
|
||||||
|
this.description = description;
|
||||||
|
this.propertyNames = new TreeSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void addProperty(ConfigurationProperty property) {
|
||||||
|
this.propertyNames.add(property.getDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void write(Asciidoc asciidoc) {
|
||||||
|
asciidoc.append("|");
|
||||||
|
asciidoc.append("[[" + getAnchor() + "]]");
|
||||||
|
asciidoc.append("<<" + getAnchor() + ",");
|
||||||
|
this.propertyNames.forEach(asciidoc::appendWithHardLineBreaks);
|
||||||
|
asciidoc.appendln(">>");
|
||||||
|
asciidoc.appendln("|+++", this.description, "+++");
|
||||||
|
asciidoc.appendln("|");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,125 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.boot.build.context.properties;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.gradle.api.file.FileCollection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write Asciidoc documents with configuration properties listings.
|
|
||||||
*
|
|
||||||
* @author Brian Clozel
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
public class ConfigurationMetadataDocumentWriter {
|
|
||||||
|
|
||||||
public void writeDocument(Path outputDirectory, DocumentOptions options, FileCollection metadataFiles)
|
|
||||||
throws IOException {
|
|
||||||
assertValidOutputDirectory(outputDirectory);
|
|
||||||
if (!Files.exists(outputDirectory)) {
|
|
||||||
Files.createDirectory(outputDirectory);
|
|
||||||
}
|
|
||||||
List<ConfigurationTable> tables = createConfigTables(ConfigurationProperties.fromFiles(metadataFiles), options);
|
|
||||||
for (ConfigurationTable table : tables) {
|
|
||||||
writeConfigurationTable(table, outputDirectory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertValidOutputDirectory(Path outputDirPath) {
|
|
||||||
if (outputDirPath == null) {
|
|
||||||
throw new IllegalArgumentException("output path should not be null");
|
|
||||||
}
|
|
||||||
if (Files.exists(outputDirPath) && !Files.isDirectory(outputDirPath)) {
|
|
||||||
throw new IllegalArgumentException("output path already exists and is not a directory");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ConfigurationTable> createConfigTables(Map<String, ConfigurationProperty> metadataProperties,
|
|
||||||
DocumentOptions options) {
|
|
||||||
List<ConfigurationTable> tables = new ArrayList<>();
|
|
||||||
List<String> unmappedKeys = metadataProperties.values().stream().filter((property) -> !property.isDeprecated())
|
|
||||||
.map(ConfigurationProperty::getName).collect(Collectors.toList());
|
|
||||||
Map<String, CompoundConfigurationTableEntry> overrides = getOverrides(metadataProperties, unmappedKeys,
|
|
||||||
options);
|
|
||||||
options.getMetadataSections().forEach((id, keyPrefixes) -> tables
|
|
||||||
.add(createConfigTable(metadataProperties, unmappedKeys, overrides, id, keyPrefixes)));
|
|
||||||
if (!unmappedKeys.isEmpty()) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"The following keys were not written to the documentation: " + String.join(", ", unmappedKeys));
|
|
||||||
}
|
|
||||||
if (!overrides.isEmpty()) {
|
|
||||||
throw new IllegalStateException("The following keys were not written to the documentation: "
|
|
||||||
+ String.join(", ", overrides.keySet()));
|
|
||||||
}
|
|
||||||
return tables;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, CompoundConfigurationTableEntry> getOverrides(
|
|
||||||
Map<String, ConfigurationProperty> metadataProperties, List<String> unmappedKeys, DocumentOptions options) {
|
|
||||||
Map<String, CompoundConfigurationTableEntry> overrides = new HashMap<>();
|
|
||||||
options.getOverrides().forEach((keyPrefix, description) -> {
|
|
||||||
CompoundConfigurationTableEntry entry = new CompoundConfigurationTableEntry(keyPrefix, description);
|
|
||||||
List<String> matchingKeys = unmappedKeys.stream().filter((key) -> key.startsWith(keyPrefix))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
for (String matchingKey : matchingKeys) {
|
|
||||||
entry.addConfigurationKeys(metadataProperties.get(matchingKey));
|
|
||||||
}
|
|
||||||
overrides.put(keyPrefix, entry);
|
|
||||||
unmappedKeys.removeAll(matchingKeys);
|
|
||||||
});
|
|
||||||
return overrides;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ConfigurationTable createConfigTable(Map<String, ConfigurationProperty> metadataProperties,
|
|
||||||
List<String> unmappedKeys, Map<String, CompoundConfigurationTableEntry> overrides, String id,
|
|
||||||
List<String> keyPrefixes) {
|
|
||||||
ConfigurationTable table = new ConfigurationTable(id);
|
|
||||||
for (String keyPrefix : keyPrefixes) {
|
|
||||||
List<String> matchingOverrides = overrides.keySet().stream()
|
|
||||||
.filter((overrideKey) -> overrideKey.startsWith(keyPrefix)).collect(Collectors.toList());
|
|
||||||
matchingOverrides.forEach((match) -> table.addEntry(overrides.remove(match)));
|
|
||||||
}
|
|
||||||
List<String> matchingKeys = unmappedKeys.stream()
|
|
||||||
.filter((key) -> keyPrefixes.stream().anyMatch(key::startsWith)).collect(Collectors.toList());
|
|
||||||
for (String matchingKey : matchingKeys) {
|
|
||||||
ConfigurationProperty property = metadataProperties.get(matchingKey);
|
|
||||||
table.addEntry(new SingleConfigurationTableEntry(property));
|
|
||||||
}
|
|
||||||
unmappedKeys.removeAll(matchingKeys);
|
|
||||||
return table;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeConfigurationTable(ConfigurationTable table, Path outputDirectory) throws IOException {
|
|
||||||
Path outputFilePath = outputDirectory.resolve(table.getId() + ".adoc");
|
|
||||||
Files.deleteIfExists(outputFilePath);
|
|
||||||
Files.createFile(outputFilePath);
|
|
||||||
try (OutputStream outputStream = Files.newOutputStream(outputFilePath)) {
|
|
||||||
outputStream.write(table.toAsciidocTable().getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,98 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.boot.build.context.properties;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Options for generating documentation for configuration properties.
|
|
||||||
*
|
|
||||||
* @author Brian Clozel
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
public final class DocumentOptions {
|
|
||||||
|
|
||||||
private final Map<String, List<String>> metadataSections;
|
|
||||||
|
|
||||||
private final Map<String, String> overrides;
|
|
||||||
|
|
||||||
private DocumentOptions(Map<String, List<String>> metadataSections, Map<String, String> overrides) {
|
|
||||||
this.metadataSections = metadataSections;
|
|
||||||
this.overrides = overrides;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, List<String>> getMetadataSections() {
|
|
||||||
return this.metadataSections;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, String> getOverrides() {
|
|
||||||
return this.overrides;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builder for DocumentOptions.
|
|
||||||
*/
|
|
||||||
public static class Builder {
|
|
||||||
|
|
||||||
Map<String, List<String>> metadataSections = new HashMap<>();
|
|
||||||
|
|
||||||
Map<String, String> overrides = new HashMap<>();
|
|
||||||
|
|
||||||
SectionSpec addSection(String name) {
|
|
||||||
return new SectionSpec(this, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
Builder addOverride(String keyPrefix, String description) {
|
|
||||||
this.overrides.put(keyPrefix, description);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
DocumentOptions build() {
|
|
||||||
return new DocumentOptions(this.metadataSections, this.overrides);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuration for a documentation section listing properties for a specific theme.
|
|
||||||
*/
|
|
||||||
public static class SectionSpec {
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
private final Builder builder;
|
|
||||||
|
|
||||||
SectionSpec(Builder builder, String name) {
|
|
||||||
this.builder = builder;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
Builder withKeyPrefixes(String... keyPrefixes) {
|
|
||||||
this.builder.metadataSections.put(this.name, Arrays.asList(keyPrefixes));
|
|
||||||
return this.builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021-2021 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.boot.build.context.properties;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A configuration properties snippet.
|
||||||
|
*
|
||||||
|
* @author Brian Clozed
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
class Snippet {
|
||||||
|
|
||||||
|
private final String anchor;
|
||||||
|
|
||||||
|
private final String title;
|
||||||
|
|
||||||
|
private final Set<String> prefixes;
|
||||||
|
|
||||||
|
private final Map<String, String> overrides;
|
||||||
|
|
||||||
|
Snippet(String anchor, String title, Consumer<Config> config) {
|
||||||
|
Set<String> prefixes = new LinkedHashSet<>();
|
||||||
|
Map<String, String> overrides = new LinkedHashMap<>();
|
||||||
|
if (config != null) {
|
||||||
|
config.accept(new Config() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(String prefix) {
|
||||||
|
prefixes.add(prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(String prefix, String description) {
|
||||||
|
overrides.put(prefix, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.anchor = anchor;
|
||||||
|
this.title = title;
|
||||||
|
this.prefixes = prefixes;
|
||||||
|
this.overrides = overrides;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getAnchor() {
|
||||||
|
return this.anchor;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getTitle() {
|
||||||
|
return this.title;
|
||||||
|
}
|
||||||
|
|
||||||
|
void forEachPrefix(Consumer<String> action) {
|
||||||
|
this.prefixes.forEach(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
void forEachOverride(BiConsumer<String, String> action) {
|
||||||
|
this.overrides.forEach(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback to configure the snippet.
|
||||||
|
*/
|
||||||
|
interface Config {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accept the given prefix using the meta-data description.
|
||||||
|
* @param prefix the prefix to accept
|
||||||
|
*/
|
||||||
|
void accept(String prefix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accept the given prefix with a defined description.
|
||||||
|
* @param prefix the prefix to accept
|
||||||
|
* @param description the description to use
|
||||||
|
*/
|
||||||
|
void accept(String prefix, String description);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021-2021 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.boot.build.context.properties;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.gradle.api.file.FileCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration properties snippets.
|
||||||
|
*
|
||||||
|
* @author Brian Clozed
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
class Snippets {
|
||||||
|
|
||||||
|
private final ConfigurationProperties properties;
|
||||||
|
|
||||||
|
private final List<Snippet> snippets = new ArrayList<>();
|
||||||
|
|
||||||
|
Snippets(FileCollection configurationPropertyMetadata) {
|
||||||
|
this.properties = ConfigurationProperties.fromFiles(configurationPropertyMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
void add(String anchor, String title, Consumer<Snippet.Config> config) {
|
||||||
|
this.snippets.add(new Snippet(anchor, title, config));
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeTo(Path outputDirectory) throws IOException {
|
||||||
|
createDirectory(outputDirectory);
|
||||||
|
Set<String> remaining = this.properties.stream().filter((property) -> !property.isDeprecated())
|
||||||
|
.map(ConfigurationProperty::getName).collect(Collectors.toSet());
|
||||||
|
for (Snippet snippet : this.snippets) {
|
||||||
|
Set<String> written = writeSnippet(outputDirectory, snippet, remaining);
|
||||||
|
remaining.removeAll(written);
|
||||||
|
}
|
||||||
|
if (!remaining.isEmpty()) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"The following keys were not written to the documentation: " + String.join(", ", remaining));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<String> writeSnippet(Path outputDirectory, Snippet snippet, Set<String> remaining) throws IOException {
|
||||||
|
Table table = new Table();
|
||||||
|
Set<String> added = new HashSet<>();
|
||||||
|
snippet.forEachOverride((prefix, description) -> {
|
||||||
|
CompoundRow row = new CompoundRow(snippet, prefix, description);
|
||||||
|
remaining.stream().filter((candidate) -> candidate.startsWith(prefix)).forEach((name) -> {
|
||||||
|
if (added.add(name)) {
|
||||||
|
row.addProperty(this.properties.get(name));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
table.addRow(row);
|
||||||
|
});
|
||||||
|
snippet.forEachPrefix((prefix) -> {
|
||||||
|
remaining.stream().filter((candidate) -> candidate.startsWith(prefix)).forEach((name) -> {
|
||||||
|
if (added.add(name)) {
|
||||||
|
table.addRow(new SingleRow(snippet, this.properties.get(name)));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Asciidoc asciidoc = getAsciidoc(snippet, table);
|
||||||
|
writeAsciidoc(outputDirectory, snippet, asciidoc);
|
||||||
|
return added;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Asciidoc getAsciidoc(Snippet snippet, Table table) {
|
||||||
|
Asciidoc asciidoc = new Asciidoc();
|
||||||
|
asciidoc.appendln("[[" + snippet.getAnchor() + "]]");
|
||||||
|
asciidoc.appendln("== ", snippet.getTitle());
|
||||||
|
table.write(asciidoc);
|
||||||
|
return asciidoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeAsciidoc(Path outputDirectory, Snippet snippet, Asciidoc asciidoc) throws IOException {
|
||||||
|
String[] parts = (snippet.getAnchor()).split("\\.");
|
||||||
|
Path path = outputDirectory;
|
||||||
|
for (int i = 0; i < parts.length; i++) {
|
||||||
|
String name = (i < parts.length - 1) ? parts[i] : parts[i] + ".adoc";
|
||||||
|
path = path.resolve(name);
|
||||||
|
}
|
||||||
|
createDirectory(path.getParent());
|
||||||
|
Files.deleteIfExists(path);
|
||||||
|
try (OutputStream outputStream = Files.newOutputStream(path)) {
|
||||||
|
outputStream.write(asciidoc.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createDirectory(Path path) throws IOException {
|
||||||
|
assertValidOutputDirectory(path);
|
||||||
|
if (!Files.exists(path)) {
|
||||||
|
Files.createDirectory(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertValidOutputDirectory(Path path) {
|
||||||
|
if (path == null) {
|
||||||
|
throw new IllegalArgumentException("Directory path should not be null");
|
||||||
|
}
|
||||||
|
if (Files.exists(path) && !Files.isDirectory(path)) {
|
||||||
|
throw new IllegalArgumentException("Path already exists and is not a directory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.boot.build.context.properties;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link CompoundConfigurationTableEntry}.
|
|
||||||
*
|
|
||||||
* @author Brian Clozel
|
|
||||||
*/
|
|
||||||
public class CompoundConfigurationTableEntryTests {
|
|
||||||
|
|
||||||
private static final String NEWLINE = System.lineSeparator();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void simpleProperty() {
|
|
||||||
ConfigurationProperty firstProp = new ConfigurationProperty("spring.test.first", "java.lang.String");
|
|
||||||
ConfigurationProperty secondProp = new ConfigurationProperty("spring.test.second", "java.lang.String");
|
|
||||||
ConfigurationProperty thirdProp = new ConfigurationProperty("spring.test.third", "java.lang.String");
|
|
||||||
CompoundConfigurationTableEntry entry = new CompoundConfigurationTableEntry("spring.test",
|
|
||||||
"This is a description.");
|
|
||||||
entry.addConfigurationKeys(firstProp, secondProp, thirdProp);
|
|
||||||
AsciidocBuilder builder = new AsciidocBuilder();
|
|
||||||
entry.write(builder);
|
|
||||||
assertThat(builder.toString()).isEqualTo("|[[spring.test]]<<spring.test,`+spring.test.first+` +" + NEWLINE
|
|
||||||
+ "`+spring.test.second+` +" + NEWLINE + "`+spring.test.third+` +" + NEWLINE + ">>" + NEWLINE + NEWLINE
|
|
||||||
+ "|" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2021 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.boot.build.context.properties;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link CompoundRow}.
|
||||||
|
*
|
||||||
|
* @author Brian Clozel
|
||||||
|
*/
|
||||||
|
public class CompoundRowTests {
|
||||||
|
|
||||||
|
private static final String NEWLINE = System.lineSeparator();
|
||||||
|
|
||||||
|
private static final Snippet SNIPPET = new Snippet("my", "title", null);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void simpleProperty() {
|
||||||
|
CompoundRow row = new CompoundRow(SNIPPET, "spring.test", "This is a description.");
|
||||||
|
row.addProperty(new ConfigurationProperty("spring.test.first", "java.lang.String"));
|
||||||
|
row.addProperty(new ConfigurationProperty("spring.test.second", "java.lang.String"));
|
||||||
|
row.addProperty(new ConfigurationProperty("spring.test.third", "java.lang.String"));
|
||||||
|
Asciidoc asciidoc = new Asciidoc();
|
||||||
|
row.write(asciidoc);
|
||||||
|
assertThat(asciidoc.toString()).isEqualTo("|[[my.spring.test]]<<my.spring.test,`+spring.test.first+` +"
|
||||||
|
+ NEWLINE + "`+spring.test.second+` +" + NEWLINE + "`+spring.test.third+` +" + NEWLINE + ">>" + NEWLINE
|
||||||
|
+ "|+++This is a description.+++" + NEWLINE + "|" + NEWLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2021 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.boot.build.context.properties;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link ConfigurationTable}.
|
|
||||||
*
|
|
||||||
* @author Brian Clozel
|
|
||||||
*/
|
|
||||||
public class ConfigurationTableTests {
|
|
||||||
|
|
||||||
private static final String NEWLINE = System.lineSeparator();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void simpleTable() {
|
|
||||||
ConfigurationTable table = new ConfigurationTable("test");
|
|
||||||
ConfigurationProperty first = new ConfigurationProperty("spring.test.prop", "java.lang.String", "something",
|
|
||||||
"This is a description.", false);
|
|
||||||
ConfigurationProperty second = new ConfigurationProperty("spring.test.other", "java.lang.String", "other value",
|
|
||||||
"This is another description.", false);
|
|
||||||
table.addEntry(new SingleConfigurationTableEntry(first));
|
|
||||||
table.addEntry(new SingleConfigurationTableEntry(second));
|
|
||||||
assertThat(table.toAsciidocTable()).isEqualTo("[cols=\"4,3,3\", options=\"header\"]" + NEWLINE + "|==="
|
|
||||||
+ NEWLINE + "|Key|Default Value|Description" + NEWLINE + NEWLINE
|
|
||||||
+ "|[[spring.test.other]]<<spring.test.other,`+spring.test.other+`>>" + NEWLINE + "|`+other value+`"
|
|
||||||
+ NEWLINE + "|+++This is another description.+++" + NEWLINE + NEWLINE
|
|
||||||
+ "|[[spring.test.prop]]<<spring.test.prop,`+spring.test.prop+`>>" + NEWLINE + "|`+something+`"
|
|
||||||
+ NEWLINE + "|+++This is a description.+++" + NEWLINE + NEWLINE + "|===" + NEWLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,111 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.boot.build.context.properties;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link SingleConfigurationTableEntry}.
|
|
||||||
*
|
|
||||||
* @author Brian Clozel
|
|
||||||
*/
|
|
||||||
public class SingleConfigurationTableEntryTests {
|
|
||||||
|
|
||||||
private static final String NEWLINE = System.lineSeparator();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void simpleProperty() {
|
|
||||||
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop", "java.lang.String", "something",
|
|
||||||
"This is a description.", false);
|
|
||||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
|
||||||
AsciidocBuilder builder = new AsciidocBuilder();
|
|
||||||
entry.write(builder);
|
|
||||||
assertThat(builder.toString()).isEqualTo("|[[spring.test.prop]]<<spring.test.prop,`+spring.test.prop+`>>"
|
|
||||||
+ NEWLINE + "|`+something+`" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void noDefaultValue() {
|
|
||||||
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop", "java.lang.String", null,
|
|
||||||
"This is a description.", false);
|
|
||||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
|
||||||
AsciidocBuilder builder = new AsciidocBuilder();
|
|
||||||
entry.write(builder);
|
|
||||||
assertThat(builder.toString()).isEqualTo("|[[spring.test.prop]]<<spring.test.prop,`+spring.test.prop+`>>"
|
|
||||||
+ NEWLINE + "|" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void defaultValueWithPipes() {
|
|
||||||
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop", "java.lang.String",
|
|
||||||
"first|second", "This is a description.", false);
|
|
||||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
|
||||||
AsciidocBuilder builder = new AsciidocBuilder();
|
|
||||||
entry.write(builder);
|
|
||||||
assertThat(builder.toString()).isEqualTo("|[[spring.test.prop]]<<spring.test.prop,`+spring.test.prop+`>>"
|
|
||||||
+ NEWLINE + "|`+first\\|second+`" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void defaultValueWithBackslash() {
|
|
||||||
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop", "java.lang.String",
|
|
||||||
"first\\second", "This is a description.", false);
|
|
||||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
|
||||||
AsciidocBuilder builder = new AsciidocBuilder();
|
|
||||||
entry.write(builder);
|
|
||||||
assertThat(builder.toString()).isEqualTo("|[[spring.test.prop]]<<spring.test.prop,`+spring.test.prop+`>>"
|
|
||||||
+ NEWLINE + "|`+first\\\\second+`" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void descriptionWithPipe() {
|
|
||||||
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop", "java.lang.String", null,
|
|
||||||
"This is a description with a | pipe.", false);
|
|
||||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
|
||||||
AsciidocBuilder builder = new AsciidocBuilder();
|
|
||||||
entry.write(builder);
|
|
||||||
assertThat(builder.toString()).isEqualTo("|[[spring.test.prop]]<<spring.test.prop,`+spring.test.prop+`>>"
|
|
||||||
+ NEWLINE + "|" + NEWLINE + "|+++This is a description with a \\| pipe.+++" + NEWLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void mapProperty() {
|
|
||||||
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop",
|
|
||||||
"java.util.Map<java.lang.String,java.lang.String>", null, "This is a description.", false);
|
|
||||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
|
||||||
AsciidocBuilder builder = new AsciidocBuilder();
|
|
||||||
entry.write(builder);
|
|
||||||
assertThat(builder.toString()).isEqualTo("|[[spring.test.prop]]<<spring.test.prop,`+spring.test.prop.*+`>>"
|
|
||||||
+ NEWLINE + "|" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void listProperty() {
|
|
||||||
String[] defaultValue = new String[] { "first", "second", "third" };
|
|
||||||
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop",
|
|
||||||
"java.util.List<java.lang.String>", defaultValue, "This is a description.", false);
|
|
||||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
|
||||||
AsciidocBuilder builder = new AsciidocBuilder();
|
|
||||||
entry.write(builder);
|
|
||||||
assertThat(builder.toString()).isEqualTo(
|
|
||||||
"|[[spring.test.prop]]<<spring.test.prop,`+spring.test.prop+`>>" + NEWLINE + "|`+first," + NEWLINE
|
|
||||||
+ "second," + NEWLINE + "third+`" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2021 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.boot.build.context.properties;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link SingleRow}.
|
||||||
|
*
|
||||||
|
* @author Brian Clozel
|
||||||
|
*/
|
||||||
|
public class SingleRowTests {
|
||||||
|
|
||||||
|
private static final String NEWLINE = System.lineSeparator();
|
||||||
|
|
||||||
|
private static final Snippet SNIPPET = new Snippet("my", "title", null);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void simpleProperty() {
|
||||||
|
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop", "java.lang.String", "something",
|
||||||
|
"This is a description.", false);
|
||||||
|
SingleRow row = new SingleRow(SNIPPET, property);
|
||||||
|
Asciidoc asciidoc = new Asciidoc();
|
||||||
|
row.write(asciidoc);
|
||||||
|
assertThat(asciidoc.toString()).isEqualTo("|[[my.spring.test.prop]]<<my.spring.test.prop,`+spring.test.prop+`>>"
|
||||||
|
+ NEWLINE + "|+++This is a description.+++" + NEWLINE + "|`+something+`" + NEWLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void noDefaultValue() {
|
||||||
|
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop", "java.lang.String", null,
|
||||||
|
"This is a description.", false);
|
||||||
|
SingleRow row = new SingleRow(SNIPPET, property);
|
||||||
|
Asciidoc asciidoc = new Asciidoc();
|
||||||
|
row.write(asciidoc);
|
||||||
|
assertThat(asciidoc.toString()).isEqualTo("|[[my.spring.test.prop]]<<my.spring.test.prop,`+spring.test.prop+`>>"
|
||||||
|
+ NEWLINE + "|+++This is a description.+++" + NEWLINE + "|" + NEWLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void defaultValueWithPipes() {
|
||||||
|
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop", "java.lang.String",
|
||||||
|
"first|second", "This is a description.", false);
|
||||||
|
SingleRow row = new SingleRow(SNIPPET, property);
|
||||||
|
Asciidoc asciidoc = new Asciidoc();
|
||||||
|
row.write(asciidoc);
|
||||||
|
assertThat(asciidoc.toString()).isEqualTo("|[[my.spring.test.prop]]<<my.spring.test.prop,`+spring.test.prop+`>>"
|
||||||
|
+ NEWLINE + "|+++This is a description.+++" + NEWLINE + "|`+first\\|second+`" + NEWLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void defaultValueWithBackslash() {
|
||||||
|
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop", "java.lang.String",
|
||||||
|
"first\\second", "This is a description.", false);
|
||||||
|
SingleRow row = new SingleRow(SNIPPET, property);
|
||||||
|
Asciidoc asciidoc = new Asciidoc();
|
||||||
|
row.write(asciidoc);
|
||||||
|
assertThat(asciidoc.toString()).isEqualTo("|[[my.spring.test.prop]]<<my.spring.test.prop,`+spring.test.prop+`>>"
|
||||||
|
+ NEWLINE + "|+++This is a description.+++" + NEWLINE + "|`+first\\\\second+`" + NEWLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void descriptionWithPipe() {
|
||||||
|
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop", "java.lang.String", null,
|
||||||
|
"This is a description with a | pipe.", false);
|
||||||
|
SingleRow row = new SingleRow(SNIPPET, property);
|
||||||
|
Asciidoc asciidoc = new Asciidoc();
|
||||||
|
row.write(asciidoc);
|
||||||
|
assertThat(asciidoc.toString()).isEqualTo("|[[my.spring.test.prop]]<<my.spring.test.prop,`+spring.test.prop+`>>"
|
||||||
|
+ NEWLINE + "|+++This is a description with a \\| pipe.+++" + NEWLINE + "|" + NEWLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void mapProperty() {
|
||||||
|
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop",
|
||||||
|
"java.util.Map<java.lang.String,java.lang.String>", null, "This is a description.", false);
|
||||||
|
SingleRow row = new SingleRow(SNIPPET, property);
|
||||||
|
Asciidoc asciidoc = new Asciidoc();
|
||||||
|
row.write(asciidoc);
|
||||||
|
assertThat(asciidoc.toString())
|
||||||
|
.isEqualTo("|[[my.spring.test.prop]]<<my.spring.test.prop,`+spring.test.prop.*+`>>" + NEWLINE
|
||||||
|
+ "|+++This is a description.+++" + NEWLINE + "|" + NEWLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void listProperty() {
|
||||||
|
String[] defaultValue = new String[] { "first", "second", "third" };
|
||||||
|
ConfigurationProperty property = new ConfigurationProperty("spring.test.prop",
|
||||||
|
"java.util.List<java.lang.String>", defaultValue, "This is a description.", false);
|
||||||
|
SingleRow row = new SingleRow(SNIPPET, property);
|
||||||
|
Asciidoc asciidoc = new Asciidoc();
|
||||||
|
row.write(asciidoc);
|
||||||
|
assertThat(asciidoc.toString()).isEqualTo("|[[my.spring.test.prop]]<<my.spring.test.prop,`+spring.test.prop+`>>"
|
||||||
|
+ NEWLINE + "|+++This is a description.+++" + NEWLINE + "|`+first," + NEWLINE + "second," + NEWLINE
|
||||||
|
+ "third+`" + NEWLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2021 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.boot.build.context.properties;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link Table}.
|
||||||
|
*
|
||||||
|
* @author Brian Clozel
|
||||||
|
*/
|
||||||
|
public class TableTests {
|
||||||
|
|
||||||
|
private static final String NEWLINE = System.lineSeparator();
|
||||||
|
|
||||||
|
private static final Snippet SNIPPET = new Snippet("my", "title", null);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void simpleTable() {
|
||||||
|
Table table = new Table();
|
||||||
|
table.addRow(new SingleRow(SNIPPET, new ConfigurationProperty("spring.test.prop", "java.lang.String",
|
||||||
|
"something", "This is a description.", false)));
|
||||||
|
table.addRow(new SingleRow(SNIPPET, new ConfigurationProperty("spring.test.other", "java.lang.String",
|
||||||
|
"other value", "This is another description.", false)));
|
||||||
|
Asciidoc asciidoc = new Asciidoc();
|
||||||
|
table.write(asciidoc);
|
||||||
|
// @formatter:off
|
||||||
|
assertThat(asciidoc.toString()).isEqualTo(
|
||||||
|
"[cols=\"4,3,3\", options=\"header\"]" + NEWLINE +
|
||||||
|
"|===" + NEWLINE +
|
||||||
|
"|Name|Description|Default Value" + NEWLINE + NEWLINE +
|
||||||
|
"|[[my.spring.test.other]]<<my.spring.test.other,`+spring.test.other+`>>" + NEWLINE +
|
||||||
|
"|+++This is another description.+++" + NEWLINE +
|
||||||
|
"|`+other value+`" + NEWLINE + NEWLINE +
|
||||||
|
"|[[my.spring.test.prop]]<<my.spring.test.prop,`+spring.test.prop+`>>" + NEWLINE +
|
||||||
|
"|+++This is a description.+++" + NEWLINE +
|
||||||
|
"|`+something+`" + NEWLINE + NEWLINE +
|
||||||
|
"|===" + NEWLINE);
|
||||||
|
// @formatter:on
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.actuator]]
|
|
||||||
== Actuator Properties [[actuator-properties]]
|
|
||||||
include::documented-application-properties/actuator.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.cache]]
|
|
||||||
== Cache Properties [[cache-properties]]
|
|
||||||
include::documented-application-properties/cache.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.core]]
|
|
||||||
== Core Properties [[core-properties]]
|
|
||||||
include::documented-application-properties/core.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.data-migration]]
|
|
||||||
== Data Migration Properties [[data-migration-properties]]
|
|
||||||
include::documented-application-properties/data-migration.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.data]]
|
|
||||||
== Data Properties [[data-properties]]
|
|
||||||
include::documented-application-properties/data.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.devtools]]
|
|
||||||
== Devtools Properties [[devtools-properties]]
|
|
||||||
include::documented-application-properties/devtools.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.integration]]
|
|
||||||
== Integration Properties [[integration-properties]]
|
|
||||||
include::documented-application-properties/integration.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.json]]
|
|
||||||
== JSON Properties [[json-properties]]
|
|
||||||
include::documented-application-properties/json.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.mail]]
|
|
||||||
== Mail Properties [[mail-properties]]
|
|
||||||
include::documented-application-properties/mail.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.rsocket]]
|
|
||||||
== RSocket Properties [[rsocket-properties]]
|
|
||||||
include::documented-application-properties/rsocket.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.security]]
|
|
||||||
== Security Properties [[security-properties]]
|
|
||||||
include::documented-application-properties/security.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.server]]
|
|
||||||
== Server Properties [[server-properties]]
|
|
||||||
include::documented-application-properties/server.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.templating]]
|
|
||||||
== Templating Properties [[templating-properties]]
|
|
||||||
include::documented-application-properties/templating.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.testing]]
|
|
||||||
== Testing Properties [[testing-properties]]
|
|
||||||
include::documented-application-properties/testing.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.transaction]]
|
|
||||||
== Transaction Properties [[transaction-properties]]
|
|
||||||
include::documented-application-properties/transaction.adoc[]
|
|
@ -1,3 +0,0 @@
|
|||||||
[[application-properties.web]]
|
|
||||||
== Web Properties [[web-properties]]
|
|
||||||
include::documented-application-properties/web.adoc[]
|
|
Loading…
Reference in New Issue