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

Adjusts for kotlin blueprint. #26463

Merged
merged 8 commits into from
Jun 18, 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
2 changes: 1 addition & 1 deletion generators/base-application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export default class BaseApplicationGenerator<
if ([PREPARING, LOADING].includes(priorityName)) {
return {
application,
applicationDefaults: data => mutateData(application, data),
applicationDefaults: data => mutateData(application, { __override__: false, ...data }),
};
}
if (LOADING_ENTITIES === priorityName) {
Expand Down
6 changes: 4 additions & 2 deletions generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,10 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;
cache: false,
};
const copyOptions = { noGlob: true };
// TODO drop for v8 final release
const data = (this as any).jhipster7Migration ? createJHipster7Context(this, context, { ignoreWarnings: true }) : context;
const { jhipster7Migration } = this as any;
const data = jhipster7Migration
? createJHipster7Context(this, context, { log: jhipster7Migration === 'verbose' ? msg => this.log.info(msg) : () => {} })
: context;
if (useAsync) {
await (this as any).renderTemplateAsync(sourceFileFrom, targetFile, data, renderOptions, copyOptions);
} else {
Expand Down
2 changes: 1 addition & 1 deletion generators/base/support/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const mutateData = (
if (override !== false || context[key] === undefined) {
context[key] = value(context);
}
} else if (context[key] === undefined) {
} else if (context[key] === undefined || override === true) {
context[key] = value;
}
}
Expand Down
266 changes: 189 additions & 77 deletions generators/base/support/jhipster7-context.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
/* eslint-disable no-console */
import chalk from 'chalk';
import { camelCase } from 'lodash-es';

import { isReservedTableName } from '../../../jdl/jhipster/reserved-keywords.js';
import { upperFirstCamelCase } from './string.js';
import {
getJavaValueGeneratorForType,
getJoinTableName,
getPrimaryKeyValue,
getSpecificationBuildForType,
hibernateSnakeCase,
} from '../../server/support/index.js';
import { getDBCExtraOption } from '../../spring-data-relational/support/database-data.js';
import { getJdbcUrl, getR2dbcUrl } from '../../spring-data-relational/support/database-url.js';
import { fieldTypes } from '../../../jdl/index.js';

const { BYTES, BYTE_BUFFER } = fieldTypes.RelationalOnlyDBTypes;

