Merge pull request #728 from ruifigueira

* pr/728:
  Polish "Enable kotlin jpa plugin if necessary"
  Enable kotlin jpa plugin if necessary
This commit is contained in:
Stephane Nicoll 2018-09-28 15:35:14 -04:00
commit 495ac3213c
7 changed files with 109 additions and 0 deletions

View File

@ -467,6 +467,9 @@ public class ProjectGenerator {
// Java versions
model.put("java8OrLater", isJava8OrLater(request));
// Facets
request.getFacets().forEach((facet) -> model.put("facets." + facet, true));
// Append the project request to the model
BeanWrapperImpl bean = new BeanWrapperImpl(request);
for (PropertyDescriptor descriptor : bean.getPropertyDescriptors()) {

View File

@ -304,6 +304,14 @@ public class ProjectRequest extends BasicProjectRequest {
this.resolvedDependencies.add(root);
}
/**
* 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 web facet enabled.
* @return {@code true} if the project has the web facet

View File

@ -19,6 +19,9 @@ buildscript {
{{#kotlin}}
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
{{#facets.jpa}}
classpath("org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}")
{{/facets.jpa}}
{{/kotlin}}
}
}
@ -26,6 +29,9 @@ buildscript {
apply plugin: '{{language}}'
{{#kotlin}}
apply plugin: 'kotlin-spring'
{{#facets.jpa}}
apply plugin: 'kotlin-jpa'
{{/facets.jpa}}
{{/kotlin}}
{{#war}}
apply plugin: 'eclipse-wtp'

View File

@ -195,6 +195,9 @@
</args>
<compilerPlugins>
<plugin>spring</plugin>
{{#facets.jpa}}
<plugin>jpa</plugin>
{{/facets.jpa}}
</compilerPlugins>
{{^kotlinSupport}}
{{#java8OrLater}}
@ -226,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}}

View File

@ -960,4 +960,71 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
}
}
@Test
public void kotlinWithMavenUseJpaFacetHasJpaKotlinPlugin() {
applyJpaMetadata(true);
ProjectRequest request = createProjectRequest("data-jpa");
request.setType("maven-project");
request.setLanguage("kotlin");
generateMavenPom(request).contains("<plugin>jpa</plugin>")
.contains("kotlin-maven-noarg");
}
@Test
public void kotlinWithMavenWithoutJpaFacetDoesNotHaveJpaKotlinPlugin() {
applyJpaMetadata(false);
ProjectRequest request = createProjectRequest("data-jpa");
request.setType("maven-project");
request.setLanguage("kotlin");
generateMavenPom(request).doesNotContain("<plugin>jpa</plugin>")
.doesNotContain("kotlin-maven-noarg");
}
@Test
public void javaWithMavenUseJpaFacetDoesNotHaveJpaKotlinPlugin() {
applyJpaMetadata(true);
ProjectRequest request = createProjectRequest("data-jpa");
request.setType("maven-project");
request.setLanguage("java");
generateMavenPom(request).doesNotContain("<plugin>jpa</plugin>")
.doesNotContain("kotlin-maven-noarg");
}
@Test
public void kotlinWithGradleUseJpaFacetHasJpaKotlinPlugin() {
applyJpaMetadata(true);
ProjectRequest request = createProjectRequest("data-jpa");
request.setType("gradle-project");
request.setLanguage("kotlin");
generateGradleBuild(request).contains("apply plugin: 'kotlin-jpa'");
}
@Test
public void kotlinWithGradleWithoutJpaFacetDoesNotHaveJpaKotlinPlugin() {
applyJpaMetadata(false);
ProjectRequest request = createProjectRequest("data-jpa");
request.setType("gradle-project");
request.setLanguage("kotlin");
generateGradleBuild(request).doesNotContain("apply plugin: 'kotlin-jpa'");
}
@Test
public void javaWithGradleUseJpaFacetDoesNotHaveJpaKotlinPlugin() {
applyJpaMetadata(true);
ProjectRequest request = createProjectRequest("data-jpa");
request.setType("gradle-project");
request.setLanguage("java");
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);
}
}

View File

@ -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");
@ -91,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))

View File

@ -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: