mirror of
https://gitee.com/dcren/initializr.git
synced 2026-09-19 06:17:42 +08:00
Polish "Enable kotlin jpa plugin if necessary"
Closes gh-728
This commit is contained in:
+2
-4
@@ -467,10 +467,8 @@ public class ProjectGenerator {
|
|||||||
// Java versions
|
// Java versions
|
||||||
model.put("java8OrLater", isJava8OrLater(request));
|
model.put("java8OrLater", isJava8OrLater(request));
|
||||||
|
|
||||||
// Has JPA facet
|
// Facets
|
||||||
if (request.hasJpaFacet()) {
|
request.getFacets().forEach((facet) -> model.put("facets." + facet, true));
|
||||||
model.put("jpaFacet", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Append the project request to the model
|
// Append the project request to the model
|
||||||
BeanWrapperImpl bean = new BeanWrapperImpl(request);
|
BeanWrapperImpl bean = new BeanWrapperImpl(request);
|
||||||
|
|||||||
+8
-8
@@ -304,14 +304,6 @@ public class ProjectRequest extends BasicProjectRequest {
|
|||||||
this.resolvedDependencies.add(root);
|
this.resolvedDependencies.add(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Specify if this request has the web facet enabled.
|
|
||||||
* @return {@code true} if the project has the web facet
|
|
||||||
*/
|
|
||||||
public boolean hasWebFacet() {
|
|
||||||
return hasFacet("web");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify if this request has the jpa facet enabled.
|
* Specify if this request has the jpa facet enabled.
|
||||||
* @return {@code true} if the project has the jpa facet
|
* @return {@code true} if the project has the jpa facet
|
||||||
@@ -320,6 +312,14 @@ public class ProjectRequest extends BasicProjectRequest {
|
|||||||
return hasFacet("jpa");
|
return hasFacet("jpa");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify if this request has the web facet enabled.
|
||||||
|
* @return {@code true} if the project has the web facet
|
||||||
|
*/
|
||||||
|
public boolean hasWebFacet() {
|
||||||
|
return hasFacet("web");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify if this request has the specified facet enabled.
|
* Specify if this request has the specified facet enabled.
|
||||||
* @param facet the facet to check
|
* @param facet the facet to check
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ buildscript {
|
|||||||
{{#kotlin}}
|
{{#kotlin}}
|
||||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
|
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
|
||||||
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
|
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
|
||||||
{{#jpaFacet}}
|
{{#facets.jpa}}
|
||||||
classpath("org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}")
|
classpath("org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}")
|
||||||
{{/jpaFacet}}
|
{{/facets.jpa}}
|
||||||
{{/kotlin}}
|
{{/kotlin}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,9 +29,9 @@ buildscript {
|
|||||||
apply plugin: '{{language}}'
|
apply plugin: '{{language}}'
|
||||||
{{#kotlin}}
|
{{#kotlin}}
|
||||||
apply plugin: 'kotlin-spring'
|
apply plugin: 'kotlin-spring'
|
||||||
{{#jpaFacet}}
|
{{#facets.jpa}}
|
||||||
apply plugin: 'kotlin-jpa'
|
apply plugin: 'kotlin-jpa'
|
||||||
{{/jpaFacet}}
|
{{/facets.jpa}}
|
||||||
{{/kotlin}}
|
{{/kotlin}}
|
||||||
{{#war}}
|
{{#war}}
|
||||||
apply plugin: 'eclipse-wtp'
|
apply plugin: 'eclipse-wtp'
|
||||||
|
|||||||
@@ -195,9 +195,9 @@
|
|||||||
</args>
|
</args>
|
||||||
<compilerPlugins>
|
<compilerPlugins>
|
||||||
<plugin>spring</plugin>
|
<plugin>spring</plugin>
|
||||||
{{#jpaFacet}}
|
{{#facets.jpa}}
|
||||||
<plugin>jpa</plugin>
|
<plugin>jpa</plugin>
|
||||||
{{/jpaFacet}}
|
{{/facets.jpa}}
|
||||||
</compilerPlugins>
|
</compilerPlugins>
|
||||||
{{^kotlinSupport}}
|
{{^kotlinSupport}}
|
||||||
{{#java8OrLater}}
|
{{#java8OrLater}}
|
||||||
@@ -229,6 +229,13 @@
|
|||||||
<artifactId>kotlin-maven-allopen</artifactId>
|
<artifactId>kotlin-maven-allopen</artifactId>
|
||||||
<version>${kotlin.version}</version>
|
<version>${kotlin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
{{#facets.jpa}}
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-maven-noarg</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
{{/facets.jpa}}
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
{{/kotlin}}
|
{{/kotlin}}
|
||||||
|
|||||||
+25
-46
@@ -962,90 +962,69 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void kotlinWithMavenUseJpaFacetHasJpaKotlinPlugin() {
|
public void kotlinWithMavenUseJpaFacetHasJpaKotlinPlugin() {
|
||||||
Dependency jpa = Dependency.withId("data-jpa");
|
applyJpaMetadata(true);
|
||||||
jpa.setFacets(Collections.singletonList("jpa"));
|
|
||||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
|
||||||
.addDependencyGroup("data-jpa", jpa).build();
|
|
||||||
applyMetadata(metadata);
|
|
||||||
|
|
||||||
ProjectRequest request = createProjectRequest("data-jpa");
|
ProjectRequest request = createProjectRequest("data-jpa");
|
||||||
request.setType("maven-project");
|
request.setType("maven-project");
|
||||||
request.setLanguage("kotlin");
|
request.setLanguage("kotlin");
|
||||||
assertThat(generateMavenPom(request).getMavenPom())
|
generateMavenPom(request).contains("<plugin>jpa</plugin>")
|
||||||
.contains("<plugin>jpa</plugin>");
|
.contains("kotlin-maven-noarg");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void kotlinWithMavenWithoutJpaFacetDoesNotHaveJpaKotlinPlugin() {
|
public void kotlinWithMavenWithoutJpaFacetDoesNotHaveJpaKotlinPlugin() {
|
||||||
Dependency jpa = Dependency.withId("data-jpa");
|
applyJpaMetadata(false);
|
||||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
|
||||||
.addDependencyGroup("data-jpa", jpa).build();
|
|
||||||
applyMetadata(metadata);
|
|
||||||
|
|
||||||
ProjectRequest request = createProjectRequest("data-jpa");
|
ProjectRequest request = createProjectRequest("data-jpa");
|
||||||
request.setType("maven-project");
|
request.setType("maven-project");
|
||||||
request.setLanguage("kotlin");
|
request.setLanguage("kotlin");
|
||||||
assertThat(generateMavenPom(request).getMavenPom())
|
generateMavenPom(request).doesNotContain("<plugin>jpa</plugin>")
|
||||||
.doesNotContain("<plugin>jpa</plugin>");
|
.doesNotContain("kotlin-maven-noarg");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void javaWithMavenUseJpaFacetDoesNotHaveJpaKotlinPlugin() {
|
public void javaWithMavenUseJpaFacetDoesNotHaveJpaKotlinPlugin() {
|
||||||
Dependency jpa = Dependency.withId("data-jpa");
|
applyJpaMetadata(true);
|
||||||
jpa.setFacets(Collections.singletonList("jpa"));
|
|
||||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
|
||||||
.addDependencyGroup("data-jpa", jpa).build();
|
|
||||||
applyMetadata(metadata);
|
|
||||||
|
|
||||||
ProjectRequest request = createProjectRequest("data-jpa");
|
ProjectRequest request = createProjectRequest("data-jpa");
|
||||||
request.setType("maven-project");
|
request.setType("maven-project");
|
||||||
request.setLanguage("java");
|
request.setLanguage("java");
|
||||||
assertThat(generateMavenPom(request).getMavenPom())
|
generateMavenPom(request).doesNotContain("<plugin>jpa</plugin>")
|
||||||
.doesNotContain("<plugin>jpa</plugin>");
|
.doesNotContain("kotlin-maven-noarg");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void kotlinWithGradleUseJpaFacetHasJpaKotlinPlugin() {
|
public void kotlinWithGradleUseJpaFacetHasJpaKotlinPlugin() {
|
||||||
Dependency jpa = Dependency.withId("data-jpa");
|
applyJpaMetadata(true);
|
||||||
jpa.setFacets(Collections.singletonList("jpa"));
|
|
||||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
|
||||||
.addDependencyGroup("data-jpa", jpa).build();
|
|
||||||
applyMetadata(metadata);
|
|
||||||
|
|
||||||
ProjectRequest request = createProjectRequest("data-jpa");
|
ProjectRequest request = createProjectRequest("data-jpa");
|
||||||
request.setType("gradle-project");
|
request.setType("gradle-project");
|
||||||
request.setLanguage("kotlin");
|
request.setLanguage("kotlin");
|
||||||
assertThat(generateGradleBuild(request).getGradleBuild())
|
generateGradleBuild(request).contains("apply plugin: 'kotlin-jpa'");
|
||||||
.contains("apply plugin: 'kotlin-jpa'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void kotlinWithGradleWithoutJpaFacetDoesNotHaveJpaKotlinPlugin() {
|
public void kotlinWithGradleWithoutJpaFacetDoesNotHaveJpaKotlinPlugin() {
|
||||||
Dependency jpa = Dependency.withId("data-jpa");
|
applyJpaMetadata(false);
|
||||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
|
||||||
.addDependencyGroup("data-jpa", jpa).build();
|
|
||||||
applyMetadata(metadata);
|
|
||||||
|
|
||||||
ProjectRequest request = createProjectRequest("data-jpa");
|
ProjectRequest request = createProjectRequest("data-jpa");
|
||||||
request.setType("gradle-project");
|
request.setType("gradle-project");
|
||||||
request.setLanguage("kotlin");
|
request.setLanguage("kotlin");
|
||||||
assertThat(generateGradleBuild(request).getGradleBuild())
|
generateGradleBuild(request).doesNotContain("apply plugin: 'kotlin-jpa'");
|
||||||
.doesNotContain("apply plugin: 'kotlin-jpa'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void javaWithGradleUseJpaFacetDoesNotHaveJpaKotlinPlugin() {
|
public void javaWithGradleUseJpaFacetDoesNotHaveJpaKotlinPlugin() {
|
||||||
Dependency jpa = Dependency.withId("data-jpa");
|
applyJpaMetadata(true);
|
||||||
jpa.setFacets(Collections.singletonList("jpa"));
|
|
||||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
|
||||||
.addDependencyGroup("data-jpa", jpa).build();
|
|
||||||
applyMetadata(metadata);
|
|
||||||
|
|
||||||
ProjectRequest request = createProjectRequest("data-jpa");
|
ProjectRequest request = createProjectRequest("data-jpa");
|
||||||
request.setType("gradle-project");
|
request.setType("gradle-project");
|
||||||
request.setLanguage("java");
|
request.setLanguage("java");
|
||||||
assertThat(generateGradleBuild(request).getGradleBuild())
|
generateGradleBuild(request).doesNotContain("apply plugin: 'kotlin-jpa'");
|
||||||
.doesNotContain("apply plugin: 'kotlin-jpa'");
|
}
|
||||||
|
|
||||||
|
private void applyJpaMetadata(boolean enableJpaFacet) {
|
||||||
|
Dependency jpa = Dependency.withId("data-jpa");
|
||||||
|
if (enableJpaFacet) {
|
||||||
|
jpa.setFacets(Collections.singletonList("jpa"));
|
||||||
|
}
|
||||||
|
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||||
|
.addDependencyGroup("data-jpa", jpa).build();
|
||||||
|
applyMetadata(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-4
@@ -94,6 +94,16 @@ public class PomAssert {
|
|||||||
.hasJavaVersion(request.getJavaVersion());
|
.hasJavaVersion(request.getJavaVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PomAssert contains(String expression) {
|
||||||
|
assertThat(this.content).contains(expression);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PomAssert doesNotContain(String expression) {
|
||||||
|
assertThat(this.content).doesNotContain(expression);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public PomAssert hasGroupId(String groupId) {
|
public PomAssert hasGroupId(String groupId) {
|
||||||
try {
|
try {
|
||||||
assertThat(this.eng.evaluate(createRootNodeXPath("groupId"), this.doc))
|
assertThat(this.eng.evaluate(createRootNodeXPath("groupId"), this.doc))
|
||||||
@@ -301,10 +311,6 @@ public class PomAssert {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMavenPom() {
|
|
||||||
return this.content;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PomAssert hasPluginRepository(String name) {
|
private PomAssert hasPluginRepository(String name) {
|
||||||
NodeList nodes;
|
NodeList nodes;
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user