Skip to content

Commit 34b288e

Browse files
committed
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-26375
1 parent 86a5c90 commit 34b288e

40 files changed

+796
-674
lines changed

buildSrc/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies {
2828
testImplementation("org.assertj:assertj-core:3.11.1")
2929
testImplementation("org.apache.logging.log4j:log4j-core:2.12.1")
3030
testImplementation("org.junit.jupiter:junit-jupiter:5.6.0")
31+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
3132
}
3233

3334
checkstyle {
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,36 +21,36 @@
2121
*
2222
* @author Phillip Webb
2323
*/
24-
class AsciidocBuilder {
24+
class Asciidoc {
2525

2626
private final StringBuilder content;
2727

28-
AsciidocBuilder() {
28+
Asciidoc() {
2929
this.content = new StringBuilder();
3030
}
3131

32-
AsciidocBuilder appendKey(Object... items) {
32+
Asciidoc appendWithHardLineBreaks(Object... items) {
3333
for (Object item : items) {
3434
appendln("`+", item, "+` +");
3535
}
3636
return this;
3737
}
3838

39-
AsciidocBuilder newLine() {
40-
return append(System.lineSeparator());
41-
}
42-
43-
AsciidocBuilder appendln(Object... items) {
39+
Asciidoc appendln(Object... items) {
4440
return append(items).newLine();
4541
}
4642

47-
AsciidocBuilder append(Object... items) {
43+
Asciidoc append(Object... items) {
4844
for (Object item : items) {
4945
this.content.append(item);
5046
}
5147
return this;
5248
}
5349

50+
Asciidoc newLine() {
51+
return append(System.lineSeparator());
52+
}
53+
5454
@Override
5555
public String toString() {
5656
return this.content.toString();

buildSrc/src/main/java/org/springframework/boot/build/context/properties/CompoundConfigurationTableEntry.java

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2012-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.context.properties;
18+
19+
import java.util.Set;
20+
import java.util.TreeSet;
21+
22+
/**
23+
* Table row regrouping a list of configuration properties sharing the same description.
24+
*
25+
* @author Brian Clozel
26+
* @author Phillip Webb
27+
*/
28+
class CompoundRow extends Row {
29+
30+
private final Set<String> propertyNames;
31+
32+
private final String description;
33+
34+
CompoundRow(Snippet snippet, String prefix, String description) {
35+
super(snippet, prefix);
36+
this.description = description;
37+
this.propertyNames = new TreeSet<>();
38+
}
39+
40+
void addProperty(ConfigurationProperty property) {
41+
this.propertyNames.add(property.getDisplayName());
42+
}
43+
44+
@Override
45+
void write(Asciidoc asciidoc) {
46+
asciidoc.append("|");
47+
asciidoc.append("[[" + getAnchor() + "]]");
48+
asciidoc.append("<<" + getAnchor() + ",");
49+
this.propertyNames.forEach(asciidoc::appendWithHardLineBreaks);
50+
asciidoc.appendln(">>");
51+
asciidoc.appendln("|+++", this.description, "+++");
52+
asciidoc.appendln("|");
53+
}
54+
55+
}

buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationMetadataDocumentWriter.java

Lines changed: 0 additions & 125 deletions
This file was deleted.

buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationProperties.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
package org.springframework.boot.build.context.properties;
1818

1919
import java.io.File;
20-
import java.io.FileReader;
2120
import java.io.IOException;
22-
import java.io.Reader;
2321
import java.util.ArrayList;
22+
import java.util.Collections;
23+
import java.util.LinkedHashMap;
2424
import java.util.List;
2525
import java.util.Map;
26-
import java.util.function.Function;
27-
import java.util.stream.Collectors;
26+
import java.util.stream.Stream;
2827

2928
import com.fasterxml.jackson.databind.ObjectMapper;
3029

@@ -33,35 +32,40 @@
3332
* {@code META-INF/spring-configuration-metadata.json} files.
3433
*
3534
* @author Andy Wilkinson
35+
* @author Phillip Webb
3636
*/
3737
final class ConfigurationProperties {
3838

39-
private ConfigurationProperties() {
39+
private final Map<String, ConfigurationProperty> byName;
4040

41+
private ConfigurationProperties(List<ConfigurationProperty> properties) {
42+
Map<String, ConfigurationProperty> byName = new LinkedHashMap<>();
43+
for (ConfigurationProperty property : properties) {
44+
byName.put(property.getName(), property);
45+
}
46+
this.byName = Collections.unmodifiableMap(byName);
47+
}
48+
49+
ConfigurationProperty get(String propertyName) {
50+
return this.byName.get(propertyName);
51+
}
52+
53+
Stream<ConfigurationProperty> stream() {
54+
return this.byName.values().stream();
4155
}
4256

4357
@SuppressWarnings("unchecked")
44-
static Map<String, ConfigurationProperty> fromFiles(Iterable<File> files) {
45-
List<ConfigurationProperty> configurationProperties = new ArrayList<>();
58+
static ConfigurationProperties fromFiles(Iterable<File> files) {
4659
try {
4760
ObjectMapper objectMapper = new ObjectMapper();
61+
List<ConfigurationProperty> properties = new ArrayList<>();
4862
for (File file : files) {
49-
try (Reader reader = new FileReader(file)) {
50-
Map<String, Object> json = objectMapper.readValue(file, Map.class);
51-
List<Map<String, Object>> properties = (List<Map<String, Object>>) json.get("properties");
52-
for (Map<String, Object> property : properties) {
53-
String name = (String) property.get("name");
54-
String type = (String) property.get("type");
55-
Object defaultValue = property.get("defaultValue");
56-
String description = (String) property.get("description");
57-
boolean deprecated = property.containsKey("deprecated");
58-
configurationProperties
59-
.add(new ConfigurationProperty(name, type, defaultValue, description, deprecated));
60-
}
63+
Map<String, Object> json = objectMapper.readValue(file, Map.class);
64+
for (Map<String, Object> property : (List<Map<String, Object>>) json.get("properties")) {
65+
properties.add(ConfigurationProperty.fromJsonProperties(property));
6166
}
6267
}
63-
return configurationProperties.stream()
64-
.collect(Collectors.toMap(ConfigurationProperty::getName, Function.identity()));
68+
return new ConfigurationProperties(properties);
6569
}
6670
catch (IOException ex) {
6771
throw new RuntimeException("Failed to load configuration metadata", ex);

0 commit comments

Comments
 (0)