From 7065f3205c578b90e0f3d2945258736f73203698 Mon Sep 17 00:00:00 2001 From: Marcelo Boveto Shima Date: Tue, 16 Jan 2024 12:43:53 -0300 Subject: [PATCH 1/2] add support to nested generators --- cli/environment-builder.mjs | 20 ++++++++++++++++--- .../templates/cli/cli.cjs.ejs | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cli/environment-builder.mjs b/cli/environment-builder.mjs index c1dbccc45257..0152448fe17b 100644 --- a/cli/environment-builder.mjs +++ b/cli/environment-builder.mjs @@ -35,6 +35,10 @@ const __dirname = dirname(__filename); const jhipsterDevBlueprintPath = process.env.JHIPSTER_DEV_BLUEPRINT === 'true' ? path.join(__dirname, '../.blueprint') : undefined; const devBlueprintNamespace = '@jhipster/jhipster-dev'; const localBlueprintNamespace = '@jhipster/jhipster-local'; +const defaultLookupOptions = { + lookups: ['generators', 'generators/*/generators'], + customizeNamespace: ns => ns?.replaceAll(':generators:', ':'), +}; function loadYoRc(filePath = '.yo-rc.json') { if (!existsSync(filePath)) { @@ -155,7 +159,12 @@ export default class EnvironmentBuilder { packagePath = path.join(__dirname, '../..'); lookup = `${sourceRoot}/generators`; } - (await this.env.lookup({ packagePaths: [packagePath], lookups: [lookup] })).forEach(generator => { + const generators = await this.env.lookup({ + ...defaultLookupOptions, + packagePaths: [packagePath], + lookups: [lookup, `${lookup}/*/generators`], + }); + generators.forEach(generator => { // Verify jhipster generators namespace. assert( generator.namespace.startsWith(`${CLI_NAME}:`), @@ -193,7 +202,7 @@ export default class EnvironmentBuilder { async _lookups(lookups = []) { lookups = [].concat(lookups); for (const lookup of lookups) { - await this.env.lookup(lookup); + await this.env.lookup({ ...defaultLookupOptions, ...lookup }); } return this; } @@ -226,7 +235,12 @@ export default class EnvironmentBuilder { if (missingBlueprints && missingBlueprints.length > 0) { // Lookup for blueprints. - await this.env.lookup({ ...options, filterPaths: true, packagePatterns: missingBlueprints }); + await this.env.lookup({ + ...defaultLookupOptions, + ...options, + filterPaths: true, + packagePatterns: missingBlueprints, + }); } return this; } diff --git a/generators/generate-blueprint/templates/cli/cli.cjs.ejs b/generators/generate-blueprint/templates/cli/cli.cjs.ejs index 7e249bb66095..7d955918471d 100755 --- a/generators/generate-blueprint/templates/cli/cli.cjs.ejs +++ b/generators/generate-blueprint/templates/cli/cli.cjs.ejs @@ -26,7 +26,7 @@ const blueprint = packageFolderName.startsWith('jhipster-') ? `generator-${packa console.log('===================== JHipster <%= baseName %> ====================='); console.log(''); }, - lookups: [{ packagePaths: [packagePath], lookups: ['generators'] }], + lookups: [{ packagePaths: [packagePath] }], }).catch(done); process.on('unhandledRejection', up => { From 277a18c6dbd82d3a68038f9f46b19e664242f591 Mon Sep 17 00:00:00 2001 From: Marcelo Boveto Shima Date: Wed, 24 Jan 2024 22:24:55 -0300 Subject: [PATCH 2/2] split kafka and pulsar sub-generators --- generators/spring-cloud-stream/generator.ts | 128 ++---------------- .../{ => generators/kafka}/cleanup.ts | 0 .../{ => generators/kafka}/files.ts | 45 +----- .../generators/kafka/generator.ts | 99 ++++++++++++++ .../generators/kafka/index.ts | 19 +++ .../jhipster.kafka-conventions.gradle.ejs | 0 .../broker/KafkaConsumer_imperative.java.ejs | 0 .../broker/KafkaConsumer_reactive.java.ejs | 0 .../_package_/broker/KafkaProducer.java.ejs | 0 .../rest/KafkaResource_imperative.java.ejs | 0 .../web/rest/KafkaResource_reactive.java.ejs | 0 .../_package_/config/EmbeddedKafka.java.ejs | 0 .../config/KafkaTestContainer.java.ejs | 0 ...ersSpringContextCustomizerFactory.java.ejs | 0 .../rest/KafkaResourceIT_imperative.java.ejs | 0 .../rest/KafkaResourceIT_reactive.java.ejs | 0 .../generators/pulsar/files.ts | 44 ++++++ .../generators/pulsar/generator.ts | 84 ++++++++++++ .../generators/pulsar/index.ts | 19 +++ .../jhipster.pulsar-conventions.gradle.ejs | 0 .../java/_package_/broker/PulsarIT.java.ejs | 0 .../config/BrokerConfiguration.java.ejs | 0 .../_package_/config/EmbeddedPulsar.java.ejs | 0 .../config/PulsarTestContainer.java.ejs | 0 ...ersSpringContextCustomizerFactory.java.ejs | 0 25 files changed, 281 insertions(+), 157 deletions(-) rename generators/spring-cloud-stream/{ => generators/kafka}/cleanup.ts (100%) rename generators/spring-cloud-stream/{ => generators/kafka}/files.ts (66%) create mode 100644 generators/spring-cloud-stream/generators/kafka/generator.ts create mode 100644 generators/spring-cloud-stream/generators/kafka/index.ts rename generators/spring-cloud-stream/{ => generators/kafka}/templates/buildSrc/src/main/groovy/jhipster.kafka-conventions.gradle.ejs (100%) rename generators/spring-cloud-stream/{ => generators/kafka}/templates/src/main/java/_package_/broker/KafkaConsumer_imperative.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/kafka}/templates/src/main/java/_package_/broker/KafkaConsumer_reactive.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/kafka}/templates/src/main/java/_package_/broker/KafkaProducer.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/kafka}/templates/src/main/java/_package_/web/rest/KafkaResource_imperative.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/kafka}/templates/src/main/java/_package_/web/rest/KafkaResource_reactive.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/kafka}/templates/src/test/java/_package_/config/EmbeddedKafka.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/kafka}/templates/src/test/java/_package_/config/KafkaTestContainer.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/kafka}/templates/src/test/java/_package_/config/KafkaTestContainersSpringContextCustomizerFactory.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/kafka}/templates/src/test/java/_package_/web/rest/KafkaResourceIT_imperative.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/kafka}/templates/src/test/java/_package_/web/rest/KafkaResourceIT_reactive.java.ejs (100%) create mode 100644 generators/spring-cloud-stream/generators/pulsar/files.ts create mode 100644 generators/spring-cloud-stream/generators/pulsar/generator.ts create mode 100644 generators/spring-cloud-stream/generators/pulsar/index.ts rename generators/spring-cloud-stream/{ => generators/pulsar}/templates/buildSrc/src/main/groovy/jhipster.pulsar-conventions.gradle.ejs (100%) rename generators/spring-cloud-stream/{ => generators/pulsar}/templates/src/test/java/_package_/broker/PulsarIT.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/pulsar}/templates/src/test/java/_package_/config/BrokerConfiguration.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/pulsar}/templates/src/test/java/_package_/config/EmbeddedPulsar.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/pulsar}/templates/src/test/java/_package_/config/PulsarTestContainer.java.ejs (100%) rename generators/spring-cloud-stream/{ => generators/pulsar}/templates/src/test/java/_package_/config/PulsarTestContainersSpringContextCustomizerFactory.java.ejs (100%) diff --git a/generators/spring-cloud-stream/generator.ts b/generators/spring-cloud-stream/generator.ts index 3f12fbb4c995..c138a3e1a951 100644 --- a/generators/spring-cloud-stream/generator.ts +++ b/generators/spring-cloud-stream/generator.ts @@ -19,8 +19,6 @@ import BaseApplicationGenerator from '../base-application/index.js'; import { GENERATOR_SPRING_CLOUD_STREAM, GENERATOR_BOOTSTRAP_APPLICATION_SERVER } from '../generator-list.js'; -import cleanupFilesTask from './cleanup.js'; -import writeFilesTask from './files.js'; export default class KafkaGenerator extends BaseApplicationGenerator { async beforeQueue() { @@ -33,6 +31,19 @@ export default class KafkaGenerator extends BaseApplicationGenerator { } } + get composing() { + return this.asComposingTaskGroup({ + async compose() { + const { messageBroker } = this.jhipsterConfig; + await this.composeWithJHipster(`jhipster:spring-cloud-stream:${messageBroker}`); + }, + }); + } + + get [BaseApplicationGenerator.COMPOSING]() { + return this.delegateTasksToBlueprint(() => this.composing); + } + get preparing() { return this.asPreparingTaskGroup({ preparing({ application }) { @@ -47,117 +58,4 @@ export default class KafkaGenerator extends BaseApplicationGenerator { get [BaseApplicationGenerator.PREPARING]() { return this.delegateTasksToBlueprint(() => this.preparing); } - - get writing() { - return this.asWritingTaskGroup({ - cleanupFilesTask, - writeFilesTask, - }); - } - - get [BaseApplicationGenerator.WRITING]() { - return this.delegateTasksToBlueprint(() => this.writing); - } - - get postWriting() { - return this.asPostWritingTaskGroup({ - customizeApplicationForKafka({ source, application }) { - if (application.messageBrokerKafka) { - source.addLogbackMainLog?.({ name: 'org.apache.kafka', level: 'INFO' }); - source.addLogbackTestLog?.({ name: 'kafka', level: 'WARN' }); - source.addLogbackTestLog?.({ name: 'org.I0Itec', level: 'WARN' }); - source.addIntegrationTestAnnotation?.({ package: `${application.packageName}.config`, annotation: 'EmbeddedKafka' }); - - source.addTestSpringFactory?.({ - key: 'org.springframework.test.context.ContextCustomizerFactory', - value: `${application.packageName}.config.KafkaTestContainersSpringContextCustomizerFactory`, - }); - } - }, - applyKafkaGradleConventionPlugin({ source, application }) { - if (application.buildToolGradle && application.messageBrokerKafka) { - if (application.messageBrokerKafka) { - source.addGradlePlugin?.({ id: 'jhipster.kafka-conventions' }); - } - } - }, - addKafkaMavenDependencies({ application, source }) { - if (application.buildToolMaven && application.messageBrokerKafka) { - source.addMavenDependency?.([ - { - groupId: 'org.springframework.cloud', - artifactId: 'spring-cloud-stream', - }, - { - groupId: 'org.springframework.cloud', - artifactId: 'spring-cloud-starter-stream-kafka', - }, - { - groupId: 'org.springframework.cloud', - artifactId: 'spring-cloud-stream-test-binder', - scope: 'test', - }, - { - groupId: 'org.testcontainers', - artifactId: 'junit-jupiter', - scope: 'test', - }, - { - groupId: 'org.testcontainers', - artifactId: 'testcontainers', - scope: 'test', - }, - { - groupId: 'org.testcontainers', - artifactId: 'kafka', - scope: 'test', - }, - ]); - } - }, - customizeApplicationForPulsar({ source, application }) { - if (application.messageBrokerPulsar) { - source.addLogbackMainLog?.({ name: 'org.apache.pulsar', level: 'INFO' }); - source.addIntegrationTestAnnotation?.({ package: `${application.packageName}.config`, annotation: 'EmbeddedPulsar' }); - - source.addTestSpringFactory?.({ - key: 'org.springframework.test.context.ContextCustomizerFactory', - value: `${application.packageName}.config.PulsarTestContainersSpringContextCustomizerFactory`, - }); - } - }, - applyPulsarGradleConventionPlugin({ source, application }) { - if (application.buildToolGradle && application.messageBrokerPulsar) { - const { javaDependencies } = application; - source.addGradlePlugin?.({ id: 'jhipster.pulsar-conventions' }); - source.addGradleDependencyCatalogVersion?.({ name: 'pulsar-spring', version: javaDependencies?.['spring-pulsar'] }); - source.addGradleBuildSrcDependencyCatalogVersion?.({ name: 'pulsar-spring', version: javaDependencies?.['spring-pulsar'] }); - } - }, - addPulsarMavenDependencies({ application, source }) { - if (application.buildToolMaven && application.messageBrokerPulsar) { - const { javaDependencies } = application; - source.addMavenDefinition?.({ - properties: [{ property: 'spring-pulsar.version', value: javaDependencies?.['spring-pulsar'] }], - dependencies: [ - { groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-stream' }, - { - groupId: 'org.springframework.pulsar', - artifactId: 'spring-pulsar-spring-cloud-stream-binder', - // eslint-disable-next-line no-template-curly-in-string - version: '${spring-pulsar.version}', - }, - { groupId: 'org.testcontainers', artifactId: 'junit-jupiter', scope: 'test' }, - { groupId: 'org.testcontainers', artifactId: 'testcontainers', scope: 'test' }, - { groupId: 'org.testcontainers', artifactId: 'pulsar', scope: 'test' }, - ], - }); - } - }, - }); - } - - get [BaseApplicationGenerator.POST_WRITING]() { - return this.asPostWritingTaskGroup(this.delegateTasksToBlueprint(() => this.postWriting)); - } } diff --git a/generators/spring-cloud-stream/cleanup.ts b/generators/spring-cloud-stream/generators/kafka/cleanup.ts similarity index 100% rename from generators/spring-cloud-stream/cleanup.ts rename to generators/spring-cloud-stream/generators/kafka/cleanup.ts diff --git a/generators/spring-cloud-stream/files.ts b/generators/spring-cloud-stream/generators/kafka/files.ts similarity index 66% rename from generators/spring-cloud-stream/files.ts rename to generators/spring-cloud-stream/generators/kafka/files.ts index 6fa75835656b..db420fcb5028 100644 --- a/generators/spring-cloud-stream/files.ts +++ b/generators/spring-cloud-stream/generators/kafka/files.ts @@ -16,10 +16,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { WriteFileSection } from '../base/api.js'; -import { SERVER_MAIN_SRC_DIR, SERVER_TEST_SRC_DIR, GRADLE_BUILD_SRC_MAIN_DIR } from '../generator-constants.js'; -import { moveToJavaPackageSrcDir, moveToJavaPackageTestDir } from '../server/support/index.js'; -import KafkaGenerator from './generator.js'; +import { WriteFileSection } from '../../../base/api.js'; +import { SERVER_MAIN_SRC_DIR, SERVER_TEST_SRC_DIR, GRADLE_BUILD_SRC_MAIN_DIR } from '../../../generator-constants.js'; +import { moveToJavaPackageSrcDir, moveToJavaPackageTestDir } from '../../../server/support/index.js'; export const kafkaFiles: WriteFileSection = { config: [ @@ -68,41 +67,3 @@ export const kafkaFiles: WriteFileSection = { }, ], }; - -export const pulsarFiles: WriteFileSection = { - config: [ - { - condition: data => data.buildToolGradle, - path: GRADLE_BUILD_SRC_MAIN_DIR, - templates: ['jhipster.pulsar-conventions.gradle'], - }, - ], - test: [ - { - path: `${SERVER_TEST_SRC_DIR}_package_/`, - renameTo: moveToJavaPackageTestDir, - templates: [ - 'broker/PulsarIT.java', - 'config/BrokerConfiguration.java', - 'config/EmbeddedPulsar.java', - 'config/PulsarTestContainer.java', - 'config/PulsarTestContainersSpringContextCustomizerFactory.java', - ], - }, - ], -}; - -export default async function writeFilesTask(this: KafkaGenerator, { application }) { - if (application.messageBrokerKafka) { - await this.writeFiles({ - sections: kafkaFiles, - context: application, - }); - } - if (application.messageBrokerPulsar) { - await this.writeFiles({ - sections: pulsarFiles, - context: application, - }); - } -} diff --git a/generators/spring-cloud-stream/generators/kafka/generator.ts b/generators/spring-cloud-stream/generators/kafka/generator.ts new file mode 100644 index 000000000000..100f9e200a77 --- /dev/null +++ b/generators/spring-cloud-stream/generators/kafka/generator.ts @@ -0,0 +1,99 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import BaseApplicationGenerator from '../../../base-application/index.js'; +import cleanupKafkaFilesTask from './cleanup.js'; +import { kafkaFiles } from './files.js'; + +export default class KafkaGenerator extends BaseApplicationGenerator { + get writing() { + return this.asWritingTaskGroup({ + cleanupKafkaFilesTask, + async writing({ application }) { + await this.writeFiles({ + sections: kafkaFiles, + context: application, + }); + }, + }); + } + + get [BaseApplicationGenerator.WRITING]() { + return this.delegateTasksToBlueprint(() => this.writing); + } + + get postWriting() { + return this.asPostWritingTaskGroup({ + customizeApplicationForKafka({ source, application }) { + source.addLogbackMainLog?.({ name: 'org.apache.kafka', level: 'INFO' }); + source.addLogbackTestLog?.({ name: 'kafka', level: 'WARN' }); + source.addLogbackTestLog?.({ name: 'org.I0Itec', level: 'WARN' }); + source.addIntegrationTestAnnotation?.({ package: `${application.packageName}.config`, annotation: 'EmbeddedKafka' }); + + source.addTestSpringFactory?.({ + key: 'org.springframework.test.context.ContextCustomizerFactory', + value: `${application.packageName}.config.KafkaTestContainersSpringContextCustomizerFactory`, + }); + }, + applyKafkaGradleConventionPlugin({ source, application }) { + if (application.buildToolGradle) { + source.addGradlePlugin?.({ id: 'jhipster.kafka-conventions' }); + } + }, + addKafkaMavenDependencies({ application, source }) { + if (application.buildToolMaven) { + source.addMavenDependency?.([ + { + groupId: 'org.springframework.cloud', + artifactId: 'spring-cloud-stream', + }, + { + groupId: 'org.springframework.cloud', + artifactId: 'spring-cloud-starter-stream-kafka', + }, + { + groupId: 'org.springframework.cloud', + artifactId: 'spring-cloud-stream-test-binder', + scope: 'test', + }, + { + groupId: 'org.testcontainers', + artifactId: 'junit-jupiter', + scope: 'test', + }, + { + groupId: 'org.testcontainers', + artifactId: 'testcontainers', + scope: 'test', + }, + { + groupId: 'org.testcontainers', + artifactId: 'kafka', + scope: 'test', + }, + ]); + } + }, + }); + } + + get [BaseApplicationGenerator.POST_WRITING]() { + return this.asPostWritingTaskGroup(this.delegateTasksToBlueprint(() => this.postWriting)); + } +} diff --git a/generators/spring-cloud-stream/generators/kafka/index.ts b/generators/spring-cloud-stream/generators/kafka/index.ts new file mode 100644 index 000000000000..58ac334eafae --- /dev/null +++ b/generators/spring-cloud-stream/generators/kafka/index.ts @@ -0,0 +1,19 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { default } from './generator.js'; diff --git a/generators/spring-cloud-stream/templates/buildSrc/src/main/groovy/jhipster.kafka-conventions.gradle.ejs b/generators/spring-cloud-stream/generators/kafka/templates/buildSrc/src/main/groovy/jhipster.kafka-conventions.gradle.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/buildSrc/src/main/groovy/jhipster.kafka-conventions.gradle.ejs rename to generators/spring-cloud-stream/generators/kafka/templates/buildSrc/src/main/groovy/jhipster.kafka-conventions.gradle.ejs diff --git a/generators/spring-cloud-stream/templates/src/main/java/_package_/broker/KafkaConsumer_imperative.java.ejs b/generators/spring-cloud-stream/generators/kafka/templates/src/main/java/_package_/broker/KafkaConsumer_imperative.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/main/java/_package_/broker/KafkaConsumer_imperative.java.ejs rename to generators/spring-cloud-stream/generators/kafka/templates/src/main/java/_package_/broker/KafkaConsumer_imperative.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/main/java/_package_/broker/KafkaConsumer_reactive.java.ejs b/generators/spring-cloud-stream/generators/kafka/templates/src/main/java/_package_/broker/KafkaConsumer_reactive.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/main/java/_package_/broker/KafkaConsumer_reactive.java.ejs rename to generators/spring-cloud-stream/generators/kafka/templates/src/main/java/_package_/broker/KafkaConsumer_reactive.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/main/java/_package_/broker/KafkaProducer.java.ejs b/generators/spring-cloud-stream/generators/kafka/templates/src/main/java/_package_/broker/KafkaProducer.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/main/java/_package_/broker/KafkaProducer.java.ejs rename to generators/spring-cloud-stream/generators/kafka/templates/src/main/java/_package_/broker/KafkaProducer.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/main/java/_package_/web/rest/KafkaResource_imperative.java.ejs b/generators/spring-cloud-stream/generators/kafka/templates/src/main/java/_package_/web/rest/KafkaResource_imperative.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/main/java/_package_/web/rest/KafkaResource_imperative.java.ejs rename to generators/spring-cloud-stream/generators/kafka/templates/src/main/java/_package_/web/rest/KafkaResource_imperative.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/main/java/_package_/web/rest/KafkaResource_reactive.java.ejs b/generators/spring-cloud-stream/generators/kafka/templates/src/main/java/_package_/web/rest/KafkaResource_reactive.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/main/java/_package_/web/rest/KafkaResource_reactive.java.ejs rename to generators/spring-cloud-stream/generators/kafka/templates/src/main/java/_package_/web/rest/KafkaResource_reactive.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/test/java/_package_/config/EmbeddedKafka.java.ejs b/generators/spring-cloud-stream/generators/kafka/templates/src/test/java/_package_/config/EmbeddedKafka.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/test/java/_package_/config/EmbeddedKafka.java.ejs rename to generators/spring-cloud-stream/generators/kafka/templates/src/test/java/_package_/config/EmbeddedKafka.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/test/java/_package_/config/KafkaTestContainer.java.ejs b/generators/spring-cloud-stream/generators/kafka/templates/src/test/java/_package_/config/KafkaTestContainer.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/test/java/_package_/config/KafkaTestContainer.java.ejs rename to generators/spring-cloud-stream/generators/kafka/templates/src/test/java/_package_/config/KafkaTestContainer.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/test/java/_package_/config/KafkaTestContainersSpringContextCustomizerFactory.java.ejs b/generators/spring-cloud-stream/generators/kafka/templates/src/test/java/_package_/config/KafkaTestContainersSpringContextCustomizerFactory.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/test/java/_package_/config/KafkaTestContainersSpringContextCustomizerFactory.java.ejs rename to generators/spring-cloud-stream/generators/kafka/templates/src/test/java/_package_/config/KafkaTestContainersSpringContextCustomizerFactory.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/test/java/_package_/web/rest/KafkaResourceIT_imperative.java.ejs b/generators/spring-cloud-stream/generators/kafka/templates/src/test/java/_package_/web/rest/KafkaResourceIT_imperative.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/test/java/_package_/web/rest/KafkaResourceIT_imperative.java.ejs rename to generators/spring-cloud-stream/generators/kafka/templates/src/test/java/_package_/web/rest/KafkaResourceIT_imperative.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/test/java/_package_/web/rest/KafkaResourceIT_reactive.java.ejs b/generators/spring-cloud-stream/generators/kafka/templates/src/test/java/_package_/web/rest/KafkaResourceIT_reactive.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/test/java/_package_/web/rest/KafkaResourceIT_reactive.java.ejs rename to generators/spring-cloud-stream/generators/kafka/templates/src/test/java/_package_/web/rest/KafkaResourceIT_reactive.java.ejs diff --git a/generators/spring-cloud-stream/generators/pulsar/files.ts b/generators/spring-cloud-stream/generators/pulsar/files.ts new file mode 100644 index 000000000000..6c6572e15cb7 --- /dev/null +++ b/generators/spring-cloud-stream/generators/pulsar/files.ts @@ -0,0 +1,44 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { WriteFileSection } from '../../../base/api.js'; +import { SERVER_TEST_SRC_DIR, GRADLE_BUILD_SRC_MAIN_DIR } from '../../../generator-constants.js'; +import { moveToJavaPackageTestDir } from '../../../java/support/index.js'; + +export const pulsarFiles: WriteFileSection = { + config: [ + { + condition: data => data.buildToolGradle, + path: GRADLE_BUILD_SRC_MAIN_DIR, + templates: ['jhipster.pulsar-conventions.gradle'], + }, + ], + test: [ + { + path: `${SERVER_TEST_SRC_DIR}_package_/`, + renameTo: moveToJavaPackageTestDir, + templates: [ + 'broker/PulsarIT.java', + 'config/BrokerConfiguration.java', + 'config/EmbeddedPulsar.java', + 'config/PulsarTestContainer.java', + 'config/PulsarTestContainersSpringContextCustomizerFactory.java', + ], + }, + ], +}; diff --git a/generators/spring-cloud-stream/generators/pulsar/generator.ts b/generators/spring-cloud-stream/generators/pulsar/generator.ts new file mode 100644 index 000000000000..d7bbc30e79ee --- /dev/null +++ b/generators/spring-cloud-stream/generators/pulsar/generator.ts @@ -0,0 +1,84 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import BaseApplicationGenerator from '../../../base-application/index.js'; +import { pulsarFiles } from './files.js'; + +export default class KafkaGenerator extends BaseApplicationGenerator { + get writing() { + return this.asWritingTaskGroup({ + async writing({ application }) { + await this.writeFiles({ + sections: pulsarFiles, + context: application, + }); + }, + }); + } + + get [BaseApplicationGenerator.WRITING]() { + return this.delegateTasksToBlueprint(() => this.writing); + } + + get postWriting() { + return this.asPostWritingTaskGroup({ + customizeApplicationForPulsar({ source, application }) { + source.addLogbackMainLog?.({ name: 'org.apache.pulsar', level: 'INFO' }); + source.addIntegrationTestAnnotation?.({ package: `${application.packageName}.config`, annotation: 'EmbeddedPulsar' }); + + source.addTestSpringFactory?.({ + key: 'org.springframework.test.context.ContextCustomizerFactory', + value: `${application.packageName}.config.PulsarTestContainersSpringContextCustomizerFactory`, + }); + }, + applyPulsarGradleConventionPlugin({ source, application }) { + if (application.buildToolGradle) { + const { javaDependencies } = application; + source.addGradlePlugin?.({ id: 'jhipster.pulsar-conventions' }); + source.addGradleDependencyCatalogVersion?.({ name: 'pulsar-spring', version: javaDependencies?.['spring-pulsar'] }); + source.addGradleBuildSrcDependencyCatalogVersion?.({ name: 'pulsar-spring', version: javaDependencies?.['spring-pulsar'] }); + } + }, + addPulsarMavenDependencies({ application, source }) { + if (application.buildToolMaven) { + const { javaDependencies } = application; + source.addMavenDefinition?.({ + properties: [{ property: 'spring-pulsar.version', value: javaDependencies?.['spring-pulsar'] }], + dependencies: [ + { groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-stream' }, + { + groupId: 'org.springframework.pulsar', + artifactId: 'spring-pulsar-spring-cloud-stream-binder', + // eslint-disable-next-line no-template-curly-in-string + version: '${spring-pulsar.version}', + }, + { groupId: 'org.testcontainers', artifactId: 'junit-jupiter', scope: 'test' }, + { groupId: 'org.testcontainers', artifactId: 'testcontainers', scope: 'test' }, + { groupId: 'org.testcontainers', artifactId: 'pulsar', scope: 'test' }, + ], + }); + } + }, + }); + } + + get [BaseApplicationGenerator.POST_WRITING]() { + return this.asPostWritingTaskGroup(this.delegateTasksToBlueprint(() => this.postWriting)); + } +} diff --git a/generators/spring-cloud-stream/generators/pulsar/index.ts b/generators/spring-cloud-stream/generators/pulsar/index.ts new file mode 100644 index 000000000000..58ac334eafae --- /dev/null +++ b/generators/spring-cloud-stream/generators/pulsar/index.ts @@ -0,0 +1,19 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { default } from './generator.js'; diff --git a/generators/spring-cloud-stream/templates/buildSrc/src/main/groovy/jhipster.pulsar-conventions.gradle.ejs b/generators/spring-cloud-stream/generators/pulsar/templates/buildSrc/src/main/groovy/jhipster.pulsar-conventions.gradle.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/buildSrc/src/main/groovy/jhipster.pulsar-conventions.gradle.ejs rename to generators/spring-cloud-stream/generators/pulsar/templates/buildSrc/src/main/groovy/jhipster.pulsar-conventions.gradle.ejs diff --git a/generators/spring-cloud-stream/templates/src/test/java/_package_/broker/PulsarIT.java.ejs b/generators/spring-cloud-stream/generators/pulsar/templates/src/test/java/_package_/broker/PulsarIT.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/test/java/_package_/broker/PulsarIT.java.ejs rename to generators/spring-cloud-stream/generators/pulsar/templates/src/test/java/_package_/broker/PulsarIT.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/test/java/_package_/config/BrokerConfiguration.java.ejs b/generators/spring-cloud-stream/generators/pulsar/templates/src/test/java/_package_/config/BrokerConfiguration.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/test/java/_package_/config/BrokerConfiguration.java.ejs rename to generators/spring-cloud-stream/generators/pulsar/templates/src/test/java/_package_/config/BrokerConfiguration.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/test/java/_package_/config/EmbeddedPulsar.java.ejs b/generators/spring-cloud-stream/generators/pulsar/templates/src/test/java/_package_/config/EmbeddedPulsar.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/test/java/_package_/config/EmbeddedPulsar.java.ejs rename to generators/spring-cloud-stream/generators/pulsar/templates/src/test/java/_package_/config/EmbeddedPulsar.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/test/java/_package_/config/PulsarTestContainer.java.ejs b/generators/spring-cloud-stream/generators/pulsar/templates/src/test/java/_package_/config/PulsarTestContainer.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/test/java/_package_/config/PulsarTestContainer.java.ejs rename to generators/spring-cloud-stream/generators/pulsar/templates/src/test/java/_package_/config/PulsarTestContainer.java.ejs diff --git a/generators/spring-cloud-stream/templates/src/test/java/_package_/config/PulsarTestContainersSpringContextCustomizerFactory.java.ejs b/generators/spring-cloud-stream/generators/pulsar/templates/src/test/java/_package_/config/PulsarTestContainersSpringContextCustomizerFactory.java.ejs similarity index 100% rename from generators/spring-cloud-stream/templates/src/test/java/_package_/config/PulsarTestContainersSpringContextCustomizerFactory.java.ejs rename to generators/spring-cloud-stream/generators/pulsar/templates/src/test/java/_package_/config/PulsarTestContainersSpringContextCustomizerFactory.java.ejs