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
7 changed files with 109 additions and 0 deletions

View File

@@ -467,6 +467,9 @@ public class ProjectGenerator {
// Java versions // Java versions
model.put("java8OrLater", isJava8OrLater(request)); model.put("java8OrLater", isJava8OrLater(request));
// Facets
request.getFacets().forEach((facet) -> model.put("facets." + facet, 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);
for (PropertyDescriptor descriptor : bean.getPropertyDescriptors()) { for (PropertyDescriptor descriptor : bean.getPropertyDescriptors()) {

View File

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

View File

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

View File

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

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 { public class PomAssert {
private final String content;
private final XpathEngine eng; private final XpathEngine eng;
private final Document doc; private final Document doc;
@@ -61,6 +63,7 @@ public class PomAssert {
private final Map<String, Repository> repositories = new LinkedHashMap<>(); private final Map<String, Repository> repositories = new LinkedHashMap<>();
public PomAssert(String content) { public PomAssert(String content) {
this.content = content;
this.eng = XMLUnit.newXpathEngine(); this.eng = XMLUnit.newXpathEngine();
Map<String, String> context = new LinkedHashMap<>(); Map<String, String> context = new LinkedHashMap<>();
context.put("pom", "http://maven.apache.org/POM/4.0.0"); context.put("pom", "http://maven.apache.org/POM/4.0.0");
@@ -91,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))

View File

@@ -481,6 +481,8 @@ initializr:
id: data-jpa id: data-jpa
description: Java Persistence API including spring-data-jpa, spring-orm and Hibernate description: Java Persistence API including spring-data-jpa, spring-orm and Hibernate
weight: 100 weight: 100
facets:
- jpa
aliases: aliases:
- jpa - jpa
links: links: