Skip to content

Commit 663cbdd

Browse files
YangSiJun528mhalbritter
authored andcommitted
Handle ConfigurationFileFormat in description copy and diff
The ConfigurationFileFormat introduced in gh-1682 is not handled in the MutableProjectDescription copy constructor or in ProjectDescriptionDiff. This commit adds the missing logic and corresponding tests. See gh-1693 Signed-off-by: sijun-yang <yangsijun5528@gmail.com>
1 parent 485c315 commit 663cbdd

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

initializr-generator/src/main/java/io/spring/initializr/generator/project/MutableProjectDescription.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ protected MutableProjectDescription(MutableProjectDescription source) {
7979
this.buildSystem = source.getBuildSystem();
8080
this.packaging = source.getPackaging();
8181
this.language = source.getLanguage();
82+
this.configurationFileFormat = source.getConfigurationFileFormat();
8283
this.requestedDependencies.putAll(source.getRequestedDependencies());
8384
this.groupId = source.getGroupId();
8485
this.artifactId = source.getArtifactId();

initializr-generator/src/main/java/io/spring/initializr/generator/project/ProjectDescriptionDiff.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.function.BiConsumer;
2121

2222
import io.spring.initializr.generator.buildsystem.BuildSystem;
23+
import io.spring.initializr.generator.configuration.format.ConfigurationFileFormat;
2324
import io.spring.initializr.generator.language.Language;
2425
import io.spring.initializr.generator.packaging.Packaging;
2526
import io.spring.initializr.generator.version.Version;
@@ -100,6 +101,19 @@ public void ifLanguageChanged(ProjectDescription current, BiConsumer<Language, L
100101
}
101102
}
102103

104+
/**
105+
* Calls the specified consumer if the {@code configurationFileFormat} is different on
106+
* the original source project description than the specified project description.
107+
* @param current the description to test against
108+
* @param consumer to call if the property has changed
109+
*/
110+
public void ifConfigurationFileFormatChanged(ProjectDescription current,
111+
BiConsumer<ConfigurationFileFormat, ConfigurationFileFormat> consumer) {
112+
if (!Objects.equals(this.original.getConfigurationFileFormat(), current.getConfigurationFileFormat())) {
113+
consumer.accept(this.original.getConfigurationFileFormat(), current.getConfigurationFileFormat());
114+
}
115+
}
116+
103117
/**
104118
* Calls the specified consumer if the {@code groupId} is different on the original
105119
* source project description than the specified project description.

initializr-generator/src/test/java/io/spring/initializr/generator/project/ProjectDescriptionDiffTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import io.spring.initializr.generator.buildsystem.BuildSystem;
2323
import io.spring.initializr.generator.buildsystem.gradle.GradleBuildSystem;
2424
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
25+
import io.spring.initializr.generator.configuration.format.ConfigurationFileFormat;
26+
import io.spring.initializr.generator.configuration.format.properties.PropertiesFormat;
27+
import io.spring.initializr.generator.configuration.format.yaml.YamlFormat;
2528
import io.spring.initializr.generator.language.Language;
2629
import io.spring.initializr.generator.language.java.JavaLanguage;
2730
import io.spring.initializr.generator.packaging.Packaging;
@@ -58,6 +61,8 @@ void projectDescriptionDiffWithUnmodifiedDescriptionDoesNotInvokeConsumer() {
5861
diff.ifBuildSystemChanged(description, (original, actual) -> fail("Values should not have changed"));
5962
diff.ifPackagingChanged(description, (original, actual) -> fail("Values should not have changed"));
6063
diff.ifLanguageChanged(description, (original, actual) -> fail("Values should not have changed"));
64+
diff.ifConfigurationFileFormatChanged(description,
65+
(original, actual) -> fail("Values should not have changed"));
6166
diff.ifGroupIdChanged(description, (original, actual) -> fail("Values should not have changed"));
6267
diff.ifArtifactIdChanged(description, (original, actual) -> fail("Values should not have changed"));
6368
diff.ifVersionChanged(description, (original, actual) -> fail("Values should not have changed"));
@@ -112,6 +117,17 @@ void projectDescriptionDiffWithModifiedLanguageInvokesConsumer() {
112117
validateConsumer(original, actual, (consumer) -> diff.ifLanguageChanged(description, consumer));
113118
}
114119

120+
@Test
121+
void projectDescriptionDiffWithModifiedConfigurationFileFormatInvokesConsumer() {
122+
ConfigurationFileFormat original = ConfigurationFileFormat.forId(YamlFormat.ID);
123+
ConfigurationFileFormat actual = ConfigurationFileFormat.forId(PropertiesFormat.ID);
124+
MutableProjectDescription description = new MutableProjectDescription();
125+
description.setConfigurationFileFormat(original);
126+
ProjectDescriptionDiff diff = new ProjectDescriptionDiff(description);
127+
description.setConfigurationFileFormat(actual);
128+
validateConsumer(original, actual, (consumer) -> diff.ifConfigurationFileFormatChanged(description, consumer));
129+
}
130+
115131
@Test
116132
void projectDescriptionDiffWithModifiedGroupIdInvokesConsumer() {
117133
String original = "com.example";

0 commit comments

Comments
 (0)