-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Configuration for Kotlin's All-Open Plugin for JPA Entities #1576
Changes from 20 commits
17d5995
a83a718
f17b215
b4b8ab4
0fad955
0c2ff7f
3ebc0ac
f4134b9
86d15da
ec2e609
fe148e5
706aaf5
e7e48f5
a9837f9
301c356
4ad7dd4
90b8c5b
5779e8a
b1fd50b
a985271
6f8b889
c5986c9
1f44994
59c4588
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -28,6 +29,7 @@ | |
* | ||
* @author Madhura Bhave | ||
* @author Sebastien Deleuze | ||
* @author Sijun Yang | ||
*/ | ||
public class KotlinJpaMavenBuildCustomizer implements BuildCustomizer<MavenBuild> { | ||
|
||
|
@@ -41,11 +43,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")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to support JavaEE anymore. |
||
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"); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
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; | ||
|
@@ -35,6 +37,7 @@ | |
* Tests for {@link KotlinJpaGradleBuildCustomizer}. | ||
* | ||
* @author Madhura Bhave | ||
* @author Sijun Yang | ||
*/ | ||
class KotlinJpaGradleBuildCustomizerTests { | ||
|
||
|
@@ -58,6 +61,41 @@ void customizeWhenJpaFacetAbsentShouldNotAddKotlinJpaPlugin() { | |
assertThat(build.plugins().values()).isEmpty(); | ||
} | ||
|
||
@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"), | ||
List.of("jakarta.persistence.MappedSuperclass"), List.of("jakarta.persistence.Embeddable")); | ||
}); | ||
} | ||
|
||
@Test | ||
void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to support JavaEE anymore. |
||
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"), | ||
List.of("javax.persistence.MappedSuperclass"), List.of("javax.persistence.Embeddable")); | ||
}); | ||
|
||
} | ||
|
||
private GradleBuild getCustomizedBuild(Dependency dependency) { | ||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() | ||
.addDependencyGroup("test", dependency) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you remove this? |
||
* Tests for {@link KotlinJpaMavenBuildCustomizer}. | ||
* | ||
* @author Madhura Bhave | ||
* @author Sebastien Deleuze | ||
*/ | ||
class KotlinJpaMavenBuildCustomizerTests { | ||
|
||
@Test | ||
|
@@ -67,6 +61,48 @@ 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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to support JavaEE anymore. |
||
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to support JavaEE anymore. Our baseline is Spring Boot 3.2, which already uses JakartaEE.