|
|
|
@ -14,7 +14,7 @@ |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.legacyproperties; |
|
|
|
package org.springframework.boot.context.properties.migrator; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
@ -28,21 +28,21 @@ import org.springframework.boot.configurationmetadata.ConfigurationMetadataPrope |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Provides a legacy properties report. |
|
|
|
* Provides a properties migration report. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Stephane Nicoll |
|
|
|
* @author Stephane Nicoll |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class LegacyPropertiesReport { |
|
|
|
class PropertiesMigrationReport { |
|
|
|
|
|
|
|
|
|
|
|
private final Map<String, LegacyProperties> content = new LinkedHashMap<>(); |
|
|
|
private final Map<String, LegacyProperties> content = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return a report for all the legacy properties that were automatically renamed. If |
|
|
|
* Return a report for all the properties that were automatically renamed. If no such |
|
|
|
* no such legacy properties were found, return {@code null}. |
|
|
|
* properties were found, return {@code null}. |
|
|
|
* @return a report with the configurations keys that should be renamed |
|
|
|
* @return a report with the configurations keys that should be renamed |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String getWarningReport() { |
|
|
|
public String getWarningReport() { |
|
|
|
Map<String, List<LegacyProperty>> content = getContent( |
|
|
|
Map<String, List<PropertyMigration>> content = getContent( |
|
|
|
LegacyProperties::getRenamed); |
|
|
|
LegacyProperties::getRenamed); |
|
|
|
if (content.isEmpty()) { |
|
|
|
if (content.isEmpty()) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
@ -61,12 +61,12 @@ class LegacyPropertiesReport { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return a report for all the legacy properties that are no longer supported. If no |
|
|
|
* Return a report for all the properties that are no longer supported. If no such |
|
|
|
* such legacy properties were found, return {@code null}. |
|
|
|
* properties were found, return {@code null}. |
|
|
|
* @return a report with the configurations keys that are no longer supported |
|
|
|
* @return a report with the configurations keys that are no longer supported |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String getErrorReport() { |
|
|
|
public String getErrorReport() { |
|
|
|
Map<String, List<LegacyProperty>> content = getContent( |
|
|
|
Map<String, List<PropertyMigration>> content = getContent( |
|
|
|
LegacyProperties::getUnsupported); |
|
|
|
LegacyProperties::getUnsupported); |
|
|
|
if (content.isEmpty()) { |
|
|
|
if (content.isEmpty()) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
@ -85,8 +85,8 @@ class LegacyPropertiesReport { |
|
|
|
return report.toString(); |
|
|
|
return report.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Map<String, List<LegacyProperty>> getContent( |
|
|
|
private Map<String, List<PropertyMigration>> getContent( |
|
|
|
Function<LegacyProperties, List<LegacyProperty>> extractor) { |
|
|
|
Function<LegacyProperties, List<PropertyMigration>> extractor) { |
|
|
|
return this.content.entrySet().stream() |
|
|
|
return this.content.entrySet().stream() |
|
|
|
.filter((entry) -> !extractor.apply(entry.getValue()).isEmpty()) |
|
|
|
.filter((entry) -> !extractor.apply(entry.getValue()).isEmpty()) |
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, |
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, |
|
|
|
@ -94,11 +94,11 @@ class LegacyPropertiesReport { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void append(StringBuilder report, |
|
|
|
private void append(StringBuilder report, |
|
|
|
Map<String, List<LegacyProperty>> content, |
|
|
|
Map<String, List<PropertyMigration>> content, |
|
|
|
Function<ConfigurationMetadataProperty, String> deprecationMessage) { |
|
|
|
Function<ConfigurationMetadataProperty, String> deprecationMessage) { |
|
|
|
content.forEach((name, properties) -> { |
|
|
|
content.forEach((name, properties) -> { |
|
|
|
report.append(String.format("Property source '%s':%n", name)); |
|
|
|
report.append(String.format("Property source '%s':%n", name)); |
|
|
|
properties.sort(LegacyProperty.COMPARATOR); |
|
|
|
properties.sort(PropertyMigration.COMPARATOR); |
|
|
|
properties.forEach((property) -> { |
|
|
|
properties.forEach((property) -> { |
|
|
|
ConfigurationMetadataProperty metadata = property.getMetadata(); |
|
|
|
ConfigurationMetadataProperty metadata = property.getMetadata(); |
|
|
|
report.append(String.format("\tKey: %s%n", metadata.getId())); |
|
|
|
report.append(String.format("\tKey: %s%n", metadata.getId())); |
|
|
|
@ -119,19 +119,19 @@ class LegacyPropertiesReport { |
|
|
|
* @param renamed the properties that were renamed |
|
|
|
* @param renamed the properties that were renamed |
|
|
|
* @param unsupported the properties that are no longer supported |
|
|
|
* @param unsupported the properties that are no longer supported |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void add(String name, List<LegacyProperty> renamed, |
|
|
|
void add(String name, List<PropertyMigration> renamed, |
|
|
|
List<LegacyProperty> unsupported) { |
|
|
|
List<PropertyMigration> unsupported) { |
|
|
|
this.content.put(name, new LegacyProperties(renamed, unsupported)); |
|
|
|
this.content.put(name, new LegacyProperties(renamed, unsupported)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static class LegacyProperties { |
|
|
|
private static class LegacyProperties { |
|
|
|
|
|
|
|
|
|
|
|
private final List<LegacyProperty> renamed; |
|
|
|
private final List<PropertyMigration> renamed; |
|
|
|
|
|
|
|
|
|
|
|
private final List<LegacyProperty> unsupported; |
|
|
|
private final List<PropertyMigration> unsupported; |
|
|
|
|
|
|
|
|
|
|
|
LegacyProperties(List<LegacyProperty> renamed, |
|
|
|
LegacyProperties(List<PropertyMigration> renamed, |
|
|
|
List<LegacyProperty> unsupported) { |
|
|
|
List<PropertyMigration> unsupported) { |
|
|
|
this.renamed = asNewList(renamed); |
|
|
|
this.renamed = asNewList(renamed); |
|
|
|
this.unsupported = asNewList(unsupported); |
|
|
|
this.unsupported = asNewList(unsupported); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -140,11 +140,11 @@ class LegacyPropertiesReport { |
|
|
|
return (source == null ? Collections.emptyList() : new ArrayList<>(source)); |
|
|
|
return (source == null ? Collections.emptyList() : new ArrayList<>(source)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<LegacyProperty> getRenamed() { |
|
|
|
public List<PropertyMigration> getRenamed() { |
|
|
|
return this.renamed; |
|
|
|
return this.renamed; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<LegacyProperty> getUnsupported() { |
|
|
|
public List<PropertyMigration> getUnsupported() { |
|
|
|
return this.unsupported; |
|
|
|
return this.unsupported; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|