Skip to content

Commit

Permalink
Merge pull request #26973 from mshima/java-dependencies
Browse files Browse the repository at this point in the history
add addJavaDefinitions api to sources.
  • Loading branch information
DanielFran authored Aug 14, 2024
2 parents ae6e831 + c8b2eac commit 92507ac
Show file tree
Hide file tree
Showing 11 changed files with 828 additions and 536 deletions.
55 changes: 27 additions & 28 deletions generators/cucumber/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,30 @@ export default class CucumberGenerator extends BaseApplicationGenerator {
return this.asPostWritingTaskGroup({
addDependencies({ application, source }) {
const { javaDependencies, gradleBuildSrc } = application;
source.addJavaDependencies?.(
[
{
groupId: 'io.cucumber',
artifactId: 'cucumber-bom',
version: javaDependencies!['cucumber-bom'],
type: 'pom',
scope: 'import',
},
{ groupId: 'io.cucumber', artifactId: 'cucumber-junit-platform-engine', scope: 'test' },
{ groupId: 'io.cucumber', artifactId: 'cucumber-java', scope: 'test' },
{ groupId: 'io.cucumber', artifactId: 'cucumber-spring', scope: 'test' },
{ groupId: 'org.junit.platform', artifactId: 'junit-platform-console', scope: 'test' },
{ groupId: 'org.testng', artifactId: 'testng', scope: 'test', version: javaDependencies!.testng },
],
source.addJavaDefinitions?.(
{ gradleFile: `${gradleBuildSrc}src/main/groovy/jhipster.cucumber-conventions.gradle` },
);

if (application.buildToolMaven) {
source.addMavenDefinition?.({
plugins: [{ groupId: 'org.apache.maven.plugins', artifactId: 'maven-antrun-plugin' }],
pluginManagement: [
{
dependencies: [
{
groupId: 'org.apache.maven.plugins',
artifactId: 'maven-antrun-plugin',
additionalContent: `
groupId: 'io.cucumber',
artifactId: 'cucumber-bom',
version: javaDependencies!['cucumber-bom'],
type: 'pom',
scope: 'import',
},
{ groupId: 'io.cucumber', artifactId: 'cucumber-junit-platform-engine', scope: 'test' },
{ groupId: 'io.cucumber', artifactId: 'cucumber-java', scope: 'test' },
{ groupId: 'io.cucumber', artifactId: 'cucumber-spring', scope: 'test' },
{ groupId: 'org.junit.platform', artifactId: 'junit-platform-console', scope: 'test' },
{ groupId: 'org.testng', artifactId: 'testng', scope: 'test', version: javaDependencies!.testng },
],
mavenDefinition: {
plugins: [{ groupId: 'org.apache.maven.plugins', artifactId: 'maven-antrun-plugin' }],
pluginManagement: [
{
groupId: 'org.apache.maven.plugins',
artifactId: 'maven-antrun-plugin',
additionalContent: `
<executions>
<execution>
<!--Work around. Surefire does not use JUnit's Test Engine discovery functionality -->
Expand Down Expand Up @@ -105,10 +103,11 @@ export default class CucumberGenerator extends BaseApplicationGenerator {
</execution>
</executions>
`,
},
],
});
}
},
],
},
},
);

if (application.buildToolGradle) {
source.addGradlePlugin?.({ id: 'jhipster.cucumber-conventions' });
Expand Down
26 changes: 23 additions & 3 deletions generators/java/generators/build-tool/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import BaseApplicationGenerator from '../../../base-application/index.js';
import { GENERATOR_GRADLE, GENERATOR_MAVEN } from '../../../generator-list.js';
import type { MavenDependency } from '../../../maven/types.js';
import { javaScopeToGradleScope } from '../../support/index.js';
import type { JavaDependency } from '../../types.js';
import type { ConditionalJavaDefinition, JavaDependency, JavaNeedleOptions } from '../../types.js';

const { GRADLE, MAVEN } = buildToolTypes;

Expand Down Expand Up @@ -109,7 +109,7 @@ export default class BuildToolGenerator extends BaseApplicationGenerator {
};

source.addJavaDefinition = (definition, options) => {
const { dependencies, versions } = definition;
const { dependencies, versions, mavenDefinition } = definition;
if (dependencies) {
source.addJavaDependencies!(
dependencies.filter(dep => {
Expand All @@ -128,7 +128,27 @@ export default class BuildToolGenerator extends BaseApplicationGenerator {
});
}
if (application.buildToolGradle) {
source.addGradleDependencyCatalogVersions?.(versions, options);
source.addGradleDependencyCatalogVersions!(versions, options);
}
}
if (application.buildToolMaven && mavenDefinition) {
source.addMavenDefinition!(mavenDefinition);
}
};

source.addJavaDefinitions = (
optionsOrDefinition: JavaNeedleOptions | ConditionalJavaDefinition,
...definitions: ConditionalJavaDefinition[]
) => {
let options: JavaNeedleOptions | undefined = undefined;
if ('gradleFile' in optionsOrDefinition || 'gradleVersionCatalogFile' in optionsOrDefinition) {
options = optionsOrDefinition;
} else {
definitions.unshift(optionsOrDefinition as ConditionalJavaDefinition);
}
for (const definition of definitions) {
if (definition.condition ?? true) {
source.addJavaDefinition!(definition, options);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,61 @@

exports[`generator - java:openapi-generator gradle-addOpenapiGeneratorPlugin(false) should call source snapshot 1`] = `
{
"addJavaDependencies": [
"addJavaDefinitions": [
[
{
"artifactId": "jackson-databind-nullable",
"groupId": "org.openapitools",
"version": "'JACKSON-DATABIND-NULLABLE-VERSION'",
"dependencies": [
{
"artifactId": "jackson-databind-nullable",
"groupId": "org.openapitools",
"version": "'JACKSON-DATABIND-NULLABLE-VERSION'",
},
],
},
{
"condition": false,
"mavenDefinition": {
"pluginManagement": [
{
"additionalContent": " <executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>\${project.basedir}/src/main/resources/swagger/api.yml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.mycompany.myapp.web.api</apiPackage>
<modelPackage>com.mycompany.myapp.service.api.dto</modelPackage>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<skipValidateSpec>false</skipValidateSpec>
<configOptions>
<delegatePattern>true</delegatePattern>
<title>jhipster</title>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>
</configuration>
</execution>
</executions>
",
"artifactId": "openapi-generator-maven-plugin",
"groupId": "org.openapitools",
"version": "\${openapi-generator-maven-plugin.version}",
},
],
"plugins": [
{
"artifactId": "openapi-generator-maven-plugin",
"groupId": "org.openapitools",
},
],
"properties": [
{
"property": "openapi-generator-maven-plugin.version",
"value": "'OPENAPI-GENERATOR-MAVEN-PLUGIN-VERSION'",
},
],
},
},
],
],
Expand Down Expand Up @@ -51,12 +100,61 @@ exports[`generator - java:openapi-generator gradle-addOpenapiGeneratorPlugin(tru
"id": "jhipster.openapi-generator-conventions",
},
],
"addJavaDependencies": [
"addJavaDefinitions": [
[
{
"artifactId": "jackson-databind-nullable",
"groupId": "org.openapitools",
"version": "'JACKSON-DATABIND-NULLABLE-VERSION'",
"dependencies": [
{
"artifactId": "jackson-databind-nullable",
"groupId": "org.openapitools",
"version": "'JACKSON-DATABIND-NULLABLE-VERSION'",
},
],
},
{
"condition": true,
"mavenDefinition": {
"pluginManagement": [
{
"additionalContent": " <executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>\${project.basedir}/src/main/resources/swagger/api.yml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.mycompany.myapp.web.api</apiPackage>
<modelPackage>com.mycompany.myapp.service.api.dto</modelPackage>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<skipValidateSpec>false</skipValidateSpec>
<configOptions>
<delegatePattern>true</delegatePattern>
<title>jhipster</title>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>
</configuration>
</execution>
</executions>
",
"artifactId": "openapi-generator-maven-plugin",
"groupId": "org.openapitools",
"version": "\${openapi-generator-maven-plugin.version}",
},
],
"plugins": [
{
"artifactId": "openapi-generator-maven-plugin",
"groupId": "org.openapitools",
},
],
"properties": [
{
"property": "openapi-generator-maven-plugin.version",
"value": "'OPENAPI-GENERATOR-MAVEN-PLUGIN-VERSION'",
},
],
},
},
],
],
Expand Down Expand Up @@ -88,12 +186,61 @@ exports[`generator - java:openapi-generator gradle-addOpenapiGeneratorPlugin(tru

exports[`generator - java:openapi-generator maven-addOpenapiGeneratorPlugin(false) should call source snapshot 1`] = `
{
"addJavaDependencies": [
"addJavaDefinitions": [
[
{
"artifactId": "jackson-databind-nullable",
"groupId": "org.openapitools",
"version": "'JACKSON-DATABIND-NULLABLE-VERSION'",
"dependencies": [
{
"artifactId": "jackson-databind-nullable",
"groupId": "org.openapitools",
"version": "'JACKSON-DATABIND-NULLABLE-VERSION'",
},
],
},
{
"condition": false,
"mavenDefinition": {
"pluginManagement": [
{
"additionalContent": " <executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>\${project.basedir}/src/main/resources/swagger/api.yml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.mycompany.myapp.web.api</apiPackage>
<modelPackage>com.mycompany.myapp.service.api.dto</modelPackage>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<skipValidateSpec>false</skipValidateSpec>
<configOptions>
<delegatePattern>true</delegatePattern>
<title>jhipster</title>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>
</configuration>
</execution>
</executions>
",
"artifactId": "openapi-generator-maven-plugin",
"groupId": "org.openapitools",
"version": "\${openapi-generator-maven-plugin.version}",
},
],
"plugins": [
{
"artifactId": "openapi-generator-maven-plugin",
"groupId": "org.openapitools",
},
],
"properties": [
{
"property": "openapi-generator-maven-plugin.version",
"value": "'OPENAPI-GENERATOR-MAVEN-PLUGIN-VERSION'",
},
],
},
},
],
],
Expand Down Expand Up @@ -122,20 +269,23 @@ exports[`generator - java:openapi-generator maven-addOpenapiGeneratorPlugin(fals

exports[`generator - java:openapi-generator maven-addOpenapiGeneratorPlugin(true) should call source snapshot 1`] = `
{
"addJavaDependencies": [
"addJavaDefinitions": [
[
{
"artifactId": "jackson-databind-nullable",
"groupId": "org.openapitools",
"version": "'JACKSON-DATABIND-NULLABLE-VERSION'",
"dependencies": [
{
"artifactId": "jackson-databind-nullable",
"groupId": "org.openapitools",
"version": "'JACKSON-DATABIND-NULLABLE-VERSION'",
},
],
},
],
],
"addMavenDefinition": [
{
"pluginManagement": [
{
"additionalContent": " <executions>
{
"condition": true,
"mavenDefinition": {
"pluginManagement": [
{
"additionalContent": " <executions>
<execution>
<goals>
<goal>generate</goal>
Expand All @@ -156,24 +306,26 @@ exports[`generator - java:openapi-generator maven-addOpenapiGeneratorPlugin(true
</execution>
</executions>
",
"artifactId": "openapi-generator-maven-plugin",
"groupId": "org.openapitools",
"version": "\${openapi-generator-maven-plugin.version}",
},
],
"plugins": [
{
"artifactId": "openapi-generator-maven-plugin",
"groupId": "org.openapitools",
"artifactId": "openapi-generator-maven-plugin",
"groupId": "org.openapitools",
"version": "\${openapi-generator-maven-plugin.version}",
},
],
"plugins": [
{
"artifactId": "openapi-generator-maven-plugin",
"groupId": "org.openapitools",
},
],
"properties": [
{
"property": "openapi-generator-maven-plugin.version",
"value": "'OPENAPI-GENERATOR-MAVEN-PLUGIN-VERSION'",
},
],
},
],
"properties": [
{
"property": "openapi-generator-maven-plugin.version",
"value": "'OPENAPI-GENERATOR-MAVEN-PLUGIN-VERSION'",
},
],
},
},
],
],
}
`;
Expand Down
Loading

0 comments on commit 92507ac

Please sign in to comment.