From 17d5995639247cad8b17cb7db13ecec630c2dacd Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 02:47:49 +0900 Subject: [PATCH 01/24] Add comments of code analysis --- .../spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java | 3 +++ .../main/java/io/spring/initializr/metadata/Dependency.java | 1 + 2 files changed, 4 insertions(+) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java index db12fe04eb..fe4b2395d7 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java @@ -29,6 +29,7 @@ * * @author Madhura Bhave */ +// BuildCustomizer 구현체를 보니 Kotlin + JPA 관련 객체가 이미 있음. public class KotlinJpaGradleBuildCustomizer implements BuildCustomizer { private final BuildMetadataResolver buildMetadataResolver; @@ -43,9 +44,11 @@ public KotlinJpaGradleBuildCustomizer(InitializrMetadata metadata, KotlinProject @Override public void customize(GradleBuild build) { + // jpa가 있을때, 특정 조건 추가 if (this.buildMetadataResolver.hasFacet(build, "jpa")) { build.plugins() .add("org.jetbrains.kotlin.plugin.jpa", (plugin) -> plugin.setVersion(this.settings.getVersion())); + //TODO jakarta or javax 일 때, 알맞은 구성 추가 } } diff --git a/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java b/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java index 16a1c87e3d..a6cbff753c 100644 --- a/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java +++ b/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java @@ -123,6 +123,7 @@ public class Dependency extends MetadataElement implements Describable { public Dependency() { } + //groupId로 jakarta 또는 javax 사용 여부를 확인할 수 있을 것 같음. public Dependency(Dependency dependency) { super(dependency); this.aliases.addAll(dependency.aliases); From a83a718c708a6dc6c29f3a0513ac8b1b68e8598b Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 02:53:02 +0900 Subject: [PATCH 02/24] Update KotlinJpaGradleBuildCustomizer.java --- .../KotlinJpaGradleBuildCustomizer.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java index fe4b2395d7..de2a16be70 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java @@ -48,8 +48,29 @@ public void customize(GradleBuild build) { if (this.buildMetadataResolver.hasFacet(build, "jpa")) { build.plugins() .add("org.jetbrains.kotlin.plugin.jpa", (plugin) -> plugin.setVersion(this.settings.getVersion())); - //TODO jakarta or javax 일 때, 알맞은 구성 추가 + if(this.buildMetadataResolver.dependencies(build).anyMatch(a -> a.getGroupId().equals("javax.persistence"))) { + customizeAllOpenJPA_TEMP_jakarta(build); + } else if(this.buildMetadataResolver.dependencies(build).anyMatch(a -> a.getGroupId().equals("jakarta.persistence"))) { + customizeAllOpenJPA_TEMP_javax(build); + } } } + private void customizeAllOpenJPA_TEMP_jakarta(GradleBuild build) { + build.extensions().customize("allOpen", (allOpen) -> { + allOpen.invoke("annotation", "jakarta.persistence.Entity"); + allOpen.invoke("annotation", "jakarta.persistence.MappedSuperclass"); + allOpen.invoke("annotation", "jakarta.persistence.Embeddable"); + }); + } + + private void customizeAllOpenJPA_TEMP_javax(GradleBuild build) { + build.extensions().customize("allOpen", (allOpen) -> { + allOpen.invoke("annotation", "javax.persistence.Entity"); + allOpen.invoke("annotation", "javax.persistence.MappedSuperclass"); + allOpen.invoke("annotation", "javax.persistence.Embeddable"); + }); + } + + } From f17b215e6c4f46a628cb1518ea3c7520c7c98e4b Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 03:26:15 +0900 Subject: [PATCH 03/24] Add hasGroupId method --- .../generator/spring/build/BuildMetadataResolver.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/BuildMetadataResolver.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/BuildMetadataResolver.java index 38660f6dfa..68a20e3be0 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/BuildMetadataResolver.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/BuildMetadataResolver.java @@ -65,4 +65,14 @@ public boolean hasFacet(Build build, String facet) { return dependencies(build).anyMatch((dependency) -> dependency.getFacets().contains(facet)); } + /** + * Checks if the given {@link Build} contains dependencies with the given {@code groupId}. + * @param build the build to query + * @param groupId the groupId to query + * @return {@code true} if this build defines at least a dependency with that groupId, {@code false} otherwise + */ + public boolean hasGroupId(Build build, String groupId) { + return dependencies(build).anyMatch((dependency) -> dependency.getGroupId().equals(groupId)); + } + } From b4b8ab485e65b56de168e9a92397213751d1082b Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 03:29:16 +0900 Subject: [PATCH 04/24] Refactor to use hasGroupId --- .../spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java index de2a16be70..bc3af9d4aa 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java @@ -48,9 +48,10 @@ public void customize(GradleBuild build) { if (this.buildMetadataResolver.hasFacet(build, "jpa")) { build.plugins() .add("org.jetbrains.kotlin.plugin.jpa", (plugin) -> plugin.setVersion(this.settings.getVersion())); - if(this.buildMetadataResolver.dependencies(build).anyMatch(a -> a.getGroupId().equals("javax.persistence"))) { + if (this.buildMetadataResolver.hasGroupId(build, "jakarta.persistence")) { customizeAllOpenJPA_TEMP_jakarta(build); - } else if(this.buildMetadataResolver.dependencies(build).anyMatch(a -> a.getGroupId().equals("jakarta.persistence"))) { + } + else if (this.buildMetadataResolver.hasGroupId(build, "javax.persistence")) { customizeAllOpenJPA_TEMP_javax(build); } } @@ -72,5 +73,4 @@ private void customizeAllOpenJPA_TEMP_javax(GradleBuild build) { }); } - } From 0fad95518e7132f973dd84722b0155a57c7bbf2b Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 04:13:16 +0900 Subject: [PATCH 05/24] Refactor KotlinJpaGradleBuildCustomizer - Rename methods - Simplify allOpen.invoke --- .../KotlinJpaGradleBuildCustomizer.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java index bc3af9d4aa..d90db93605 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java @@ -44,32 +44,29 @@ public KotlinJpaGradleBuildCustomizer(InitializrMetadata metadata, KotlinProject @Override public void customize(GradleBuild build) { - // jpa가 있을때, 특정 조건 추가 if (this.buildMetadataResolver.hasFacet(build, "jpa")) { build.plugins() .add("org.jetbrains.kotlin.plugin.jpa", (plugin) -> plugin.setVersion(this.settings.getVersion())); if (this.buildMetadataResolver.hasGroupId(build, "jakarta.persistence")) { - customizeAllOpenJPA_TEMP_jakarta(build); + customizeAllOpenWithJakarta(build); } else if (this.buildMetadataResolver.hasGroupId(build, "javax.persistence")) { - customizeAllOpenJPA_TEMP_javax(build); + customizeAllOpenWithJavax(build); } } } - private void customizeAllOpenJPA_TEMP_jakarta(GradleBuild build) { + private void customizeAllOpenWithJakarta(GradleBuild build) { build.extensions().customize("allOpen", (allOpen) -> { - allOpen.invoke("annotation", "jakarta.persistence.Entity"); - allOpen.invoke("annotation", "jakarta.persistence.MappedSuperclass"); - allOpen.invoke("annotation", "jakarta.persistence.Embeddable"); + allOpen.invoke("annotation", "jakarta.persistence.Entity", "jakarta.persistence.MappedSuperclass", + "jakarta.persistence.Embeddable"); }); } - private void customizeAllOpenJPA_TEMP_javax(GradleBuild build) { + private void customizeAllOpenWithJavax(GradleBuild build) { build.extensions().customize("allOpen", (allOpen) -> { - allOpen.invoke("annotation", "javax.persistence.Entity"); - allOpen.invoke("annotation", "javax.persistence.MappedSuperclass"); - allOpen.invoke("annotation", "javax.persistence.Embeddable"); + allOpen.invoke("annotation", "javax.persistence.Entity", "javax.persistence.MappedSuperclass", + "javax.persistence.Embeddable"); }); } From 0c2ff7fc80c98f8005dd8bf9c4fad19d0f8277ca Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 04:13:55 +0900 Subject: [PATCH 06/24] Add Tests --- .../KotlinJpaGradleBuildCustomizerTests.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java index e36aa71a5a..7931326049 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java @@ -17,9 +17,12 @@ package io.spring.initializr.generator.spring.code.kotlin; import java.util.Collections; +import java.util.List; +import java.util.Objects; import io.spring.initializr.generator.buildsystem.gradle.GradleBuild; import io.spring.initializr.generator.buildsystem.gradle.GradlePlugin; +import io.spring.initializr.generator.buildsystem.gradle.Invocation; import io.spring.initializr.generator.buildsystem.gradle.StandardGradlePlugin; import io.spring.initializr.generator.project.MutableProjectDescription; import io.spring.initializr.generator.test.InitializrMetadataTestBuilder; @@ -73,4 +76,39 @@ private GradleBuild getCustomizedBuild(Dependency dependency) { return build; } + @Test + void customizeWhenJakartaPersistencePresentShouldCustomizeAllOpenWithJakarta() { + Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api"); + dependency.setFacets(Collections.singletonList("jpa")); + GradleBuild build = getCustomizedBuild(dependency); + assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { + assertThat(plugin.getId()).isEqualTo("org.jetbrains.kotlin.plugin.jpa"); + }); + assertThat(build.extensions().values()).singleElement().satisfies((extension) -> { + assertThat(extension.getName()).isEqualTo("allOpen"); + assertThat(extension.getInvocations()) + .filteredOn(invocation -> Objects.equals(invocation.getTarget(), "annotation")) + .extracting("arguments") + .containsExactlyInAnyOrder(List.of("jakarta.persistence.Entity", "jakarta.persistence.MappedSuperclass", "jakarta.persistence.Embeddable")); + }); + } + + @Test + void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() { + Dependency dependency = Dependency.withId("foo", "javax.persistence", "javax.persistence-api"); + dependency.setFacets(Collections.singletonList("jpa")); + GradleBuild build = getCustomizedBuild(dependency); + assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { + assertThat(plugin.getId()).isEqualTo("org.jetbrains.kotlin.plugin.jpa"); + }); + assertThat(build.extensions().values()).singleElement().satisfies((extension) -> { + assertThat(extension.getName()).isEqualTo("allOpen"); + assertThat(extension.getInvocations()) + .filteredOn(invocation -> Objects.equals(invocation.getTarget(), "annotation")) + .extracting("arguments") + .containsExactlyInAnyOrder(List.of("javax.persistence.Entity", "javax.persistence.MappedSuperclass", "javax.persistence.Embeddable")); + }); + + } + } From 3ebc0ac8bd438970470a86e8f91d0e7cc5e0e333 Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 10:26:37 +0900 Subject: [PATCH 07/24] Chore - Add author tag of JavaDoc - Remove Comment --- .../spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java | 2 +- .../spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java | 1 + .../src/main/java/io/spring/initializr/metadata/Dependency.java | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java index d90db93605..d226ed6f51 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java @@ -28,8 +28,8 @@ * related dependency is present. * * @author Madhura Bhave + * @author Sijun Yang */ -// BuildCustomizer 구현체를 보니 Kotlin + JPA 관련 객체가 이미 있음. public class KotlinJpaGradleBuildCustomizer implements BuildCustomizer { private final BuildMetadataResolver buildMetadataResolver; diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java index 7931326049..e2662f6a63 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java @@ -38,6 +38,7 @@ * Tests for {@link KotlinJpaGradleBuildCustomizer}. * * @author Madhura Bhave + * @author Sijun Yang */ class KotlinJpaGradleBuildCustomizerTests { diff --git a/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java b/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java index a6cbff753c..a96249f495 100644 --- a/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java +++ b/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java @@ -35,6 +35,7 @@ * number of {@code aliases}. * * @author Stephane Nicoll + * @author Sijun Yang */ @JsonInclude(JsonInclude.Include.NON_EMPTY) public class Dependency extends MetadataElement implements Describable { From f4134b9544ba3acbc30eaf817eea7e133f9c72c6 Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 12:13:40 +0900 Subject: [PATCH 08/24] Update KotlinJpaMavenBuildCustomizer.java - Add Configure kotlin + allOpen --- .../kotlin/KotlinJpaMavenBuildCustomizer.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java index c57927c002..bb0e889e33 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java @@ -17,6 +17,7 @@ package io.spring.initializr.generator.spring.code.kotlin; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; +import io.spring.initializr.generator.buildsystem.maven.MavenPlugin; import io.spring.initializr.generator.project.ProjectDescription; import io.spring.initializr.generator.spring.build.BuildCustomizer; import io.spring.initializr.generator.spring.build.BuildMetadataResolver; @@ -41,11 +42,31 @@ public KotlinJpaMavenBuildCustomizer(InitializrMetadata metadata, ProjectDescrip public void customize(MavenBuild build) { if (this.buildMetadataResolver.hasFacet(build, "jpa")) { build.plugins().add("org.jetbrains.kotlin", "kotlin-maven-plugin", (kotlinPlugin) -> { - kotlinPlugin.configuration((configuration) -> configuration.configure("compilerPlugins", - (compilerPlugins) -> compilerPlugins.add("plugin", "jpa"))); + kotlinPlugin.configuration((configuration) -> { + configuration.configure("compilerPlugins", + (compilerPlugins) -> compilerPlugins.add("plugin", "jpa")); + if (this.buildMetadataResolver.hasGroupId(build, "jakarta.persistence")) { + customizeAllOpenWithJakarta(configuration); + } + else if (this.buildMetadataResolver.hasGroupId(build, "javax.persistence")) { + customizeAllOpenWithJavax(configuration); + } + }); kotlinPlugin.dependency("org.jetbrains.kotlin", "kotlin-maven-noarg", "${kotlin.version}"); }); } } + private void customizeAllOpenWithJakarta(MavenPlugin.ConfigurationBuilder option) { + option.add("option", "all-open:annotation=jakarta.persistence.Entity"); + option.add("option", "all-open:annotation=jakarta.persistence.MappedSuperclass"); + option.add("option", "all-open:annotation=jakarta.persistence.Embeddable"); + } + + private void customizeAllOpenWithJavax(MavenPlugin.ConfigurationBuilder option) { + option.add("option", "all-open:annotation=javax.persistence.Entity"); + option.add("option", "all-open:annotation=javax.persistence.MappedSuperclass"); + option.add("option", "all-open:annotation=javax.persistence.Embeddable"); + } + } From 86d15da3aea34df90c0c4826dfbaf520e2e46d15 Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 12:13:50 +0900 Subject: [PATCH 09/24] Add Tests --- .../KotlinJpaMavenBuildCustomizerTests.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java index a907b18526..018773a835 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java @@ -67,6 +67,46 @@ void customizeWhenJpaFacetAbsentShouldNotAddKotlinJpaPlugin() { assertThat(build.plugins().isEmpty()).isTrue(); } + @Test + void customizeWhenJakartaPersistencePresentShouldCustomizeAllOpenWithJakarta() { + Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api"); + dependency.setFacets(Collections.singletonList("jpa")); + MavenBuild build = getCustomizedBuild(dependency); + assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { + assertThat(plugin.getGroupId()).isEqualTo("org.jetbrains.kotlin"); + assertThat(plugin.getArtifactId()).isEqualTo("kotlin-maven-plugin"); + }); + assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { + MavenPlugin.Configuration configuration = plugin.getConfiguration(); + assertThat(configuration.getSettings().stream() + .filter(setting -> "option".equals(setting.getName())) + .map(MavenPlugin.Setting::getValue)) + .containsExactlyInAnyOrder("all-open:annotation=jakarta.persistence.Entity", + "all-open:annotation=jakarta.persistence.MappedSuperclass", + "all-open:annotation=jakarta.persistence.Embeddable"); + }); + } + + @Test + void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() { + Dependency dependency = Dependency.withId("foo", "javax.persistence", "javax.persistence-api"); + dependency.setFacets(Collections.singletonList("jpa")); + MavenBuild build = getCustomizedBuild(dependency); + assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { + assertThat(plugin.getGroupId()).isEqualTo("org.jetbrains.kotlin"); + assertThat(plugin.getArtifactId()).isEqualTo("kotlin-maven-plugin"); + }); + assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { + MavenPlugin.Configuration configuration = plugin.getConfiguration(); + assertThat(configuration.getSettings().stream() + .filter(setting -> "option".equals(setting.getName())) + .map(MavenPlugin.Setting::getValue)) + .containsExactlyInAnyOrder("all-open:annotation=javax.persistence.Entity", + "all-open:annotation=javax.persistence.MappedSuperclass", + "all-open:annotation=javax.persistence.Embeddable"); + }); + } + private MavenBuild getCustomizedBuild(Dependency dependency) { InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() .addDependencyGroup("test", dependency) From ec2e609f4b5d22d7e7adbcc2dcdcbdbd0d5a725e Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 12:16:26 +0900 Subject: [PATCH 10/24] Update KotlinJpaMavenBuildCustomizer.java - Add author tag of JavaDoc --- .../spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java index bb0e889e33..33e6fbf970 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java @@ -29,6 +29,7 @@ * * @author Madhura Bhave * @author Sebastien Deleuze + * @author Sijun Yang */ public class KotlinJpaMavenBuildCustomizer implements BuildCustomizer { From fe148e52c78999052a822c2ddf5183716d8eb80c Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 12:32:12 +0900 Subject: [PATCH 11/24] Add temp code for check buildfile --- .../gradle/GradleBuildProjectContributor.java | 4 +-- .../KotlinJpaGradleBuildCustomizerTests.java | 34 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/GradleBuildProjectContributor.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/GradleBuildProjectContributor.java index 7f1bd62742..4c90caea96 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/GradleBuildProjectContributor.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/GradleBuildProjectContributor.java @@ -44,8 +44,8 @@ public class GradleBuildProjectContributor implements BuildWriter, ProjectContri private final String buildFileName; - GradleBuildProjectContributor(GradleBuildWriter buildWriter, GradleBuild build, - IndentingWriterFactory indentingWriterFactory, String buildFileName) { + public GradleBuildProjectContributor(GradleBuildWriter buildWriter, GradleBuild build, + IndentingWriterFactory indentingWriterFactory, String buildFileName) { this.buildWriter = buildWriter; this.build = build; this.indentingWriterFactory = indentingWriterFactory; diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java index e2662f6a63..13b2f6e65c 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java @@ -16,16 +16,19 @@ package io.spring.initializr.generator.spring.code.kotlin; +import java.io.IOException; +import java.io.StringWriter; import java.util.Collections; import java.util.List; import java.util.Objects; -import io.spring.initializr.generator.buildsystem.gradle.GradleBuild; -import io.spring.initializr.generator.buildsystem.gradle.GradlePlugin; -import io.spring.initializr.generator.buildsystem.gradle.Invocation; -import io.spring.initializr.generator.buildsystem.gradle.StandardGradlePlugin; +import io.spring.initializr.generator.buildsystem.gradle.*; +import io.spring.initializr.generator.io.IndentingWriterFactory; +import io.spring.initializr.generator.io.SimpleIndentStrategy; import io.spring.initializr.generator.project.MutableProjectDescription; +import io.spring.initializr.generator.spring.build.gradle.GradleBuildProjectContributor; import io.spring.initializr.generator.test.InitializrMetadataTestBuilder; +import io.spring.initializr.generator.test.io.TextTestUtils; import io.spring.initializr.generator.version.Version; import io.spring.initializr.metadata.Dependency; import io.spring.initializr.metadata.InitializrMetadata; @@ -90,7 +93,7 @@ void customizeWhenJakartaPersistencePresentShouldCustomizeAllOpenWithJakarta() { assertThat(extension.getInvocations()) .filteredOn(invocation -> Objects.equals(invocation.getTarget(), "annotation")) .extracting("arguments") - .containsExactlyInAnyOrder(List.of("jakarta.persistence.Entity", "jakarta.persistence.MappedSuperclass", "jakarta.persistence.Embeddable")); + .containsExactlyInAnyOrder(List.of("jakarta.persistence.Entity"), List.of("jakarta.persistence.MappedSuperclass"), List.of("jakarta.persistence.Embeddable")); }); } @@ -107,9 +110,28 @@ void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() { assertThat(extension.getInvocations()) .filteredOn(invocation -> Objects.equals(invocation.getTarget(), "annotation")) .extracting("arguments") - .containsExactlyInAnyOrder(List.of("javax.persistence.Entity", "javax.persistence.MappedSuperclass", "javax.persistence.Embeddable")); + .containsExactlyInAnyOrder(List.of("javax.persistence.Entity"), List.of("javax.persistence.MappedSuperclass"), List.of("javax.persistence.Embeddable")); }); } + private GradleBuildProjectContributor kotlinDslGradleBuildProjectContributor(GradleBuild build, + IndentingWriterFactory indentingWriterFactory) { + return new GradleBuildProjectContributor(new KotlinDslGradleBuildWriter(), build, indentingWriterFactory, + "build.gradle.kts"); + } + + @Test + void tempTestForBuildFile() throws IOException { + IndentingWriterFactory indentingWriterFactory = IndentingWriterFactory.create(new SimpleIndentStrategy(" "), + (factory) -> factory.indentingStrategy("gradle", new SimpleIndentStrategy(" "))); + Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api"); + dependency.setFacets(Collections.singletonList("jpa")); + GradleBuild build = getCustomizedBuild(dependency); + var gradleBuildProjectContributor= kotlinDslGradleBuildProjectContributor(build, indentingWriterFactory); + StringWriter writer = new StringWriter(); + gradleBuildProjectContributor.writeBuild(writer); + System.out.println(TextTestUtils.readAllLines(writer.toString())); + } + } From 706aaf52ae8dd36dd0582a55c9c728b68fb107ac Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 12:35:39 +0900 Subject: [PATCH 12/24] Fix allOpen.invoke --- .../code/kotlin/KotlinJpaGradleBuildCustomizer.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java index d226ed6f51..5beaa187b6 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java @@ -58,15 +58,17 @@ else if (this.buildMetadataResolver.hasGroupId(build, "javax.persistence")) { private void customizeAllOpenWithJakarta(GradleBuild build) { build.extensions().customize("allOpen", (allOpen) -> { - allOpen.invoke("annotation", "jakarta.persistence.Entity", "jakarta.persistence.MappedSuperclass", - "jakarta.persistence.Embeddable"); + allOpen.invoke("annotation", "jakarta.persistence.Entity"); + allOpen.invoke("annotation", "jakarta.persistence.MappedSuperclass"); + allOpen.invoke("annotation", "jakarta.persistence.Embeddable"); }); } private void customizeAllOpenWithJavax(GradleBuild build) { build.extensions().customize("allOpen", (allOpen) -> { - allOpen.invoke("annotation", "javax.persistence.Entity", "javax.persistence.MappedSuperclass", - "javax.persistence.Embeddable"); + allOpen.invoke("annotation", "javax.persistence.Entity"); + allOpen.invoke("annotation", "javax.persistence.MappedSuperclass"); + allOpen.invoke("annotation", "javax.persistence.Embeddable"); }); } From e7e48f5b43ef66744732c721f5165f0a7baa92ef Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 15:01:17 +0900 Subject: [PATCH 13/24] Add temp code for check buildfile --- .../KotlinJpaGradleBuildCustomizerTests.java | 15 +++++++- .../KotlinJpaMavenBuildCustomizerTests.java | 37 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java index 13b2f6e65c..049ddc2c00 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java @@ -122,7 +122,7 @@ private GradleBuildProjectContributor kotlinDslGradleBuildProjectContributor(Gra } @Test - void tempTestForBuildFile() throws IOException { + void tempTestForBuildFile1() throws IOException { IndentingWriterFactory indentingWriterFactory = IndentingWriterFactory.create(new SimpleIndentStrategy(" "), (factory) -> factory.indentingStrategy("gradle", new SimpleIndentStrategy(" "))); Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api"); @@ -134,4 +134,17 @@ void tempTestForBuildFile() throws IOException { System.out.println(TextTestUtils.readAllLines(writer.toString())); } + @Test + void tempTestForBuildFile2() throws IOException { + IndentingWriterFactory indentingWriterFactory = IndentingWriterFactory.create(new SimpleIndentStrategy(" "), + (factory) -> factory.indentingStrategy("gradle", new SimpleIndentStrategy(" "))); + Dependency dependency = Dependency.withId("foo", "javax.persistence", "javax.persistence-api"); + dependency.setFacets(Collections.singletonList("jpa")); + GradleBuild build = getCustomizedBuild(dependency); + var gradleBuildProjectContributor= kotlinDslGradleBuildProjectContributor(build, indentingWriterFactory); + StringWriter writer = new StringWriter(); + gradleBuildProjectContributor.writeBuild(writer); + System.out.println(TextTestUtils.readAllLines(writer.toString())); + } + } diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java index 018773a835..ef6b8fa150 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java @@ -16,12 +16,19 @@ package io.spring.initializr.generator.spring.code.kotlin; +import java.io.IOException; +import java.io.StringWriter; import java.util.Collections; +import io.spring.initializr.generator.buildsystem.gradle.GradleBuild; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin; +import io.spring.initializr.generator.io.IndentingWriterFactory; +import io.spring.initializr.generator.io.SimpleIndentStrategy; import io.spring.initializr.generator.project.MutableProjectDescription; +import io.spring.initializr.generator.spring.build.maven.MavenBuildProjectContributor; import io.spring.initializr.generator.test.InitializrMetadataTestBuilder; +import io.spring.initializr.generator.test.io.TextTestUtils; import io.spring.initializr.generator.version.Version; import io.spring.initializr.metadata.Dependency; import io.spring.initializr.metadata.InitializrMetadata; @@ -120,4 +127,34 @@ private MavenBuild getCustomizedBuild(Dependency dependency) { return build; } + @Test + void tempTestForBuildFile1() throws IOException { + IndentingWriterFactory indentingWriterFactory = IndentingWriterFactory.create(new SimpleIndentStrategy(" "), + (factory) -> factory.indentingStrategy("gradle", new SimpleIndentStrategy(" "))); + Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api"); + dependency.setFacets(Collections.singletonList("jpa")); + MavenBuild build = getCustomizedBuild(dependency); + var gradleBuildProjectContributor= generatePom(build, indentingWriterFactory); + StringWriter writer = new StringWriter(); + gradleBuildProjectContributor.writeBuild(writer); + System.out.println(TextTestUtils.readAllLines(writer.toString())); + } + + @Test + void tempTestForBuildFile2() throws IOException { + IndentingWriterFactory indentingWriterFactory = IndentingWriterFactory.create(new SimpleIndentStrategy(" "), + (factory) -> factory.indentingStrategy("gradle", new SimpleIndentStrategy(" "))); + Dependency dependency = Dependency.withId("foo", "javax.persistence", "javax.persistence-api"); + dependency.setFacets(Collections.singletonList("jpa")); + MavenBuild build = getCustomizedBuild(dependency); + var gradleBuildProjectContributor= generatePom(build, indentingWriterFactory); + StringWriter writer = new StringWriter(); + gradleBuildProjectContributor.writeBuild(writer); + System.out.println(TextTestUtils.readAllLines(writer.toString())); + } + + private MavenBuildProjectContributor generatePom(MavenBuild mavenBuild, IndentingWriterFactory indentingWriterFactory) { + return new MavenBuildProjectContributor(mavenBuild, indentingWriterFactory); + } + } From a9837f957bfee5bc5cbafc3338de9a9b8d87a9ba Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 15:07:35 +0900 Subject: [PATCH 14/24] Update KotlinJpaGradleBuildCustomizerTests.java --- .../spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java index 049ddc2c00..f8f1296db9 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java @@ -110,7 +110,7 @@ void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() { assertThat(extension.getInvocations()) .filteredOn(invocation -> Objects.equals(invocation.getTarget(), "annotation")) .extracting("arguments") - .containsExactlyInAnyOrder(List.of("javax.persistence.Entity"), List.of("javax.persistence.MappedSuperclass"), List.of("javax.persistence.Embeddable")); + .containsExactlyInAnyOrder("javax.persistence.Entity", "javax.persistence.MappedSuperclass", "javax.persistence.Embeddable"); }); } From 301c35634c9b3f10723f868c971b7927e8773cff Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 15:46:09 +0900 Subject: [PATCH 15/24] Change code style --- .../spring/build/BuildMetadataResolver.java | 6 ++-- .../gradle/GradleBuildProjectContributor.java | 2 +- .../KotlinJpaGradleBuildCustomizerTests.java | 12 ++++--- .../KotlinJpaMavenBuildCustomizerTests.java | 33 ++++++++++--------- .../initializr/metadata/Dependency.java | 1 - 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/BuildMetadataResolver.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/BuildMetadataResolver.java index 68a20e3be0..05cd896e8f 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/BuildMetadataResolver.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/BuildMetadataResolver.java @@ -66,10 +66,12 @@ public boolean hasFacet(Build build, String facet) { } /** - * Checks if the given {@link Build} contains dependencies with the given {@code groupId}. + * Checks if the given {@link Build} contains dependencies with the given + * {@code groupId}. * @param build the build to query * @param groupId the groupId to query - * @return {@code true} if this build defines at least a dependency with that groupId, {@code false} otherwise + * @return {@code true} if this build defines at least a dependency with that groupId, + * {@code false} otherwise */ public boolean hasGroupId(Build build, String groupId) { return dependencies(build).anyMatch((dependency) -> dependency.getGroupId().equals(groupId)); diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/GradleBuildProjectContributor.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/GradleBuildProjectContributor.java index 4c90caea96..00808f4877 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/GradleBuildProjectContributor.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/GradleBuildProjectContributor.java @@ -45,7 +45,7 @@ public class GradleBuildProjectContributor implements BuildWriter, ProjectContri private final String buildFileName; public GradleBuildProjectContributor(GradleBuildWriter buildWriter, GradleBuild build, - IndentingWriterFactory indentingWriterFactory, String buildFileName) { + IndentingWriterFactory indentingWriterFactory, String buildFileName) { this.buildWriter = buildWriter; this.build = build; this.indentingWriterFactory = indentingWriterFactory; diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java index f8f1296db9..8cb4b378b0 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java @@ -93,7 +93,8 @@ void customizeWhenJakartaPersistencePresentShouldCustomizeAllOpenWithJakarta() { assertThat(extension.getInvocations()) .filteredOn(invocation -> Objects.equals(invocation.getTarget(), "annotation")) .extracting("arguments") - .containsExactlyInAnyOrder(List.of("jakarta.persistence.Entity"), List.of("jakarta.persistence.MappedSuperclass"), List.of("jakarta.persistence.Embeddable")); + .containsExactlyInAnyOrder(List.of("jakarta.persistence.Entity"), + List.of("jakarta.persistence.MappedSuperclass"), List.of("jakarta.persistence.Embeddable")); }); } @@ -110,13 +111,14 @@ void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() { assertThat(extension.getInvocations()) .filteredOn(invocation -> Objects.equals(invocation.getTarget(), "annotation")) .extracting("arguments") - .containsExactlyInAnyOrder("javax.persistence.Entity", "javax.persistence.MappedSuperclass", "javax.persistence.Embeddable"); + .containsExactlyInAnyOrder("javax.persistence.Entity", "javax.persistence.MappedSuperclass", + "javax.persistence.Embeddable"); }); } private GradleBuildProjectContributor kotlinDslGradleBuildProjectContributor(GradleBuild build, - IndentingWriterFactory indentingWriterFactory) { + IndentingWriterFactory indentingWriterFactory) { return new GradleBuildProjectContributor(new KotlinDslGradleBuildWriter(), build, indentingWriterFactory, "build.gradle.kts"); } @@ -128,7 +130,7 @@ void tempTestForBuildFile1() throws IOException { Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api"); dependency.setFacets(Collections.singletonList("jpa")); GradleBuild build = getCustomizedBuild(dependency); - var gradleBuildProjectContributor= kotlinDslGradleBuildProjectContributor(build, indentingWriterFactory); + var gradleBuildProjectContributor = kotlinDslGradleBuildProjectContributor(build, indentingWriterFactory); StringWriter writer = new StringWriter(); gradleBuildProjectContributor.writeBuild(writer); System.out.println(TextTestUtils.readAllLines(writer.toString())); @@ -141,7 +143,7 @@ void tempTestForBuildFile2() throws IOException { Dependency dependency = Dependency.withId("foo", "javax.persistence", "javax.persistence-api"); dependency.setFacets(Collections.singletonList("jpa")); GradleBuild build = getCustomizedBuild(dependency); - var gradleBuildProjectContributor= kotlinDslGradleBuildProjectContributor(build, indentingWriterFactory); + var gradleBuildProjectContributor = kotlinDslGradleBuildProjectContributor(build, indentingWriterFactory); StringWriter writer = new StringWriter(); gradleBuildProjectContributor.writeBuild(writer); System.out.println(TextTestUtils.readAllLines(writer.toString())); diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java index ef6b8fa150..fcde21f628 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java @@ -85,12 +85,13 @@ void customizeWhenJakartaPersistencePresentShouldCustomizeAllOpenWithJakarta() { }); assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { MavenPlugin.Configuration configuration = plugin.getConfiguration(); - assertThat(configuration.getSettings().stream() - .filter(setting -> "option".equals(setting.getName())) - .map(MavenPlugin.Setting::getValue)) - .containsExactlyInAnyOrder("all-open:annotation=jakarta.persistence.Entity", - "all-open:annotation=jakarta.persistence.MappedSuperclass", - "all-open:annotation=jakarta.persistence.Embeddable"); + assertThat(configuration.getSettings() + .stream() + .filter(setting -> "option".equals(setting.getName())) + .map(MavenPlugin.Setting::getValue)) + .containsExactlyInAnyOrder("all-open:annotation=jakarta.persistence.Entity", + "all-open:annotation=jakarta.persistence.MappedSuperclass", + "all-open:annotation=jakarta.persistence.Embeddable"); }); } @@ -105,12 +106,13 @@ void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() { }); assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { MavenPlugin.Configuration configuration = plugin.getConfiguration(); - assertThat(configuration.getSettings().stream() - .filter(setting -> "option".equals(setting.getName())) - .map(MavenPlugin.Setting::getValue)) - .containsExactlyInAnyOrder("all-open:annotation=javax.persistence.Entity", - "all-open:annotation=javax.persistence.MappedSuperclass", - "all-open:annotation=javax.persistence.Embeddable"); + assertThat(configuration.getSettings() + .stream() + .filter(setting -> "option".equals(setting.getName())) + .map(MavenPlugin.Setting::getValue)) + .containsExactlyInAnyOrder("all-open:annotation=javax.persistence.Entity", + "all-open:annotation=javax.persistence.MappedSuperclass", + "all-open:annotation=javax.persistence.Embeddable"); }); } @@ -134,7 +136,7 @@ void tempTestForBuildFile1() throws IOException { Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api"); dependency.setFacets(Collections.singletonList("jpa")); MavenBuild build = getCustomizedBuild(dependency); - var gradleBuildProjectContributor= generatePom(build, indentingWriterFactory); + var gradleBuildProjectContributor = generatePom(build, indentingWriterFactory); StringWriter writer = new StringWriter(); gradleBuildProjectContributor.writeBuild(writer); System.out.println(TextTestUtils.readAllLines(writer.toString())); @@ -147,13 +149,14 @@ void tempTestForBuildFile2() throws IOException { Dependency dependency = Dependency.withId("foo", "javax.persistence", "javax.persistence-api"); dependency.setFacets(Collections.singletonList("jpa")); MavenBuild build = getCustomizedBuild(dependency); - var gradleBuildProjectContributor= generatePom(build, indentingWriterFactory); + var gradleBuildProjectContributor = generatePom(build, indentingWriterFactory); StringWriter writer = new StringWriter(); gradleBuildProjectContributor.writeBuild(writer); System.out.println(TextTestUtils.readAllLines(writer.toString())); } - private MavenBuildProjectContributor generatePom(MavenBuild mavenBuild, IndentingWriterFactory indentingWriterFactory) { + private MavenBuildProjectContributor generatePom(MavenBuild mavenBuild, + IndentingWriterFactory indentingWriterFactory) { return new MavenBuildProjectContributor(mavenBuild, indentingWriterFactory); } diff --git a/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java b/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java index a96249f495..89a92fe0ea 100644 --- a/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java +++ b/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java @@ -124,7 +124,6 @@ public class Dependency extends MetadataElement implements Describable { public Dependency() { } - //groupId로 jakarta 또는 javax 사용 여부를 확인할 수 있을 것 같음. public Dependency(Dependency dependency) { super(dependency); this.aliases.addAll(dependency.aliases); From 4ad7dd47a9a779e8732df1dcc953bc5d86b0c871 Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 15:49:13 +0900 Subject: [PATCH 16/24] Remove temp test code --- .../KotlinJpaGradleBuildCustomizerTests.java | 38 ------------------- .../KotlinJpaMavenBuildCustomizerTests.java | 38 ------------------- 2 files changed, 76 deletions(-) diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java index 8cb4b378b0..ee9f49d89a 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java @@ -16,19 +16,13 @@ package io.spring.initializr.generator.spring.code.kotlin; -import java.io.IOException; -import java.io.StringWriter; import java.util.Collections; import java.util.List; import java.util.Objects; import io.spring.initializr.generator.buildsystem.gradle.*; -import io.spring.initializr.generator.io.IndentingWriterFactory; -import io.spring.initializr.generator.io.SimpleIndentStrategy; import io.spring.initializr.generator.project.MutableProjectDescription; -import io.spring.initializr.generator.spring.build.gradle.GradleBuildProjectContributor; import io.spring.initializr.generator.test.InitializrMetadataTestBuilder; -import io.spring.initializr.generator.test.io.TextTestUtils; import io.spring.initializr.generator.version.Version; import io.spring.initializr.metadata.Dependency; import io.spring.initializr.metadata.InitializrMetadata; @@ -117,36 +111,4 @@ void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() { } - private GradleBuildProjectContributor kotlinDslGradleBuildProjectContributor(GradleBuild build, - IndentingWriterFactory indentingWriterFactory) { - return new GradleBuildProjectContributor(new KotlinDslGradleBuildWriter(), build, indentingWriterFactory, - "build.gradle.kts"); - } - - @Test - void tempTestForBuildFile1() throws IOException { - IndentingWriterFactory indentingWriterFactory = IndentingWriterFactory.create(new SimpleIndentStrategy(" "), - (factory) -> factory.indentingStrategy("gradle", new SimpleIndentStrategy(" "))); - Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api"); - dependency.setFacets(Collections.singletonList("jpa")); - GradleBuild build = getCustomizedBuild(dependency); - var gradleBuildProjectContributor = kotlinDslGradleBuildProjectContributor(build, indentingWriterFactory); - StringWriter writer = new StringWriter(); - gradleBuildProjectContributor.writeBuild(writer); - System.out.println(TextTestUtils.readAllLines(writer.toString())); - } - - @Test - void tempTestForBuildFile2() throws IOException { - IndentingWriterFactory indentingWriterFactory = IndentingWriterFactory.create(new SimpleIndentStrategy(" "), - (factory) -> factory.indentingStrategy("gradle", new SimpleIndentStrategy(" "))); - Dependency dependency = Dependency.withId("foo", "javax.persistence", "javax.persistence-api"); - dependency.setFacets(Collections.singletonList("jpa")); - GradleBuild build = getCustomizedBuild(dependency); - var gradleBuildProjectContributor = kotlinDslGradleBuildProjectContributor(build, indentingWriterFactory); - StringWriter writer = new StringWriter(); - gradleBuildProjectContributor.writeBuild(writer); - System.out.println(TextTestUtils.readAllLines(writer.toString())); - } - } diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java index fcde21f628..a1d45dc686 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java @@ -16,19 +16,12 @@ package io.spring.initializr.generator.spring.code.kotlin; -import java.io.IOException; -import java.io.StringWriter; import java.util.Collections; -import io.spring.initializr.generator.buildsystem.gradle.GradleBuild; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin; -import io.spring.initializr.generator.io.IndentingWriterFactory; -import io.spring.initializr.generator.io.SimpleIndentStrategy; import io.spring.initializr.generator.project.MutableProjectDescription; -import io.spring.initializr.generator.spring.build.maven.MavenBuildProjectContributor; import io.spring.initializr.generator.test.InitializrMetadataTestBuilder; -import io.spring.initializr.generator.test.io.TextTestUtils; import io.spring.initializr.generator.version.Version; import io.spring.initializr.metadata.Dependency; import io.spring.initializr.metadata.InitializrMetadata; @@ -129,35 +122,4 @@ private MavenBuild getCustomizedBuild(Dependency dependency) { return build; } - @Test - void tempTestForBuildFile1() throws IOException { - IndentingWriterFactory indentingWriterFactory = IndentingWriterFactory.create(new SimpleIndentStrategy(" "), - (factory) -> factory.indentingStrategy("gradle", new SimpleIndentStrategy(" "))); - Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api"); - dependency.setFacets(Collections.singletonList("jpa")); - MavenBuild build = getCustomizedBuild(dependency); - var gradleBuildProjectContributor = generatePom(build, indentingWriterFactory); - StringWriter writer = new StringWriter(); - gradleBuildProjectContributor.writeBuild(writer); - System.out.println(TextTestUtils.readAllLines(writer.toString())); - } - - @Test - void tempTestForBuildFile2() throws IOException { - IndentingWriterFactory indentingWriterFactory = IndentingWriterFactory.create(new SimpleIndentStrategy(" "), - (factory) -> factory.indentingStrategy("gradle", new SimpleIndentStrategy(" "))); - Dependency dependency = Dependency.withId("foo", "javax.persistence", "javax.persistence-api"); - dependency.setFacets(Collections.singletonList("jpa")); - MavenBuild build = getCustomizedBuild(dependency); - var gradleBuildProjectContributor = generatePom(build, indentingWriterFactory); - StringWriter writer = new StringWriter(); - gradleBuildProjectContributor.writeBuild(writer); - System.out.println(TextTestUtils.readAllLines(writer.toString())); - } - - private MavenBuildProjectContributor generatePom(MavenBuild mavenBuild, - IndentingWriterFactory indentingWriterFactory) { - return new MavenBuildProjectContributor(mavenBuild, indentingWriterFactory); - } - } From 90b8c5b7ca147b4f935bc5da500bd92e0ca12765 Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 15:50:54 +0900 Subject: [PATCH 17/24] Revert GradleBuildProjectContributor to protected --- .../spring/build/gradle/GradleBuildProjectContributor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/GradleBuildProjectContributor.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/GradleBuildProjectContributor.java index 00808f4877..7f1bd62742 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/GradleBuildProjectContributor.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/GradleBuildProjectContributor.java @@ -44,7 +44,7 @@ public class GradleBuildProjectContributor implements BuildWriter, ProjectContri private final String buildFileName; - public GradleBuildProjectContributor(GradleBuildWriter buildWriter, GradleBuild build, + GradleBuildProjectContributor(GradleBuildWriter buildWriter, GradleBuild build, IndentingWriterFactory indentingWriterFactory, String buildFileName) { this.buildWriter = buildWriter; this.build = build; From 5779e8ac73b81d5d24f265b5076ca7aeed2547aa Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 15:52:30 +0900 Subject: [PATCH 18/24] Chore - Update comment, javadoc --- .../initializr/generator/spring/build/BuildMetadataResolver.java | 1 + .../src/main/java/io/spring/initializr/metadata/Dependency.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/BuildMetadataResolver.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/BuildMetadataResolver.java index 05cd896e8f..b9673d56f7 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/BuildMetadataResolver.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/BuildMetadataResolver.java @@ -29,6 +29,7 @@ * * @author Stephane Nicoll * @author Moritz Halbritter + * @author Sijun Yang */ public class BuildMetadataResolver { diff --git a/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java b/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java index 89a92fe0ea..16a1c87e3d 100644 --- a/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java +++ b/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java @@ -35,7 +35,6 @@ * number of {@code aliases}. * * @author Stephane Nicoll - * @author Sijun Yang */ @JsonInclude(JsonInclude.Include.NON_EMPTY) public class Dependency extends MetadataElement implements Describable { From b1fd50bcf1a675f64cef47f09e4b5e3d0d86fb7f Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 16:54:58 +0900 Subject: [PATCH 19/24] Change code style --- .../code/kotlin/KotlinJpaGradleBuildCustomizerTests.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java index ee9f49d89a..c2c8421960 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java @@ -20,7 +20,9 @@ import java.util.List; import java.util.Objects; -import io.spring.initializr.generator.buildsystem.gradle.*; +import io.spring.initializr.generator.buildsystem.gradle.GradleBuild; +import io.spring.initializr.generator.buildsystem.gradle.GradlePlugin; +import io.spring.initializr.generator.buildsystem.gradle.StandardGradlePlugin; import io.spring.initializr.generator.project.MutableProjectDescription; import io.spring.initializr.generator.test.InitializrMetadataTestBuilder; import io.spring.initializr.generator.version.Version; From a985271da531a785ac2987b6e8e7cad9600a20fe Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Wed, 9 Oct 2024 17:43:07 +0900 Subject: [PATCH 20/24] Fix test with code style --- .../KotlinJpaGradleBuildCustomizerTests.java | 48 +++++++++---------- .../KotlinJpaMavenBuildCustomizerTests.java | 12 ++--- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java index c2c8421960..ab8639d414 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java @@ -61,33 +61,17 @@ void customizeWhenJpaFacetAbsentShouldNotAddKotlinJpaPlugin() { assertThat(build.plugins().values()).isEmpty(); } - private GradleBuild getCustomizedBuild(Dependency dependency) { - InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() - .addDependencyGroup("test", dependency) - .build(); - SimpleKotlinProjectSettings settings = new SimpleKotlinProjectSettings("1.2.70"); - MutableProjectDescription projectDescription = new MutableProjectDescription(); - projectDescription.setPlatformVersion(Version.parse("1.0.0")); - KotlinJpaGradleBuildCustomizer customizer = new KotlinJpaGradleBuildCustomizer(metadata, settings, - projectDescription); - GradleBuild build = new GradleBuild(new MetadataBuildItemResolver(metadata, Version.parse("2.0.0.RELEASE"))); - build.dependencies().add("foo"); - customizer.customize(build); - return build; - } - @Test void customizeWhenJakartaPersistencePresentShouldCustomizeAllOpenWithJakarta() { Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api"); dependency.setFacets(Collections.singletonList("jpa")); GradleBuild build = getCustomizedBuild(dependency); - assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { - assertThat(plugin.getId()).isEqualTo("org.jetbrains.kotlin.plugin.jpa"); - }); + assertThat(build.plugins().values()).singleElement() + .satisfies((plugin) -> assertThat(plugin.getId()).isEqualTo("org.jetbrains.kotlin.plugin.jpa")); assertThat(build.extensions().values()).singleElement().satisfies((extension) -> { assertThat(extension.getName()).isEqualTo("allOpen"); assertThat(extension.getInvocations()) - .filteredOn(invocation -> Objects.equals(invocation.getTarget(), "annotation")) + .filteredOn((invocation) -> Objects.equals(invocation.getTarget(), "annotation")) .extracting("arguments") .containsExactlyInAnyOrder(List.of("jakarta.persistence.Entity"), List.of("jakarta.persistence.MappedSuperclass"), List.of("jakarta.persistence.Embeddable")); @@ -99,18 +83,32 @@ void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() { Dependency dependency = Dependency.withId("foo", "javax.persistence", "javax.persistence-api"); dependency.setFacets(Collections.singletonList("jpa")); GradleBuild build = getCustomizedBuild(dependency); - assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { - assertThat(plugin.getId()).isEqualTo("org.jetbrains.kotlin.plugin.jpa"); - }); + assertThat(build.plugins().values()).singleElement() + .satisfies((plugin) -> assertThat(plugin.getId()).isEqualTo("org.jetbrains.kotlin.plugin.jpa")); assertThat(build.extensions().values()).singleElement().satisfies((extension) -> { assertThat(extension.getName()).isEqualTo("allOpen"); assertThat(extension.getInvocations()) - .filteredOn(invocation -> Objects.equals(invocation.getTarget(), "annotation")) + .filteredOn((invocation) -> Objects.equals(invocation.getTarget(), "annotation")) .extracting("arguments") - .containsExactlyInAnyOrder("javax.persistence.Entity", "javax.persistence.MappedSuperclass", - "javax.persistence.Embeddable"); + .containsExactlyInAnyOrder(List.of("javax.persistence.Entity"), + List.of("javax.persistence.MappedSuperclass"), List.of("javax.persistence.Embeddable")); }); } + private GradleBuild getCustomizedBuild(Dependency dependency) { + InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() + .addDependencyGroup("test", dependency) + .build(); + SimpleKotlinProjectSettings settings = new SimpleKotlinProjectSettings("1.2.70"); + MutableProjectDescription projectDescription = new MutableProjectDescription(); + projectDescription.setPlatformVersion(Version.parse("1.0.0")); + KotlinJpaGradleBuildCustomizer customizer = new KotlinJpaGradleBuildCustomizer(metadata, settings, + projectDescription); + GradleBuild build = new GradleBuild(new MetadataBuildItemResolver(metadata, Version.parse("2.0.0.RELEASE"))); + build.dependencies().add("foo"); + customizer.customize(build); + return build; + } + } diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java index a1d45dc686..5e42c807df 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2023 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. @@ -31,12 +31,6 @@ import static org.assertj.core.api.Assertions.assertThat; -/** - * Tests for {@link KotlinJpaMavenBuildCustomizer}. - * - * @author Madhura Bhave - * @author Sebastien Deleuze - */ class KotlinJpaMavenBuildCustomizerTests { @Test @@ -80,7 +74,7 @@ void customizeWhenJakartaPersistencePresentShouldCustomizeAllOpenWithJakarta() { MavenPlugin.Configuration configuration = plugin.getConfiguration(); assertThat(configuration.getSettings() .stream() - .filter(setting -> "option".equals(setting.getName())) + .filter((setting) -> "option".equals(setting.getName())) .map(MavenPlugin.Setting::getValue)) .containsExactlyInAnyOrder("all-open:annotation=jakarta.persistence.Entity", "all-open:annotation=jakarta.persistence.MappedSuperclass", @@ -101,7 +95,7 @@ void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() { MavenPlugin.Configuration configuration = plugin.getConfiguration(); assertThat(configuration.getSettings() .stream() - .filter(setting -> "option".equals(setting.getName())) + .filter((setting) -> "option".equals(setting.getName())) .map(MavenPlugin.Setting::getValue)) .containsExactlyInAnyOrder("all-open:annotation=javax.persistence.Entity", "all-open:annotation=javax.persistence.MappedSuperclass", From 6f8b889cf120929aaeab6eed7eb8fb24058e3d0f Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Fri, 11 Oct 2024 00:34:35 +0900 Subject: [PATCH 21/24] Update to no support javax --- .../KotlinJpaGradleBuildCustomizer.java | 32 +++++++------------ .../kotlin/KotlinJpaMavenBuildCustomizer.java | 24 +++----------- ...ationDefaultContributorsConfiguration.java | 14 ++++++-- 3 files changed, 27 insertions(+), 43 deletions(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java index 5beaa187b6..959ebbba56 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizer.java @@ -36,10 +36,13 @@ public class KotlinJpaGradleBuildCustomizer implements BuildCustomizer plugin.setVersion(this.settings.getVersion())); - if (this.buildMetadataResolver.hasGroupId(build, "jakarta.persistence")) { - customizeAllOpenWithJakarta(build); - } - else if (this.buildMetadataResolver.hasGroupId(build, "javax.persistence")) { - customizeAllOpenWithJavax(build); - } + build.extensions().customize("allOpen", (allOpen) -> { + allOpen.invoke("annotation", quote("jakarta.persistence.Entity")); + allOpen.invoke("annotation", quote("jakarta.persistence.MappedSuperclass")); + allOpen.invoke("annotation", quote("jakarta.persistence.Embeddable")); + }); } } - private void customizeAllOpenWithJakarta(GradleBuild build) { - build.extensions().customize("allOpen", (allOpen) -> { - allOpen.invoke("annotation", "jakarta.persistence.Entity"); - allOpen.invoke("annotation", "jakarta.persistence.MappedSuperclass"); - allOpen.invoke("annotation", "jakarta.persistence.Embeddable"); - }); - } - - private void customizeAllOpenWithJavax(GradleBuild build) { - build.extensions().customize("allOpen", (allOpen) -> { - allOpen.invoke("annotation", "javax.persistence.Entity"); - allOpen.invoke("annotation", "javax.persistence.MappedSuperclass"); - allOpen.invoke("annotation", "javax.persistence.Embeddable"); - }); + private String quote(String element) { + return this.quote + element + this.quote; } } diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java index 33e6fbf970..ea16771b1d 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java @@ -17,7 +17,6 @@ package io.spring.initializr.generator.spring.code.kotlin; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; -import io.spring.initializr.generator.buildsystem.maven.MavenPlugin; import io.spring.initializr.generator.project.ProjectDescription; import io.spring.initializr.generator.spring.build.BuildCustomizer; import io.spring.initializr.generator.spring.build.BuildMetadataResolver; @@ -46,28 +45,15 @@ public void customize(MavenBuild build) { kotlinPlugin.configuration((configuration) -> { configuration.configure("compilerPlugins", (compilerPlugins) -> compilerPlugins.add("plugin", "jpa")); - if (this.buildMetadataResolver.hasGroupId(build, "jakarta.persistence")) { - customizeAllOpenWithJakarta(configuration); - } - else if (this.buildMetadataResolver.hasGroupId(build, "javax.persistence")) { - customizeAllOpenWithJavax(configuration); - } + configuration.configure("pluginOptions", (option) -> { + option.add("option", "all-open:annotation=jakarta.persistence.Entity"); + option.add("option", "all-open:annotation=jakarta.persistence.MappedSuperclass"); + option.add("option", "all-open:annotation=jakarta.persistence.Embeddable"); + }); }); kotlinPlugin.dependency("org.jetbrains.kotlin", "kotlin-maven-noarg", "${kotlin.version}"); }); } } - private void customizeAllOpenWithJakarta(MavenPlugin.ConfigurationBuilder option) { - option.add("option", "all-open:annotation=jakarta.persistence.Entity"); - option.add("option", "all-open:annotation=jakarta.persistence.MappedSuperclass"); - option.add("option", "all-open:annotation=jakarta.persistence.Embeddable"); - } - - private void customizeAllOpenWithJavax(MavenPlugin.ConfigurationBuilder option) { - option.add("option", "all-open:annotation=javax.persistence.Entity"); - option.add("option", "all-open:annotation=javax.persistence.MappedSuperclass"); - option.add("option", "all-open:annotation=javax.persistence.Embeddable"); - } - } diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinProjectGenerationDefaultContributorsConfiguration.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinProjectGenerationDefaultContributorsConfiguration.java index 4a933aeb24..6bb36e4a81 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinProjectGenerationDefaultContributorsConfiguration.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinProjectGenerationDefaultContributorsConfiguration.java @@ -47,6 +47,7 @@ * @author Stephane Nicoll * @author Jean-Baptiste Nizet * @author Moritz Halbritter + * @author Sijun Yang */ @Configuration class KotlinProjectGenerationDefaultContributorsConfiguration { @@ -67,10 +68,17 @@ BuildCustomizer kotlinDependenciesConfigurer() { } @Bean - @ConditionalOnBuildSystem(GradleBuildSystem.ID) - KotlinJpaGradleBuildCustomizer kotlinJpaGradleBuildCustomizer(InitializrMetadata metadata, + @ConditionalOnBuildSystem(value = GradleBuildSystem.ID, dialect = GradleBuildSystem.DIALECT_KOTLIN) + KotlinJpaGradleBuildCustomizer kotlinJpaGradleBuildCustomizerKotlinDsl(InitializrMetadata metadata, + KotlinProjectSettings settings, ProjectDescription projectDescription) { + return new KotlinJpaGradleBuildCustomizer(metadata, settings, projectDescription, '\"'); + } + + @Bean + @ConditionalOnBuildSystem(value = GradleBuildSystem.ID, dialect = GradleBuildSystem.DIALECT_GROOVY) + KotlinJpaGradleBuildCustomizer kotlinJpaGradleBuildCustomizerGroovyDsl(InitializrMetadata metadata, KotlinProjectSettings settings, ProjectDescription projectDescription) { - return new KotlinJpaGradleBuildCustomizer(metadata, settings, projectDescription); + return new KotlinJpaGradleBuildCustomizer(metadata, settings, projectDescription, '\''); } @Bean From c5986c9ee0e0339e3ae473a6f5a79f127bf3ed10 Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Fri, 11 Oct 2024 00:51:15 +0900 Subject: [PATCH 22/24] Fix Tests --- .../KotlinJpaGradleBuildCustomizerTests.java | 31 ++++-------- .../KotlinJpaMavenBuildCustomizerTests.java | 50 +++++++++---------- 2 files changed, 34 insertions(+), 47 deletions(-) diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java index ab8639d414..3531ff0de5 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java @@ -62,38 +62,27 @@ void customizeWhenJpaFacetAbsentShouldNotAddKotlinJpaPlugin() { } @Test - void customizeWhenJakartaPersistencePresentShouldCustomizeAllOpenWithJakarta() { - Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api"); + void customizeWhenJpaFacetPresentShouldCustomizeAllOpen() { + Dependency dependency = Dependency.withId("foo"); dependency.setFacets(Collections.singletonList("jpa")); GradleBuild build = getCustomizedBuild(dependency); - assertThat(build.plugins().values()).singleElement() - .satisfies((plugin) -> assertThat(plugin.getId()).isEqualTo("org.jetbrains.kotlin.plugin.jpa")); assertThat(build.extensions().values()).singleElement().satisfies((extension) -> { assertThat(extension.getName()).isEqualTo("allOpen"); assertThat(extension.getInvocations()) .filteredOn((invocation) -> Objects.equals(invocation.getTarget(), "annotation")) .extracting("arguments") - .containsExactlyInAnyOrder(List.of("jakarta.persistence.Entity"), - List.of("jakarta.persistence.MappedSuperclass"), List.of("jakarta.persistence.Embeddable")); + .containsExactlyInAnyOrder(List.of("\"jakarta.persistence.Entity\""), + List.of("\"jakarta.persistence.MappedSuperclass\""), + List.of("\"jakarta.persistence.Embeddable\"")); }); } @Test - void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() { - Dependency dependency = Dependency.withId("foo", "javax.persistence", "javax.persistence-api"); - dependency.setFacets(Collections.singletonList("jpa")); + void customizeWhenJpaFacetAbsentShouldNotCustomizeAllOpen() { + Dependency dependency = Dependency.withId("foo"); GradleBuild build = getCustomizedBuild(dependency); - assertThat(build.plugins().values()).singleElement() - .satisfies((plugin) -> assertThat(plugin.getId()).isEqualTo("org.jetbrains.kotlin.plugin.jpa")); - assertThat(build.extensions().values()).singleElement().satisfies((extension) -> { - assertThat(extension.getName()).isEqualTo("allOpen"); - assertThat(extension.getInvocations()) - .filteredOn((invocation) -> Objects.equals(invocation.getTarget(), "annotation")) - .extracting("arguments") - .containsExactlyInAnyOrder(List.of("javax.persistence.Entity"), - List.of("javax.persistence.MappedSuperclass"), List.of("javax.persistence.Embeddable")); - }); - + assertThat(build.extensions().values()).filteredOn(a -> Objects.equals(a.getName(), "allOpen")).isEmpty(); + assertThat(build.extensions().values()).isEmpty(); } private GradleBuild getCustomizedBuild(Dependency dependency) { @@ -104,7 +93,7 @@ private GradleBuild getCustomizedBuild(Dependency dependency) { MutableProjectDescription projectDescription = new MutableProjectDescription(); projectDescription.setPlatformVersion(Version.parse("1.0.0")); KotlinJpaGradleBuildCustomizer customizer = new KotlinJpaGradleBuildCustomizer(metadata, settings, - projectDescription); + projectDescription, '\"'); GradleBuild build = new GradleBuild(new MetadataBuildItemResolver(metadata, Version.parse("2.0.0.RELEASE"))); build.dependencies().add("foo"); customizer.customize(build); diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java index 5e42c807df..7d91926b3f 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java @@ -17,6 +17,7 @@ package io.spring.initializr.generator.spring.code.kotlin; import java.util.Collections; +import java.util.List; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin; @@ -31,6 +32,13 @@ import static org.assertj.core.api.Assertions.assertThat; +/** + * Tests for {@link KotlinJpaMavenBuildCustomizer}. + * + * @author Madhura Bhave + * @author Sebastien Deleuze + * @author Sijun Yang + */ class KotlinJpaMavenBuildCustomizerTests { @Test @@ -62,20 +70,24 @@ void customizeWhenJpaFacetAbsentShouldNotAddKotlinJpaPlugin() { } @Test - void customizeWhenJakartaPersistencePresentShouldCustomizeAllOpenWithJakarta() { - Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api"); + void customizeWhenJpaFacetPresentShouldCustomizeAllOpen() { + Dependency dependency = Dependency.withId("foo"); dependency.setFacets(Collections.singletonList("jpa")); MavenBuild build = getCustomizedBuild(dependency); - assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { - assertThat(plugin.getGroupId()).isEqualTo("org.jetbrains.kotlin"); - assertThat(plugin.getArtifactId()).isEqualTo("kotlin-maven-plugin"); - }); + assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { MavenPlugin.Configuration configuration = plugin.getConfiguration(); - assertThat(configuration.getSettings() + + assertThat(configuration.getSettings()).filteredOn(setting -> setting.getName().equals("pluginOptions")) + .isNotEmpty(); + var a = configuration.getSettings() .stream() - .filter((setting) -> "option".equals(setting.getName())) - .map(MavenPlugin.Setting::getValue)) + .filter(setting -> setting.getName().equals("pluginOptions")) + .findFirst() + .get(); + assertThat(((List) a.getValue())) + .filteredOn(setting -> setting.getName().equals("option")) + .map(MavenPlugin.Setting::getValue) .containsExactlyInAnyOrder("all-open:annotation=jakarta.persistence.Entity", "all-open:annotation=jakarta.persistence.MappedSuperclass", "all-open:annotation=jakarta.persistence.Embeddable"); @@ -83,24 +95,10 @@ void customizeWhenJakartaPersistencePresentShouldCustomizeAllOpenWithJakarta() { } @Test - void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() { - Dependency dependency = Dependency.withId("foo", "javax.persistence", "javax.persistence-api"); - dependency.setFacets(Collections.singletonList("jpa")); + void customizeWhenJpaFacetAbsentShouldNotCustomizeAllOpen() { + Dependency dependency = Dependency.withId("foo"); MavenBuild build = getCustomizedBuild(dependency); - assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { - assertThat(plugin.getGroupId()).isEqualTo("org.jetbrains.kotlin"); - assertThat(plugin.getArtifactId()).isEqualTo("kotlin-maven-plugin"); - }); - assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { - MavenPlugin.Configuration configuration = plugin.getConfiguration(); - assertThat(configuration.getSettings() - .stream() - .filter((setting) -> "option".equals(setting.getName())) - .map(MavenPlugin.Setting::getValue)) - .containsExactlyInAnyOrder("all-open:annotation=javax.persistence.Entity", - "all-open:annotation=javax.persistence.MappedSuperclass", - "all-open:annotation=javax.persistence.Embeddable"); - }); + assertThat(build.plugins().values()).isEmpty(); } private MavenBuild getCustomizedBuild(Dependency dependency) { From 1f4499462cfe761f38c83412674baac0f9766bd0 Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Fri, 11 Oct 2024 01:12:12 +0900 Subject: [PATCH 23/24] Chore --- .../KotlinJpaGradleBuildCustomizerTests.java | 4 +++- .../KotlinJpaMavenBuildCustomizerTests.java | 23 ++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java index 3531ff0de5..666254153d 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaGradleBuildCustomizerTests.java @@ -81,7 +81,9 @@ void customizeWhenJpaFacetPresentShouldCustomizeAllOpen() { void customizeWhenJpaFacetAbsentShouldNotCustomizeAllOpen() { Dependency dependency = Dependency.withId("foo"); GradleBuild build = getCustomizedBuild(dependency); - assertThat(build.extensions().values()).filteredOn(a -> Objects.equals(a.getName(), "allOpen")).isEmpty(); + assertThat(build.extensions().values()) + .filteredOn((extension) -> Objects.equals(extension.getName(), "allOpen")) + .isEmpty(); assertThat(build.extensions().values()).isEmpty(); } diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java index 7d91926b3f..91e1172afb 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java @@ -18,6 +18,7 @@ import java.util.Collections; import java.util.List; +import java.util.Objects; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin; @@ -78,19 +79,15 @@ void customizeWhenJpaFacetPresentShouldCustomizeAllOpen() { assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { MavenPlugin.Configuration configuration = plugin.getConfiguration(); - assertThat(configuration.getSettings()).filteredOn(setting -> setting.getName().equals("pluginOptions")) - .isNotEmpty(); - var a = configuration.getSettings() - .stream() - .filter(setting -> setting.getName().equals("pluginOptions")) - .findFirst() - .get(); - assertThat(((List) a.getValue())) - .filteredOn(setting -> setting.getName().equals("option")) - .map(MavenPlugin.Setting::getValue) - .containsExactlyInAnyOrder("all-open:annotation=jakarta.persistence.Entity", - "all-open:annotation=jakarta.persistence.MappedSuperclass", - "all-open:annotation=jakarta.persistence.Embeddable"); + assertThat(configuration.getSettings()).filteredOn((setting) -> setting.getName().equals("pluginOptions")) + .isNotEmpty() + .first() + .satisfies((pluginOptions) -> assertThat(((List) pluginOptions.getValue())) + .filteredOn((option) -> Objects.equals(option.getName(), "option")) + .map(MavenPlugin.Setting::getValue) + .containsExactlyInAnyOrder("all-open:annotation=jakarta.persistence.Entity", + "all-open:annotation=jakarta.persistence.MappedSuperclass", + "all-open:annotation=jakarta.persistence.Embeddable")); }); } From 59c4588dfc2f127c3c46d1ff30c3dfb25ebf190c Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Fri, 11 Oct 2024 01:14:44 +0900 Subject: [PATCH 24/24] Chore --- .../spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java index 91e1172afb..0ef96c344c 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 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.