mirror of
https://gitee.com/dcren/initializr.git
synced 2026-02-25 21:22:58 +08:00
Enable kotlin jpa plugin if necessary
This commit add the jpa kotlin plugin in the generated project when a dependencies has the jpa facet. See gh-728
This commit is contained in:
committed by
Stephane Nicoll
parent
282b7a9916
commit
5f79f9a0fe
@@ -467,6 +467,11 @@ public class ProjectGenerator {
|
||||
// Java versions
|
||||
model.put("java8OrLater", isJava8OrLater(request));
|
||||
|
||||
// Has JPA facet
|
||||
if (request.hasJpaFacet()) {
|
||||
model.put("jpaFacet", true);
|
||||
}
|
||||
|
||||
// Append the project request to the model
|
||||
BeanWrapperImpl bean = new BeanWrapperImpl(request);
|
||||
for (PropertyDescriptor descriptor : bean.getPropertyDescriptors()) {
|
||||
|
||||
@@ -312,6 +312,14 @@ public class ProjectRequest extends BasicProjectRequest {
|
||||
return hasFacet("web");
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if this request has the jpa facet enabled.
|
||||
* @return {@code true} if the project has the jpa facet
|
||||
*/
|
||||
public boolean hasJpaFacet() {
|
||||
return hasFacet("jpa");
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if this request has the specified facet enabled.
|
||||
* @param facet the facet to check
|
||||
|
||||
@@ -19,6 +19,9 @@ buildscript {
|
||||
{{#kotlin}}
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
|
||||
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
|
||||
{{#jpaFacet}}
|
||||
classpath("org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}")
|
||||
{{/jpaFacet}}
|
||||
{{/kotlin}}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +29,9 @@ buildscript {
|
||||
apply plugin: '{{language}}'
|
||||
{{#kotlin}}
|
||||
apply plugin: 'kotlin-spring'
|
||||
{{#jpaFacet}}
|
||||
apply plugin: 'kotlin-jpa'
|
||||
{{/jpaFacet}}
|
||||
{{/kotlin}}
|
||||
{{#war}}
|
||||
apply plugin: 'eclipse-wtp'
|
||||
|
||||
@@ -195,6 +195,9 @@
|
||||
</args>
|
||||
<compilerPlugins>
|
||||
<plugin>spring</plugin>
|
||||
{{#jpaFacet}}
|
||||
<plugin>jpa</plugin>
|
||||
{{/jpaFacet}}
|
||||
</compilerPlugins>
|
||||
{{^kotlinSupport}}
|
||||
{{#java8OrLater}}
|
||||
|
||||
@@ -960,4 +960,92 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kotlinWithMavenUseJpaFacetHasJpaKotlinPlugin() {
|
||||
Dependency jpa = Dependency.withId("data-jpa");
|
||||
jpa.setFacets(Collections.singletonList("jpa"));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("data-jpa", jpa).build();
|
||||
applyMetadata(metadata);
|
||||
|
||||
ProjectRequest request = createProjectRequest("data-jpa");
|
||||
request.setType("maven-project");
|
||||
request.setLanguage("kotlin");
|
||||
assertThat(generateMavenPom(request).getMavenPom())
|
||||
.contains("<plugin>jpa</plugin>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kotlinWithMavenWithoutJpaFacetDoesNotHaveJpaKotlinPlugin() {
|
||||
Dependency jpa = Dependency.withId("data-jpa");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("data-jpa", jpa).build();
|
||||
applyMetadata(metadata);
|
||||
|
||||
ProjectRequest request = createProjectRequest("data-jpa");
|
||||
request.setType("maven-project");
|
||||
request.setLanguage("kotlin");
|
||||
assertThat(generateMavenPom(request).getMavenPom())
|
||||
.doesNotContain("<plugin>jpa</plugin>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void javaWithMavenUseJpaFacetDoesNotHaveJpaKotlinPlugin() {
|
||||
Dependency jpa = Dependency.withId("data-jpa");
|
||||
jpa.setFacets(Collections.singletonList("jpa"));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("data-jpa", jpa).build();
|
||||
applyMetadata(metadata);
|
||||
|
||||
ProjectRequest request = createProjectRequest("data-jpa");
|
||||
request.setType("maven-project");
|
||||
request.setLanguage("java");
|
||||
assertThat(generateMavenPom(request).getMavenPom())
|
||||
.doesNotContain("<plugin>jpa</plugin>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kotlinWithGradleUseJpaFacetHasJpaKotlinPlugin() {
|
||||
Dependency jpa = Dependency.withId("data-jpa");
|
||||
jpa.setFacets(Collections.singletonList("jpa"));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("data-jpa", jpa).build();
|
||||
applyMetadata(metadata);
|
||||
|
||||
ProjectRequest request = createProjectRequest("data-jpa");
|
||||
request.setType("gradle-project");
|
||||
request.setLanguage("kotlin");
|
||||
assertThat(generateGradleBuild(request).getGradleBuild())
|
||||
.contains("apply plugin: 'kotlin-jpa'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kotlinWithGradleWithoutJpaFacetDoesNotHaveJpaKotlinPlugin() {
|
||||
Dependency jpa = Dependency.withId("data-jpa");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("data-jpa", jpa).build();
|
||||
applyMetadata(metadata);
|
||||
|
||||
ProjectRequest request = createProjectRequest("data-jpa");
|
||||
request.setType("gradle-project");
|
||||
request.setLanguage("kotlin");
|
||||
assertThat(generateGradleBuild(request).getGradleBuild())
|
||||
.doesNotContain("apply plugin: 'kotlin-jpa'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void javaWithGradleUseJpaFacetDoesNotHaveJpaKotlinPlugin() {
|
||||
Dependency jpa = Dependency.withId("data-jpa");
|
||||
jpa.setFacets(Collections.singletonList("jpa"));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("data-jpa", jpa).build();
|
||||
applyMetadata(metadata);
|
||||
|
||||
ProjectRequest request = createProjectRequest("data-jpa");
|
||||
request.setType("gradle-project");
|
||||
request.setLanguage("java");
|
||||
assertThat(generateGradleBuild(request).getGradleBuild())
|
||||
.doesNotContain("apply plugin: 'kotlin-jpa'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class PomAssert {
|
||||
|
||||
private final String content;
|
||||
|
||||
private final XpathEngine eng;
|
||||
|
||||
private final Document doc;
|
||||
@@ -61,6 +63,7 @@ public class PomAssert {
|
||||
private final Map<String, Repository> repositories = new LinkedHashMap<>();
|
||||
|
||||
public PomAssert(String content) {
|
||||
this.content = content;
|
||||
this.eng = XMLUnit.newXpathEngine();
|
||||
Map<String, String> context = new LinkedHashMap<>();
|
||||
context.put("pom", "http://maven.apache.org/POM/4.0.0");
|
||||
@@ -298,6 +301,10 @@ public class PomAssert {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getMavenPom() {
|
||||
return this.content;
|
||||
}
|
||||
|
||||
private PomAssert hasPluginRepository(String name) {
|
||||
NodeList nodes;
|
||||
try {
|
||||
|
||||
@@ -481,6 +481,8 @@ initializr:
|
||||
id: data-jpa
|
||||
description: Java Persistence API including spring-data-jpa, spring-orm and Hibernate
|
||||
weight: 100
|
||||
facets:
|
||||
- jpa
|
||||
aliases:
|
||||
- jpa
|
||||
links:
|
||||
|
||||
Reference in New Issue
Block a user