Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split java/domain java/bootstrap generators #25716

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Options:
--feign-client Generate a feign client
--sync-user-with-idp Allow relationships with User for oauth2 applications
--with-generated-flag Add a GeneratedByJHipster annotation to all generated java classes and interfaces
--package-name <value> The package name for the generated application
--dev-database-type <value> Development database
--client-framework <value> Provide client framework for the application (choices: "angular", "react", "vue", "no")
--microfrontend Enable microfrontend support
Expand Down Expand Up @@ -440,6 +441,9 @@ exports[`generator - app with default config should match snapshot 1`] = `
"enableSwaggerCodegen": false,
"enableTranslation": true,
"endpointPrefix": "",
"entityPackages": [
"com.mycompany.myapp",
],
"entitySuffix": "",
"fakerSeed": undefined,
"feignClient": undefined,
Expand Down Expand Up @@ -1018,6 +1022,9 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"enableSwaggerCodegen": false,
"enableTranslation": true,
"endpointPrefix": "",
"entityPackages": [
"com.mycompany.myapp",
],
"entitySuffix": "",
"fakerSeed": undefined,
"feignClient": undefined,
Expand Down Expand Up @@ -1590,6 +1597,9 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"enableSwaggerCodegen": false,
"enableTranslation": true,
"endpointPrefix": "services/jhipster",
"entityPackages": [
"com.mycompany.myapp",
],
"entitySuffix": "",
"fakerSeed": undefined,
"feignClient": undefined,
Expand Down
21 changes: 21 additions & 0 deletions generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,27 @@ You can ignore this error by passing '--skip-checks' to jhipster command.`);
return this.prompt(this.prepareQuestions(module?.command?.configs));
}

/**
* Load the current JHipster command storage configuration into the context.
*/
async loadCurrentJHipsterCommandConfig(context: any) {
const module: any = await this._meta?.importModule?.();
const command: JHipsterCommandDefinition | undefined = module?.command;
if (!command?.configs) {
throw new Error(`Configs not found for generator ${this.options.namespace}`);
}

const config = (this as any).jhipsterConfigWithDefaults;
Object.entries(command.configs).forEach(([name, def]) => {
if (def.scope === 'storage') {
context[name] = context[name] ?? config?.[name] ?? this.config.get(name);
}
if (def.scope === 'blueprint') {
context[name] = context[name] ?? this.blueprintStorage?.get(name);
}
});
}

parseJHipsterCommand(commandDef: JHipsterCommandDefinition) {
if (commandDef.arguments) {
this.parseJHipsterArguments(commandDef.arguments);
Expand Down
1 change: 1 addition & 0 deletions generators/base/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export type PromptSpec = {
default?: any | ((any) => any);
filter?: any | ((any) => any);
transformer?: any | ((any) => any);
validate?: any | ((any) => any);
};

export type JHipsterArgumentConfig = SetOptional<ArgumentSpec, 'name'> & { scope?: 'storage' | 'blueprint' | 'generator' };
Expand Down
36 changes: 0 additions & 36 deletions generators/java/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

exports[`generator - java with default config should match files snapshot 1`] = `
{
".jhipster/Bar.json": {
"stateCleared": "modified",
},
".jhipster/Foo.json": {
"stateCleared": "modified",
},
".yo-rc.json": {
"stateCleared": "modified",
},
Expand All @@ -17,18 +11,6 @@ exports[`generator - java with default config should match files snapshot 1`] =
"src/main/java/com/mycompany/myapp/domain/Authority.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/Bar.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/Foo.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/enumeration/MyEnum.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/enumeration/package-info.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/domain/package-info.java": {
"stateCleared": "modified",
},
Expand All @@ -47,23 +29,5 @@ exports[`generator - java with default config should match files snapshot 1`] =
"src/test/java/com/mycompany/myapp/domain/AuthorityTestSamples.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/BarAsserts.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/BarTest.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/BarTestSamples.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/FooAsserts.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/FooTest.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/domain/FooTestSamples.java": {
"stateCleared": "modified",
},
}
`;
40 changes: 2 additions & 38 deletions generators/java/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,8 @@
import { JHipsterCommandDefinition } from '../base/api.js';

const command: JHipsterCommandDefinition = {
options: {
withGeneratedFlag: {
description: 'Add a GeneratedByJHipster annotation to all generated java classes and interfaces',
type: Boolean,
scope: 'storage',
},
packageInfoFile: {
description: 'write package-info.java file for every package',
type: Boolean,
default: true,
scope: 'generator',
hide: true,
},
generateEntities: {
type: Boolean,
default: true,
scope: 'generator',
hide: true,
},
useJakartaValidation: {
type: Boolean,
default: true,
scope: 'generator',
hide: true,
},
useJacksonIdentityInfo: {
type: Boolean,
default: false,
scope: 'generator',
hide: true,
},
generateEnums: {
type: Boolean,
default: true,
scope: 'generator',
hide: true,
},
},
options: {},
import: ['jhipster:java:bootstrap', 'jhipster:java:domain'],
};

export default command;
119 changes: 2 additions & 117 deletions generators/java/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import { before, it, describe, expect } from 'esmocha';
import { snakeCase } from 'lodash-es';

import { shouldSupportFeatures, testBlueprintSupport } from '../../test/support/tests.js';
import Generator from './index.js';
import { defaultHelpers as helpers, result } from '../../testing/index.js';

import { GENERATOR_JAVA } from '../generator-list.js';
import Generator from './index.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand All @@ -23,124 +21,11 @@ describe(`generator - ${generator}`, () => {

describe('with default config', () => {
before(async () => {
await helpers.runJHipster(GENERATOR_JAVA).withJHipsterConfig({}, [
{
name: 'Foo',
fields: [
{ fieldName: 'name', documentation: 'My Name', fieldType: 'String', fieldValidateRules: ['required'] },
{ fieldName: 'myEnum', fieldType: 'MyEnum', fieldValues: 'FRENCH,ENGLISH', fieldTypeDocumentation: 'Enum Doc' },
],
},
{
name: 'Bar',
documentation: 'Custom Bar',
fields: [{ fieldName: 'name2', fieldType: 'String', fieldValidateRules: ['required'] }],
},
]);
await helpers.runJHipster(generator).withJHipsterConfig();
});

it('should match files snapshot', () => {
expect(result.getStateSnapshot()).toMatchSnapshot();
});

it('should generate entities containing jakarta', () => {
result.assertFileContent('src/main/java/com/mycompany/myapp/domain/Foo.java', 'jakarta');
});

it('should generate javadocs', () => {
result.assertFileContent('src/main/java/com/mycompany/myapp/domain/Foo.java', '* A Foo');
result.assertFileContent('src/main/java/com/mycompany/myapp/domain/Foo.java', '* My Name');
result.assertFileContent('src/main/java/com/mycompany/myapp/domain/Bar.java', '* Custom Bar');
});

it('should generate openapi @Schema', () => {
result.assertFileContent('src/main/java/com/mycompany/myapp/domain/Bar.java', '@Schema(description = "Custom Bar")');
});

it('should write enum files', () => {
result.assertFile('src/main/java/com/mycompany/myapp/domain/enumeration/MyEnum.java');
expect(Object.keys(result.getStateSnapshot('**/enumeration/**')).length).toBe(2);
});

it('should generate enum javadoc', () => {
result.assertFileContent('src/main/java/com/mycompany/myapp/domain/enumeration/MyEnum.java', '* Enum Doc');
});

it('should have options defaults set', () => {
expect(result.generator.generateEntities).toBe(true);
expect(result.generator.generateEnums).toBe(true);
expect(result.generator.useJakartaValidation).toBe(true);
});
});

it('packageName with reserved keyword', async () => {
await expect(helpers.runJHipster(GENERATOR_JAVA).withJHipsterConfig({ packageName: 'com.public.myapp' })).rejects.toThrow(
'The package name "com.public.myapp" contains a reserved Java keyword "public".',
);
});

describe('with jakarta and enums disabled', () => {
before(async () => {
await helpers
.runJHipster(GENERATOR_JAVA)
.withJHipsterConfig({}, [
{
name: 'Foo',
fields: [
{ fieldName: 'name', fieldType: 'String', fieldValidateRules: ['required'] },
{ fieldName: 'myEnum', fieldType: 'MyEnum', fieldValues: 'FRENCH,ENGLISH' },
],
},
])
.withOptions({ useJakartaValidation: false, generateEnums: false });
});

it('should generate entities not containing jakarta', () => {
result.assertNoFileContent('src/main/java/com/mycompany/myapp/domain/Foo.java', 'jakarta');
});

it('should not write enum files', () => {
expect(Object.keys(result.getStateSnapshot('**/enumeration/**')).length).toBe(0);
});
});

describe('with entities disabled', () => {
before(async () => {
await helpers
.runJHipster(GENERATOR_JAVA)
.withJHipsterConfig({}, [
{
name: 'Foo',
fields: [
{ fieldName: 'name', fieldType: 'String', fieldValidateRules: ['required'] },
{ fieldName: 'myEnum', fieldType: 'MyEnum', fieldValues: 'FRENCH,ENGLISH' },
],
},
])
.withOptions({ generateEntities: false });
});

it('should not contain jakarta', () => {
result.assertNoFile('src/main/java/com/mycompany/myapp/domain/Foo.java');
});
});

describe('with custom properties values', () => {
before(async () => {
await helpers
.runJHipster(GENERATOR_JAVA)
.withJHipsterConfig({})
.onGenerator(generator => {
generator.generateEntities = false;
generator.generateEnums = false;
generator.useJakartaValidation = false;
});
});

it('should not override custom values', () => {
expect(result.generator.generateEntities).toBe(false);
expect(result.generator.generateEnums).toBe(false);
expect(result.generator.useJakartaValidation).toBe(false);
});
});
});
Loading
Loading