Skip to content

Commit

Permalink
Apply 'all-open' plugin when generation Kotlin Maven projects with JPA
Browse files Browse the repository at this point in the history
Closes gh-1607
  • Loading branch information
mhalbritter committed Dec 20, 2024
1 parent 7c20fa3 commit bac7d31
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ 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"));
configuration.configure("compilerPlugins", (compilerPlugins) -> {
compilerPlugins.add("plugin", "jpa");
compilerPlugins.add("plugin", "all-open");
});
configuration.configure("pluginOptions", (option) -> {
option.add("option", "all-open:annotation=jakarta.persistence.Entity");
option.add("option", "all-open:annotation=jakarta.persistence.MappedSuperclass");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

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;
Expand All @@ -29,6 +28,7 @@
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.support.MetadataBuildItemResolver;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -76,19 +76,17 @@ void customizeWhenJpaFacetPresentShouldCustomizeAllOpen() {
Dependency dependency = Dependency.withId("foo");
dependency.setFacets(Collections.singletonList("jpa"));
MavenBuild build = getCustomizedBuild(dependency);

assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> {
MavenPlugin.Configuration configuration = plugin.getConfiguration();

assertThat(configuration.getSettings()).filteredOn((setting) -> setting.getName().equals("pluginOptions"))
.isNotEmpty()
.first()
.satisfies((pluginOptions) -> assertThat(((List<MavenPlugin.Setting>) 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"));
List<MavenPlugin.Setting> compilerPlugins = getSettingValue(plugin.getConfiguration(), "compilerPlugins");
assertThat(compilerPlugins).isNotNull()
.map(MavenPlugin.Setting::getValue)
.containsExactlyInAnyOrder("jpa", "all-open");
List<MavenPlugin.Setting> pluginOptions = getSettingValue(plugin.getConfiguration(), "pluginOptions");
assertThat(pluginOptions).map(MavenPlugin.Setting::getValue)
.containsExactlyInAnyOrder("all-open:annotation=jakarta.persistence.Entity",
"all-open:annotation=jakarta.persistence.MappedSuperclass",
"all-open:annotation=jakarta.persistence.Embeddable");
});
}

Expand All @@ -112,4 +110,15 @@ private MavenBuild getCustomizedBuild(Dependency dependency) {
return build;
}

@SuppressWarnings("unchecked")
private <T> T getSettingValue(MavenPlugin.Configuration configuration, String name) {
for (MavenPlugin.Setting setting : configuration.getSettings()) {
if (setting.getName().equals(name)) {
return (T) setting.getValue();
}
}
Assertions.fail("No setting with name '%s' found", name);
return null;
}

}

0 comments on commit bac7d31

Please sign in to comment.