Skip to content

Commit a9680c9

Browse files
authored
Update spring-cloud generator (#31804)
* Update spring-cloud generator * Update spring-cloud generator (review)
1 parent 454c090 commit a9680c9

File tree

11 files changed

+195
-9
lines changed

11 files changed

+195
-9
lines changed

.blueprint/github-build-matrix/support/__snapshots__/git-chages.spec.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,28 @@ exports[`git-changes generators/spring-cache/index.ts should match changes snaps
792792
}
793793
`;
794794

795+
exports[`git-changes generators/spring-cloud/index.ts should match changes snapshot 1`] = `
796+
{
797+
"angular": false,
798+
"angularWorkflow": false,
799+
"base": false,
800+
"ci": false,
801+
"client": false,
802+
"common": false,
803+
"devBlueprint": false,
804+
"devserverWorkflow": false,
805+
"e2e": false,
806+
"graalvm": false,
807+
"java": true,
808+
"react": false,
809+
"reactWorkflow": false,
810+
"sonarPr": false,
811+
"vue": false,
812+
"vueWorkflow": false,
813+
"workspaces": false,
814+
}
815+
`;
816+
795817
exports[`git-changes generators/spring-data/index.ts should match changes snapshot 1`] = `
796818
{
797819
"angular": false,

generators/generate-blueprint/__snapshots__/generator.spec.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,15 @@ exports[`generator - generate-blueprint with all option should match snapshot 1`
12141214
"generators/spring-cache/templates/template-file-spring-cache.ejs": {
12151215
"stateCleared": "modified",
12161216
},
1217+
"generators/spring-cloud/command.js": {
1218+
"stateCleared": "modified",
1219+
},
1220+
"generators/spring-cloud/generator.js": {
1221+
"stateCleared": "modified",
1222+
},
1223+
"generators/spring-cloud/generator.spec.js": {
1224+
"stateCleared": "modified",
1225+
},
12171226
"generators/spring-cloud/generators/gateway/command.js": {
12181227
"stateCleared": "modified",
12191228
},
@@ -1259,6 +1268,12 @@ exports[`generator - generate-blueprint with all option should match snapshot 1`
12591268
"generators/spring-cloud/generators/pulsar/templates/template-file-spring-cloud:pulsar.ejs": {
12601269
"stateCleared": "modified",
12611270
},
1271+
"generators/spring-cloud/index.js": {
1272+
"stateCleared": "modified",
1273+
},
1274+
"generators/spring-cloud/templates/template-file-spring-cloud.ejs": {
1275+
"stateCleared": "modified",
1276+
},
12621277
"generators/spring-data/command.js": {
12631278
"stateCleared": "modified",
12641279
},

generators/generate-blueprint/internal/lookup-namespaces.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ describe('lookupGeneratorsNamespaces', () => {
103103
"spring-boot:oauth2",
104104
"spring-boot:websocket",
105105
"spring-cache",
106+
"spring-cloud",
106107
"spring-cloud:gateway",
107108
"spring-cloud:kafka",
108109
"spring-cloud:pulsar",

generators/spring-boot/command.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,7 @@ const command = {
232232
scope: 'storage',
233233
},
234234
},
235-
import: [
236-
'java',
237-
'liquibase',
238-
'jhipster:spring-data:relational',
239-
'jhipster:spring-cloud:gateway',
240-
'spring-cache',
241-
'jhipster:spring-cloud:kafka',
242-
'jhipster:spring-cloud:pulsar',
243-
],
235+
import: ['java', 'liquibase', 'jhipster:spring-data:relational', 'spring-cache', 'jhipster:spring-cloud'],
244236
} as const satisfies JHipsterCommandDefinition<any>;
245237

246238
export default command;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`generator - spring-cloud with default config should match files snapshot 1`] = `
4+
{
5+
".yo-rc.json": {
6+
"stateCleared": "modified",
7+
},
8+
}
9+
`;

generators/spring-cloud/command.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright 2013-2025 the original author or authors from the JHipster project.
3+
*
4+
* This file is part of the JHipster project, see https://www.jhipster.tech/
5+
* for more information.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* https://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
import type { JHipsterCommandDefinition } from '../../lib/command/types.ts';
20+
21+
const command = {
22+
configs: {},
23+
import: ['jhipster:spring-cloud:gateway', 'jhipster:spring-cloud:kafka', 'jhipster:spring-cloud:pulsar'],
24+
} as const satisfies JHipsterCommandDefinition;
25+
26+
export default command;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { before, describe, expect, it } from 'esmocha';
2+
import { basename } from 'node:path';
3+
4+
import { defaultHelpers as helpers, result } from '../../lib/testing/index.ts';
5+
import { shouldSupportFeatures, testBlueprintSupport } from '../../test/support/tests.ts';
6+
7+
import Generator from './index.ts';
8+
9+
const generator = basename(import.meta.dirname);
10+
11+
describe(`generator - ${generator}`, () => {
12+
shouldSupportFeatures(Generator);
13+
describe('blueprint support', () => testBlueprintSupport(generator));
14+
15+
describe('with default config', () => {
16+
before(async () => {
17+
await helpers.runJHipster(generator).withJHipsterConfig();
18+
});
19+
20+
it('should match files snapshot', () => {
21+
expect(result.getStateSnapshot()).toMatchSnapshot();
22+
});
23+
});
24+
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Copyright 2013-2025 the original author or authors from the JHipster project.
3+
*
4+
* This file is part of the JHipster project, see https://www.jhipster.tech/
5+
* for more information.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* https://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import BaseApplicationGenerator from '../base-application/index.ts';
21+
22+
import type {
23+
Application as SpringCloudApplication,
24+
Config as SpringCloudConfig,
25+
Entity as SpringCloudEntity,
26+
Options as SpringCloudOptions,
27+
Source as SpringCloudSource,
28+
} from './types.ts';
29+
30+
/**
31+
* Utility class with types.
32+
*/
33+
export class SpringCloudApplicationGenerator extends BaseApplicationGenerator<
34+
SpringCloudEntity,
35+
SpringCloudApplication<SpringCloudEntity>,
36+
SpringCloudConfig,
37+
SpringCloudOptions,
38+
SpringCloudSource
39+
> {}
40+
41+
export default class SpringCloudGenerator extends SpringCloudApplicationGenerator {
42+
async beforeQueue() {
43+
if (!this.fromBlueprint) {
44+
await this.composeWithBlueprints();
45+
}
46+
47+
await this.dependsOnBootstrap('spring-boot');
48+
}
49+
50+
get composing() {
51+
return this.asComposingTaskGroup({
52+
async composeCloud() {
53+
const { applicationType, messageBroker } = this.jhipsterConfigWithDefaults;
54+
55+
if (applicationType === 'gateway') {
56+
await this.composeWithJHipster('jhipster:spring-cloud:gateway');
57+
}
58+
59+
if (messageBroker === 'kafka') {
60+
await this.composeWithJHipster('jhipster:spring-cloud:kafka');
61+
}
62+
if (messageBroker === 'pulsar') {
63+
await this.composeWithJHipster('jhipster:spring-cloud:pulsar');
64+
}
65+
},
66+
});
67+
}
68+
69+
get [BaseApplicationGenerator.COMPOSING]() {
70+
return this.delegateTasksToBlueprint(() => this.composing);
71+
}
72+
}

generators/spring-cloud/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright 2013-2025 the original author or authors from the JHipster project.
3+
*
4+
* This file is part of the JHipster project, see https://www.jhipster.tech/
5+
* for more information.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* https://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
export { default } from './generator.ts';
20+
export { default as command } from './command.ts';

generators/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ type GeneratorsByNamespace = {
145145
'jhipster:spring-boot:websocket': import('./spring-boot/generators/websocket/generator.ts').default;
146146
'spring-cache': import('./spring-cache/generator.ts').default;
147147
'jhipster:spring-cache': import('./spring-cache/generator.ts').default;
148+
'spring-cloud': import('./spring-cloud/generator.ts').default;
149+
'jhipster:spring-cloud': import('./spring-cloud/generator.ts').default;
148150
'jhipster:spring-cloud:gateway': import('./spring-cloud/generators/gateway/generator.ts').default;
149151
'jhipster:spring-cloud:kafka': import('./spring-cloud/generators/kafka/generator.ts').default;
150152
'jhipster:spring-cloud:pulsar': import('./spring-cloud/generators/pulsar/generator.ts').default;

0 commit comments

Comments
 (0)