34 changed files with 512 additions and 446 deletions
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
/* |
||||
* Copyright 2012-2019 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.configurationdocs; |
||||
|
||||
/** |
||||
* Simple builder to help construct Asciidoc markup. |
||||
* |
||||
* @author Phillip Webb |
||||
*/ |
||||
class AsciidocBuilder { |
||||
|
||||
private static final String NEWLINE = System.lineSeparator(); |
||||
|
||||
private final StringBuilder content; |
||||
|
||||
AsciidocBuilder() { |
||||
this.content = new StringBuilder(); |
||||
} |
||||
|
||||
public AsciidocBuilder appendln(Object... items) { |
||||
append(items); |
||||
append(NEWLINE); |
||||
return this; |
||||
} |
||||
|
||||
public AsciidocBuilder append(Object... items) { |
||||
for (Object item : items) { |
||||
this.content.append(item); |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return this.content.toString(); |
||||
} |
||||
|
||||
} |
||||
17
spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/CompoundKeyEntry.java → spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/CompoundConfigurationTableEntry.java
17
spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/CompoundKeyEntry.java → spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/CompoundConfigurationTableEntry.java
23
spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/AbstractConfigurationEntry.java → spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/ConfigurationTableEntry.java
23
spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/AbstractConfigurationEntry.java → spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/ConfigurationTableEntry.java
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
/* |
||||
* Copyright 2012-2019 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.configurationdocs; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty; |
||||
|
||||
/** |
||||
* Table entry containing a single configuration property. |
||||
* |
||||
* @author Brian Clozel |
||||
*/ |
||||
class SingleConfigurationTableEntry extends ConfigurationTableEntry { |
||||
|
||||
private final String description; |
||||
|
||||
private final String defaultValue; |
||||
|
||||
SingleConfigurationTableEntry(ConfigurationMetadataProperty property) { |
||||
this.key = property.getId(); |
||||
if (property.getType() != null |
||||
&& property.getType().startsWith("java.util.Map")) { |
||||
this.key += ".*"; |
||||
} |
||||
this.description = property.getDescription(); |
||||
this.defaultValue = getDefaultValue(property.getDefaultValue()); |
||||
} |
||||
|
||||
private String getDefaultValue(Object defaultValue) { |
||||
if (defaultValue == null) { |
||||
return null; |
||||
} |
||||
if (defaultValue.getClass().isArray()) { |
||||
return Arrays.stream((Object[]) defaultValue).map(Object::toString) |
||||
.collect(Collectors.joining("," + System.lineSeparator())); |
||||
} |
||||
return defaultValue.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public void write(AsciidocBuilder builder) { |
||||
builder.appendln("|`+", this.key, "+`"); |
||||
writeDefaultValue(builder); |
||||
writeDescription(builder); |
||||
builder.appendln(); |
||||
} |
||||
|
||||
private void writeDefaultValue(AsciidocBuilder builder) { |
||||
String defaultValue = (this.defaultValue != null) ? this.defaultValue : ""; |
||||
defaultValue = defaultValue.replace("\\", "\\\\").replace("|", |
||||
"{vbar}" + System.lineSeparator()); |
||||
if (defaultValue.isEmpty()) { |
||||
builder.appendln("|"); |
||||
} |
||||
else { |
||||
builder.appendln("|`+", defaultValue, "+`"); |
||||
} |
||||
} |
||||
|
||||
private void writeDescription(AsciidocBuilder builder) { |
||||
if (this.description == null || this.description.isEmpty()) { |
||||
builder.append("|"); |
||||
} |
||||
else { |
||||
builder.append("|+++", this.description, "+++"); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -1,83 +0,0 @@
@@ -1,83 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2019 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.configurationdocs; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty; |
||||
|
||||
/** |
||||
* Table entry containing a single configuration property. |
||||
* |
||||
* @author Brian Clozel |
||||
*/ |
||||
class SingleKeyEntry extends AbstractConfigurationEntry { |
||||
|
||||
private String defaultValue; |
||||
|
||||
private String description; |
||||
|
||||
SingleKeyEntry(ConfigurationMetadataProperty property) { |
||||
|
||||
this.key = property.getId(); |
||||
if (property.getType() != null |
||||
&& property.getType().startsWith("java.util.Map")) { |
||||
this.key += ".*"; |
||||
} |
||||
|
||||
this.description = property.getDescription(); |
||||
|
||||
if (property.getDefaultValue() != null) { |
||||
if (property.getDefaultValue().getClass().isArray()) { |
||||
this.defaultValue = Arrays.stream((Object[]) property.getDefaultValue()) |
||||
.map(Object::toString).collect(Collectors.joining("," + NEWLINE)); |
||||
} |
||||
else { |
||||
this.defaultValue = property.getDefaultValue().toString(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void writeAsciidoc(StringBuilder builder) { |
||||
builder.append("|`+").append(this.key).append("+`").append(NEWLINE); |
||||
String defaultValue = processDefaultValue(); |
||||
if (!defaultValue.isEmpty()) { |
||||
builder.append("|`+").append(defaultValue).append("+`").append(NEWLINE); |
||||
} |
||||
else { |
||||
builder.append("|").append(NEWLINE); |
||||
} |
||||
if (this.description != null) { |
||||
builder.append("|+++").append(this.description).append("+++"); |
||||
} |
||||
else { |
||||
builder.append("|"); |
||||
} |
||||
builder.append(NEWLINE); |
||||
} |
||||
|
||||
private String processDefaultValue() { |
||||
if (this.defaultValue != null && !this.defaultValue.isEmpty()) { |
||||
return this.defaultValue.replace("\\", "\\\\").replace("|", |
||||
"{vbar}" + NEWLINE); |
||||
} |
||||
return ""; |
||||
} |
||||
|
||||
} |
||||
16
spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/CompoundKeyEntryTests.java → spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/CompoundConfigurationTableEntryTests.java
16
spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/CompoundKeyEntryTests.java → spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/CompoundConfigurationTableEntryTests.java
52
spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/SingleKeyEntryTests.java → spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntryTests.java
52
spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/SingleKeyEntryTests.java → spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntryTests.java
Loading…
Reference in new issue