const deprecatedProperties = {
GRADLE_VERSION: {
Expand All @@ -18,6 +34,18 @@ const deprecatedProperties = {
replacement: 'jhipsterDependenciesVersion',
get: ({ data }) => data.jhipsterDependenciesVersion,
},
JAVA_VERSION: {
replacement: 'javaVersion',
get: ({ data }) => data.javaVersion,
},
JAVA_COMPATIBLE_VERSIONS: {
replacement: 'javaCompatibleVersions',
get: ({ data }) => data.javaCompatibleVersions,
},
SPRING_BOOT_VERSION: {
replacement: "javaDependencies['spring-boot']",
get: ({ data }) => data.javaDependencies['spring-boot'],
},
DOCKER_DIR: {
replacement: 'dockerServicesDir',
get: ({ data }) => data.dockerServicesDir,
Expand Down Expand Up @@ -124,7 +152,7 @@ const deprecatedProperties = {
},
dependabotPackageJson: {
replacement: 'nodeDependencies',
get: ({ data }) => data.nodeDependencies,
get: ({ data }) => ({ dependencies: data.nodeDependencies, devDependencies: data.nodeDependencies }),
},
cacheManagerIsAvailable: {
replacement: 'cacheProviderAny',
Expand Down Expand Up @@ -158,91 +186,175 @@ const deprecatedProperties = {
replacement: 'prodDatabaseTypeMssql',
get: ({ data }) => data.prodDatabaseTypeMssql,
},
cacheProviderEhCache: {
replacement: 'cacheProviderEhcache',
get: ({ data }) => data.cacheProviderEhcache,
},

getJDBCUrl: {
replacement: '(prod/dev)(Jdbc/Liquibase)Url or this.getJDBCUrl',
get: () => getJdbcUrl,
},
getR2DBCUrl: {
replacement: '(prod/dev)R2dbcUrl of this.getR2DBCUrl',
get: () => getR2dbcUrl,
},
getDBCExtraOption: {
replacement: '???',
get: () => getDBCExtraOption,
},
getPrimaryKeyValue: {
replacement: 'current generator this.getPrimaryKeyValue',
get: () => getPrimaryKeyValue,
},
getJoinTableName: {
replacement: 'joinTable property',
get:
() =>
(...args) =>
getJoinTableName(...args).value,
},
getJavaValueGeneratorForType: {
replacement: 'javaValueGenerator property',
get: () => type => getJavaValueGeneratorForType(type).replace('longCount', 'count'),
},
asEntity: {
replacement: 'persistClass property',
get:
({ data }) =>
name =>
`${name}${data.entitySuffix}`,
},
asDto: {
replacement: 'restClass property',
get:
({ data }) =>
name =>
`${name}${data.dtoSuffix}`,
},
upperFirstCamelCase: {
replacement: 'upperFirstCamelCase* property alternative',
get: () => upperFirstCamelCase,
},
hasOauthUser: {
replacement: 'authenticationTypeOauth2 && generateBuiltInUserEntity',
get: ({ data }) => data.authenticationTypeOauth2 && data.generateBuiltInUserEntity,
},
getPrettierExtensions: {
replacement: 'prettierExtensions',
get:
({ data }) =>
() =>
data.prettierExtensions,
},
_generateSqlSafeName: {
replacement: 'relationshipSqlSafeName',
get: () => name => (isReservedTableName(name, 'sql') ? `e_${name}` : name),
},
isFilterableType: {
replacement: 'filterableField property',
get: () => fieldType => ![BYTES, BYTE_BUFFER].includes(fieldType),
},
getSpecificationBuilder: {
replacement: 'field.fieldJavaBuildSpecification || primaryKey.javaBuildSpecification',
get: () => getSpecificationBuildForType,
},
getColumnName: {
replacement: 'entityTableName || relationship.columnName',
get: () => hibernateSnakeCase,
},
};

const ejsBuiltInProperties = ['__append', '__line', 'escapeFn', 'include', 'undefined'];
const javascriptBuiltInProperties = ['parseInt', 'Boolean', 'JSON', 'Object', 'toString'];

const getProperty = (context, prop) => {
if (typeof prop === 'symbol') {
return undefined;
}
if (prop in deprecatedProperties) {
const { replacement, get } = deprecatedProperties[prop];
const value = get(context);
console.log(
`Template data ${chalk.yellow(String(prop))} was removed and should be replaced with ${chalk.yellow(replacement)}. Value: ${value}`,
);
return value;
}
if (prop?.startsWith?.('DOCKER_')) {
console.log(
`Template data ${chalk.yellow(String(prop))} was removed and should be replaced with ${chalk.yellow(
// eslint-disable-next-line no-template-curly-in-string
'dockerContainers.${dockerImage}',
)}.`,
);
}
const { generator, data } = context;
if (prop in data) {
return data[prop];
}
if (prop in generator) {
console.log(`Template data ${chalk.yellow(String(prop))} is a generator property.`);
console.log(`Change the template to '${chalk.yellow(`this.${String(prop)}`)}'`);
return generator[prop];
}
// console.log(`Template data '${chalk.yellow(String(prop))}' not found. Check your data.`);
// throw new Error(`Template data '${chalk.yellow(String(prop))}' not found. Check your data.`);
if (prop === 'undefined') {
throw new Error('Check your data');
}
return undefined;
};
const getPropertBuilder =
({ log = msg => console.log(msg) } = {}) =>
(context, prop) => {
if (typeof prop === 'symbol') {
return undefined;
}

const createHandler = ({ ignoreWarnings = false } = {}) => ({
...Object.fromEntries(
[
'apply',
'construct',
'defineProperty',
'deleteProperty',
'getOwnPropertyDescriptor',
'getPrototypeOf',
'isExtensible',
'ownKeys',
'preventExtensions',
'setPrototypeOf',
'set',
].map(method => [method, (...args) => console.log(`Fixme: template data called ${method}(${args?.pop() ?? ''})`)]),
),
ownKeys: ({ data }) => {
return Reflect.ownKeys(data);
},
getPrototypeOf: ({ data }) => {
return Object.getPrototypeOf(data);
},
getOwnPropertyDescriptor: ({ data }, prop) => {
return Object.getOwnPropertyDescriptor(data, prop);
},
has: (context, prop) => {
if (ejsBuiltInProperties.includes(prop)) {
return false;
const { generator, data } = context;
const value = prop in data ? data[prop] : undefined;
if (prop in deprecatedProperties) {
const { replacement, get } = deprecatedProperties[prop];
const fallBackValue = get(context);
const valueDesc = prop in data ? `Value: ${value}, ` : '';
log(
`Template data ${chalk.yellow(String(prop))} was removed and should be replaced with ${chalk.yellow(replacement)}. ${valueDesc}FallbackValue: ${fallBackValue}`,
);
return value ?? fallBackValue;
}
if (javascriptBuiltInProperties.includes(prop)) {
if (!ignoreWarnings) {
console.log(`${chalk.yellow(prop)} is a javascript built in symbol, its use is discouraged inside templates`);
}
return false;
if (prop?.startsWith?.('DOCKER_')) {
const container = camelCase(prop.replace('DOCKER_', '').replace('_CONTAINER', ''));
log(
`Template data ${chalk.yellow(String(prop))} was removed and should be replaced with ${chalk.yellow(
`dockerContainers.${container}`,
)}.`,
);
return value ?? data.dockerContainers[container];
}
const propValue = getProperty(context, prop);
if (propValue === undefined) {
return prop in context.data;
if (prop in data) {
return value;
}
return propValue !== undefined;
},
get: getProperty,
});
if (prop in generator) {
log(`Template data ${chalk.yellow(String(prop))} is a generator property.`);
log(`Change the template to '${chalk.yellow(`this.${String(prop)}`)}'`);
return generator[prop];
}
// console.log(`Template data '${chalk.yellow(String(prop))}' not found. Check your data.`);
// throw new Error(`Template data '${chalk.yellow(String(prop))}' not found. Check your data.`);
if (prop === 'undefined') {
throw new Error('Check your data');
}
return undefined;
};

const createHandler = ({ log } = {}) => {
const getProperty = getPropertBuilder({ log });
return {
...Object.fromEntries(
[
'apply',
'construct',
'defineProperty',
'deleteProperty',
'getOwnPropertyDescriptor',
'getPrototypeOf',
'isExtensible',
'ownKeys',
'preventExtensions',
'setPrototypeOf',
'set',
].map(method => [method, (...args) => console.log(`Fixme: template data called ${method}(${args?.pop() ?? ''})`)]),
),
ownKeys: ({ data }) => {
return Reflect.ownKeys(data);
},
getPrototypeOf: ({ data }) => {
return Object.getPrototypeOf(data);
},
getOwnPropertyDescriptor: ({ data }, prop) => {
return Object.getOwnPropertyDescriptor(data, prop);
},
has: (context, prop) => {
if (ejsBuiltInProperties.includes(prop)) {
return false;
}
if (javascriptBuiltInProperties.includes(prop)) {
log(`${chalk.yellow(prop)} is a javascript built in symbol, its use is discouraged inside templates`);
return false;
}
const propValue = getProperty(context, prop);
if (propValue === undefined) {
return prop in context.data;
}
return propValue !== undefined;
},
get: getProperty,
};
};

export default function createJHipster7Context(generator, data, options) {
return new Proxy({ generator, data }, createHandler(options));
Expand Down
2 changes: 1 addition & 1 deletion generators/bootstrap-application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class BootstrapApplicationGenerator extends BaseApplicationGenera
}

applicationDefaults({
useNpmWrapper: application => application.clientFrameworkAny && application.backendTypeSpringBoot,
useNpmWrapper: application => application.clientFrameworkAny && application.backendTypeJavaAny,
documentationArchiveUrl: ({ jhipsterVersion }) =>
`${JHIPSTER_DOCUMENTATION_URL}${JHIPSTER_DOCUMENTATION_ARCHIVE_PATH}v${jhipsterVersion}`,
});
Expand Down
2 changes: 1 addition & 1 deletion generators/ci-cd/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default class CiCdGenerator extends BaseApplicationGenerator {
postWriting({ application }) {
if (application.ciCdIntegrations.includes('deploy')) {
if (application.buildToolMaven) {
createPomStorage(this).addDistributionManagement({
createPomStorage(this, { sortFile: false }).addDistributionManagement({
releasesId: application.artifactoryReleasesId,
releasesUrl: application.artifactoryReleasesUrl,
snapshotsId: application.artifactorySnapshotsId,
Expand Down
2 changes: 1 addition & 1 deletion generators/heroku/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export default class HerokuGenerator extends BaseGenerator {
* @param {string} other - explicit other thing: build, dependencies...
*/
addMavenProfile(profileId, other) {
createPomStorage(this).addProfile({ id: profileId, content: other });
createPomStorage(this, { sortFile: false }).addProfile({ id: profileId, content: other });
}

/**
Expand Down
6 changes: 5 additions & 1 deletion generators/java/generators/bootstrap/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default class BootstrapGenerator extends BaseApplicationGenerator {
(application as any).domains = entityPackages;
},
generatedAnnotation({ application }) {
if (this.jhipsterConfig.withGeneratedFlag) {
if (this.jhipsterConfig.withGeneratedFlag && application.backendTypeJavaAny) {
this.queueTransformStream(
{
name: 'adding @GeneratedByJHipster annotations',
Expand All @@ -146,6 +146,8 @@ export default class BootstrapGenerator extends BaseApplicationGenerator {
}
},
generatedPackageInfo({ application }) {
if (!application.backendTypeJavaAny) return;

const { srcMainJava } = application;
if (this.packageInfoFile && srcMainJava) {
const mainPackageMatch = matchMainJavaFiles(srcMainJava!);
Expand Down Expand Up @@ -188,6 +190,8 @@ export default class BootstrapGenerator extends BaseApplicationGenerator {
get writing() {
return this.asWritingTaskGroup({
async writing({ application }) {
if (!application.backendTypeJavaAny) return;

await this.writeFiles({
blocks: [
javaMainPackageTemplatesBlock({
Expand Down
Loading
Loading