Skip to content

Commit b24587c

Browse files
authored
spring-cloud: move spring-cloud related code to spring-cloud generator (#31847)
1 parent 9d253d8 commit b24587c

File tree

11 files changed

+110
-174
lines changed

11 files changed

+110
-174
lines changed

generators/server/__test-support/index.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { databaseTypes, messageBrokerTypes } from '../../../lib/jhipster/index.ts';
1+
import { databaseTypes } from '../../../lib/jhipster/index.ts';
22
import type { result } from '../../../lib/testing/index.ts';
33

4-
const { KAFKA, PULSAR } = messageBrokerTypes;
54
const { SQL, COUCHBASE } = databaseTypes;
65

76
type RunResultSupplier = () => typeof result;
@@ -19,32 +18,6 @@ export const shouldComposeWithLiquibase = (testSample: boolean | Record<string,
1918
}
2019
};
2120

22-
export const shouldComposeWithSpringCloudStream = (
23-
sampleConfig: boolean | Record<string, unknown>,
24-
runResultSupplier: RunResultSupplier,
25-
) => {
26-
const pulsarEnabled = typeof sampleConfig === 'boolean' ? sampleConfig : sampleConfig?.messageBroker === PULSAR;
27-
const kafkaEnabled = typeof sampleConfig === 'boolean' ? sampleConfig : sampleConfig?.messageBroker === KAFKA;
28-
if (pulsarEnabled) {
29-
it(`should compose with spring-cloud:pulsar generator`, () => {
30-
runResultSupplier().assertGeneratorComposedOnce(`jhipster:spring-cloud:pulsar`);
31-
});
32-
} else {
33-
it(`should not compose with spring-cloud:pulsar generator`, () => {
34-
runResultSupplier().assertGeneratorNotComposed(`jhipster:spring-cloud:pulsar`);
35-
});
36-
}
37-
if (kafkaEnabled) {
38-
it(`should compose with spring-cloud:kafka generator`, () => {
39-
runResultSupplier().assertGeneratorComposedOnce(`jhipster:spring-cloud:kafka`);
40-
});
41-
} else {
42-
it(`should not compose with spring-cloud:kafka generator`, () => {
43-
runResultSupplier().assertGeneratorNotComposed(`jhipster:spring-cloud:kafka`);
44-
});
45-
}
46-
};
47-
4821
const shouldComposeWithDatabasetype = (databaseType: string, shouldCompose: boolean, runResultSupplier: RunResultSupplier) => {
4922
const generator = databaseType;
5023
if (shouldCompose) {

generators/server/generator.spec.ts

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { basename } from 'node:path';
2222
import { defaultHelpers as helpers, result as runResult } from '../../lib/testing/index.ts';
2323
import { checkEnforcements, shouldSupportFeatures, testBlueprintSupport } from '../../test/support/index.ts';
2424

25-
import { filterBasicServerGenerators, shouldComposeWithCouchbase, shouldComposeWithSpringCloudStream } from './__test-support/index.ts';
25+
import { filterBasicServerGenerators, shouldComposeWithCouchbase } from './__test-support/index.ts';
2626
import Generator from './index.ts';
2727

2828
const generator = basename(import.meta.dirname);
@@ -33,51 +33,6 @@ describe(`generator - ${generator}`, () => {
3333
checkEnforcements({}, generator, 'spring-boot');
3434

3535
describe('composing', () => {
36-
describe('messageBroker option', () => {
37-
describe('no', () => {
38-
before(async () => {
39-
await helpers
40-
.runJHipster(generator)
41-
.withJHipsterConfig({
42-
messageBroker: 'no',
43-
})
44-
.withSkipWritingPriorities()
45-
.withMockedSource({ except: ['addTestSpringFactory'] })
46-
.withMockedJHipsterGenerators({ filter: filterBasicServerGenerators });
47-
});
48-
49-
shouldComposeWithSpringCloudStream(false, () => runResult);
50-
});
51-
describe('kafka', () => {
52-
const config = {
53-
messageBroker: 'kafka' as const,
54-
};
55-
before(async () => {
56-
await helpers
57-
.runJHipster(generator)
58-
.withJHipsterConfig(config)
59-
.withSkipWritingPriorities()
60-
.withMockedSource({ except: ['addTestSpringFactory'] })
61-
.withMockedJHipsterGenerators({ filter: filterBasicServerGenerators });
62-
});
63-
shouldComposeWithSpringCloudStream(config, () => runResult);
64-
});
65-
describe('pulsar', () => {
66-
const config = {
67-
messageBroker: 'pulsar' as const,
68-
};
69-
before(async () => {
70-
await helpers
71-
.runJHipster(generator)
72-
.withJHipsterConfig(config)
73-
.withSkipWritingPriorities()
74-
.withMockedSource({ except: ['addTestSpringFactory'] })
75-
.withMockedJHipsterGenerators({ filter: filterBasicServerGenerators });
76-
});
77-
shouldComposeWithSpringCloudStream(config, () => runResult);
78-
});
79-
});
80-
8136
describe('databaseType option', () => {
8237
describe('no with jwt', () => {
8338
before(async () => {

generators/spring-boot/generator.ts

Lines changed: 14 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,9 @@ import chalk from 'chalk';
2121
import { lowerFirst, sortedUniqBy } from 'lodash-es';
2222
import { isFileStateModified } from 'mem-fs-editor/state';
2323

24-
import { APPLICATION_TYPE_GATEWAY, APPLICATION_TYPE_MICROSERVICE } from '../../lib/core/application-types.ts';
24+
import { APPLICATION_TYPE_MICROSERVICE } from '../../lib/core/application-types.ts';
2525
import type { FieldType } from '../../lib/jhipster/field-types.ts';
26-
import {
27-
cacheTypes,
28-
databaseTypes,
29-
fieldTypes,
30-
messageBrokerTypes,
31-
searchEngineTypes,
32-
testFrameworkTypes,
33-
websocketTypes,
34-
} from '../../lib/jhipster/index.ts';
26+
import { cacheTypes, databaseTypes, fieldTypes, searchEngineTypes, testFrameworkTypes, websocketTypes } from '../../lib/jhipster/index.ts';
3527
import { mutateData } from '../../lib/utils/index.ts';
3628
import BaseApplicationGenerator from '../base-application/index.ts';
3729
import { createNeedleCallback, isWin32 } from '../base-core/support/index.ts';
@@ -67,7 +59,6 @@ import type {
6759
const { CAFFEINE, EHCACHE, HAZELCAST, INFINISPAN, MEMCACHED, REDIS } = cacheTypes;
6860
const { NO: NO_WEBSOCKET, SPRING_WEBSOCKET } = websocketTypes;
6961
const { CASSANDRA, COUCHBASE, MONGODB, NEO4J, SQL } = databaseTypes;
70-
const { KAFKA, PULSAR } = messageBrokerTypes;
7162
const { ELASTICSEARCH } = searchEngineTypes;
7263

7364
const { BYTES: TYPE_BYTES, BYTE_BUFFER: TYPE_BYTE_BUFFER } = fieldTypes.RelationalOnlyDBTypes;
@@ -159,6 +150,7 @@ export default class SpringBootGenerator extends SpringBootApplicationGenerator
159150
testFrameworks,
160151
feignClient,
161152
enableSwaggerCodegen,
153+
serviceDiscoveryType,
162154
} = this.jhipsterConfigWithDefaults;
163155
const { cacheProvider } = this.jhipsterConfigWithDefaults as SpringCacheConfig;
164156
const { messageBroker } = this.jhipsterConfigWithDefaults;
@@ -184,8 +176,8 @@ export default class SpringBootGenerator extends SpringBootApplicationGenerator
184176
await this.composeWithJHipster('jhipster:java-simple-application:openapi-generator');
185177
}
186178

187-
if (applicationType === APPLICATION_TYPE_GATEWAY) {
188-
await this.composeWithJHipster('jhipster:spring-cloud:gateway');
179+
if (applicationType !== 'monolith' || messageBroker !== 'no' || serviceDiscoveryType !== 'no') {
180+
await this.composeWithJHipster('jhipster:spring-cloud');
189181
}
190182

191183
if (testFrameworks?.includes(CUCUMBER)) {
@@ -209,9 +201,6 @@ export default class SpringBootGenerator extends SpringBootApplicationGenerator
209201
} else if (databaseType === NEO4J) {
210202
await this.composeWithJHipster('jhipster:spring-data:neo4j');
211203
}
212-
if (messageBroker === KAFKA || messageBroker === PULSAR) {
213-
await this.composeWithJHipster(`jhipster:spring-cloud:${messageBroker}`);
214-
}
215204
if (searchEngine === ELASTICSEARCH) {
216205
await this.composeWithJHipster('jhipster:spring-data:elasticsearch');
217206
}
@@ -784,14 +773,7 @@ ${classProperties
784773
);
785774
},
786775
addJHipsterBomDependencies({ application, source }) {
787-
const {
788-
applicationTypeGateway,
789-
applicationTypeMicroservice,
790-
javaDependencies,
791-
jhipsterDependenciesVersion,
792-
messageBrokerAny,
793-
serviceDiscoveryAny,
794-
} = application;
776+
const { jhipsterDependenciesVersion } = application;
795777

796778
if (application.reactive && application.graalvmSupport) {
797779
source.addNativeHint!({
@@ -802,32 +784,18 @@ ${classProperties
802784
],
803785
});
804786
}
805-
source.addJavaDefinitions?.(
806-
{
807-
dependencies: [{ groupId: 'tech.jhipster', artifactId: 'jhipster-framework', version: jhipsterDependenciesVersion! }],
808-
mavenDefinition: {
809-
properties: [
810-
{
811-
property: 'spring-boot.version',
812-
// eslint-disable-next-line no-template-curly-in-string
813-
value: '${project.parent.version}',
814-
},
815-
],
816-
},
817-
},
818-
{
819-
condition: applicationTypeGateway || applicationTypeMicroservice || serviceDiscoveryAny || messageBrokerAny,
820-
dependencies: [
787+
source.addJavaDefinitions?.({
788+
dependencies: [{ groupId: 'tech.jhipster', artifactId: 'jhipster-framework', version: jhipsterDependenciesVersion! }],
789+
mavenDefinition: {
790+
properties: [
821791
{
822-
groupId: 'org.springframework.cloud',
823-
artifactId: 'spring-cloud-dependencies',
824-
type: 'pom',
825-
scope: 'import',
826-
version: javaDependencies!['spring-cloud-dependencies'],
792+
property: 'spring-boot.version',
793+
// eslint-disable-next-line no-template-curly-in-string
794+
value: '${project.parent.version}',
827795
},
828796
],
829797
},
830-
);
798+
});
831799
},
832800
addSpringdoc({ application, source }) {
833801
const springdocDependency = `springdoc-openapi-starter-${application.reactive ? 'webflux' : 'webmvc'}-api`;
@@ -1025,34 +993,6 @@ ${application.jhipsterDependenciesVersion?.includes('-CICD') ? '' : '// '}mavenL
1025993
condition: application.addSpringMilestoneRepository,
1026994
dependencies: [{ groupId: 'org.springframework.boot', artifactId: 'spring-boot-properties-migrator', scope: 'runtime' }],
1027995
},
1028-
{
1029-
condition: application.applicationTypeMicroservice || application.applicationTypeGateway,
1030-
dependencies: [
1031-
{ groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter' },
1032-
{
1033-
groupId: 'org.springframework.cloud',
1034-
artifactId: `spring-cloud-starter-circuitbreaker-${application.reactive ? 'reactor-' : ''}resilience4j`,
1035-
},
1036-
],
1037-
},
1038-
{
1039-
condition: application.serviceDiscoveryAny,
1040-
dependencies: [{ groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter-bootstrap' }],
1041-
},
1042-
{
1043-
condition: application.serviceDiscoveryEureka,
1044-
dependencies: [
1045-
{ groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter-config' },
1046-
{ groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter-netflix-eureka-client' },
1047-
],
1048-
},
1049-
{
1050-
condition: application.serviceDiscoveryConsul,
1051-
dependencies: [
1052-
{ groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter-consul-config' },
1053-
{ groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter-consul-discovery' },
1054-
],
1055-
},
1056996
);
1057997

1058998
if (application.buildToolGradle && application.reactive) {

generators/spring-cloud/__snapshots__/generator.spec.ts.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3+
exports[`generator - spring-cloud composing messageBroker option kafka should match composed generators snapshot 1`] = `
4+
[
5+
"jhipster:spring-cloud:kafka",
6+
]
7+
`;
8+
9+
exports[`generator - spring-cloud composing messageBroker option no should match composed generators snapshot 1`] = `[]`;
10+
11+
exports[`generator - spring-cloud composing messageBroker option pulsar should match composed generators snapshot 1`] = `
12+
[
13+
"jhipster:spring-cloud:pulsar",
14+
]
15+
`;
16+
317
exports[`generator - spring-cloud with default config should match files snapshot 1`] = `
418
{
519
".yo-rc.json": {

generators/spring-cloud/generator.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,27 @@ describe(`generator - ${generator}`, () => {
2121
expect(result.getStateSnapshot()).toMatchSnapshot();
2222
});
2323
});
24+
25+
describe('composing', () => {
26+
describe('messageBroker option', () => {
27+
for (const messageBroker of ['no', 'kafka', 'pulsar'] as const) {
28+
describe(messageBroker, () => {
29+
before(async () => {
30+
await helpers
31+
.runJHipster(generator)
32+
.withJHipsterConfig({
33+
messageBroker,
34+
})
35+
.withSkipWritingPriorities()
36+
.withMockedSource({ except: ['addTestSpringFactory'] })
37+
.withMockedJHipsterGenerators();
38+
});
39+
40+
it('should match composed generators snapshot', () => {
41+
expect(result.composedMockedGenerators).toMatchSnapshot();
42+
});
43+
});
44+
}
45+
});
46+
});
2447
});

generators/spring-cloud/generator.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,56 @@ export default class SpringCloudGenerator extends SpringCloudApplicationGenerato
6969
get [BaseApplicationGenerator.COMPOSING]() {
7070
return this.delegateTasksToBlueprint(() => this.composing);
7171
}
72+
73+
get postWriting() {
74+
return this.asPostWritingTaskGroup({
75+
addJHipsterBomDependencies({ application, source }) {
76+
source.addJavaDefinitions?.(
77+
{
78+
dependencies: [
79+
{
80+
groupId: 'org.springframework.cloud',
81+
artifactId: 'spring-cloud-dependencies',
82+
type: 'pom',
83+
scope: 'import',
84+
version: application.javaDependencies!['spring-cloud-dependencies'],
85+
},
86+
],
87+
},
88+
{
89+
condition: application.applicationTypeMicroservice || application.applicationTypeGateway,
90+
dependencies: [
91+
{ groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter' },
92+
{
93+
groupId: 'org.springframework.cloud',
94+
artifactId: `spring-cloud-starter-circuitbreaker-${application.reactive ? 'reactor-' : ''}resilience4j`,
95+
},
96+
],
97+
},
98+
{
99+
condition: application.serviceDiscoveryAny,
100+
dependencies: [{ groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter-bootstrap' }],
101+
},
102+
{
103+
condition: application.serviceDiscoveryEureka,
104+
dependencies: [
105+
{ groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter-config' },
106+
{ groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter-netflix-eureka-client' },
107+
],
108+
},
109+
{
110+
condition: application.serviceDiscoveryConsul,
111+
dependencies: [
112+
{ groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter-consul-config' },
113+
{ groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter-consul-discovery' },
114+
],
115+
},
116+
);
117+
},
118+
});
119+
}
120+
121+
get [BaseApplicationGenerator.POST_WRITING]() {
122+
return this.delegateTasksToBlueprint(() => this.postWriting);
123+
}
72124
}

generators/spring-data/generators/cassandra/generator.spec.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ import { basename, resolve } from 'node:path';
2222
import { databaseTypes } from '../../../../lib/jhipster/index.ts';
2323
import { buildServerSamples, defaultHelpers as helpers, entitiesSimple as entities, runResult } from '../../../../lib/testing/index.ts';
2424
import { shouldSupportFeatures, testBlueprintSupport } from '../../../../test/support/tests.ts';
25-
import {
26-
filterBasicServerGenerators,
27-
shouldComposeWithLiquibase,
28-
shouldComposeWithSpringCloudStream,
29-
} from '../../../server/__test-support/index.ts';
25+
import { filterBasicServerGenerators, shouldComposeWithLiquibase } from '../../../server/__test-support/index.ts';
3026
import Generator from '../../../server/index.ts';
3127

3228
const generator = `${basename(resolve(import.meta.dirname, '../../'))}:${basename(import.meta.dirname)}`;
@@ -79,7 +75,6 @@ describe(`generator - ${databaseType}`, () => {
7975
it('contains correct databaseType', () => {
8076
runResult.assertFileContent('.yo-rc.json', new RegExp(`"databaseType": "${databaseType}"`));
8177
});
82-
shouldComposeWithSpringCloudStream(sampleConfig, () => runResult);
8378
shouldComposeWithLiquibase(false, () => runResult);
8479
});
8580
});

generators/spring-data/generators/couchbase/generator.spec.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ import {
2929
runResult,
3030
} from '../../../../lib/testing/index.ts';
3131
import { shouldSupportFeatures, testBlueprintSupport } from '../../../../test/support/tests.ts';
32-
import {
33-
filterBasicServerGenerators,
34-
shouldComposeWithLiquibase,
35-
shouldComposeWithSpringCloudStream,
36-
} from '../../../server/__test-support/index.ts';
32+
import { filterBasicServerGenerators, shouldComposeWithLiquibase } from '../../../server/__test-support/index.ts';
3733

3834
import Generator from './generator.ts';
3935

@@ -94,7 +90,6 @@ describe(`generator - ${databaseType}`, () => {
9490
it('contains correct databaseType', () => {
9591
runResult.assertFileContent('.yo-rc.json', new RegExp(`"databaseType": "${databaseType}"`));
9692
});
97-
shouldComposeWithSpringCloudStream(sampleConfig, () => runResult);
9893
shouldComposeWithLiquibase(false, () => runResult);
9994
});
10095
});

0 commit comments

Comments
 (0)