From 711bee68e278743848cb6aa83cf52c1f6379a835 Mon Sep 17 00:00:00 2001 From: kerwin612 Date: Fri, 28 Jul 2023 10:30:38 +0800 Subject: [PATCH] Enforced order of collections in generated json file - 'profiles' are sorted in alphabetical order - 'sourceTypes' are sorted with custom comparator - minor code style changes --- .../aggregation/AggregationBuilder.java | 19 ++++++++++++------- .../model/AggregatedPropertyMetadata.java | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/spring-configuration-aggregator-maven-plugin/src/main/java/com/github/egoettelmann/spring/configuration/extensions/aggregator/maven/components/aggregation/AggregationBuilder.java b/spring-configuration-aggregator-maven-plugin/src/main/java/com/github/egoettelmann/spring/configuration/extensions/aggregator/maven/components/aggregation/AggregationBuilder.java index fde36d3..2721a38 100644 --- a/spring-configuration-aggregator-maven-plugin/src/main/java/com/github/egoettelmann/spring/configuration/extensions/aggregator/maven/components/aggregation/AggregationBuilder.java +++ b/spring-configuration-aggregator-maven-plugin/src/main/java/com/github/egoettelmann/spring/configuration/extensions/aggregator/maven/components/aggregation/AggregationBuilder.java @@ -83,27 +83,32 @@ private AggregatedPropertyMetadata create(final PropertyMetadata property, final final AggregatedPropertyMetadata aggregate = new AggregatedPropertyMetadata(); aggregate.setName(property.getName()); aggregate.setDefaultValue(property.getDefaultValue()); - // If a default value is defined, it overrides the already defined one + aggregate.setType(property.getType()); + aggregate.setDescription(property.getDescription()); + + // Adding profile specific default values for (final Map.Entry entry : this.defaultValues.entrySet()) { final String profile = entry.getKey(); final Properties profileProperties = entry.getValue(); - this.log.debug("Found " + profileProperties.size() + " values for profile " + profile); - if (!profileProperties.containsKey(property.getName())) { continue; } + this.log.debug("Found " + profileProperties.size() + " values for profile " + profile); + + // Value from 'default' profile overrides default value defined in annotation if (DefaultAggregationService.DEFAULT_PROFILE.equals(profile)) { aggregate.setDefaultValue(profileProperties.getProperty(property.getName())); continue; } + + // Adding profile specific default value if (aggregate.getProfiles() == null) { - aggregate.setProfiles(new HashMap<>()); + aggregate.setProfiles(new TreeMap<>()); } aggregate.getProfiles().put(profile, profileProperties.getProperty(property.getName())); } - aggregate.setType(property.getType()); - aggregate.setDescription(property.getDescription()); - aggregate.setSourceTypes(new ArrayList<>()); + + aggregate.setSourceTypes(new TreeSet<>()); aggregate.getSourceTypes().add(this.create(property.getSourceType(), groupId, artifactId)); return aggregate; } diff --git a/spring-configuration-aggregator-maven-plugin/src/main/java/com/github/egoettelmann/spring/configuration/extensions/aggregator/maven/core/model/AggregatedPropertyMetadata.java b/spring-configuration-aggregator-maven-plugin/src/main/java/com/github/egoettelmann/spring/configuration/extensions/aggregator/maven/core/model/AggregatedPropertyMetadata.java index 8e2e2db..c941912 100644 --- a/spring-configuration-aggregator-maven-plugin/src/main/java/com/github/egoettelmann/spring/configuration/extensions/aggregator/maven/core/model/AggregatedPropertyMetadata.java +++ b/spring-configuration-aggregator-maven-plugin/src/main/java/com/github/egoettelmann/spring/configuration/extensions/aggregator/maven/core/model/AggregatedPropertyMetadata.java @@ -2,8 +2,10 @@ import lombok.Data; +import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Set; @Data public class AggregatedPropertyMetadata { @@ -13,7 +15,7 @@ public class AggregatedPropertyMetadata { private String description; private String defaultValue; private Map profiles; - private List sourceTypes; + private Set sourceTypes; @Data public static class Wrapper { @@ -21,10 +23,18 @@ public static class Wrapper { } @Data - public static class Source { + public static class Source implements Comparable { private String groupId; private String artifactId; private String sourceType; + + @Override + public int compareTo(final Source o) { + return Comparator.comparing(Source::getGroupId) + .thenComparing(Source::getArtifactId) + .thenComparing(Source::getSourceType) + .compare(this, o); + } } }