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