Skip to content

Commit

Permalink
keytool fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tcharl committed Sep 14, 2024
1 parent 75c9898 commit 615ba66
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 351 deletions.
2 changes: 1 addition & 1 deletion generators/angular/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default asWritingTask(function cleanupOldFilesTask(this, { application })
this.removeFile(`${application.clientSrcDir}app/shared/login/login.component.ts`);
this.removeFile(`${application.clientSrcDir}app/shared/login/login.component.html`);
this.removeFile(`${application.clientSrcDir}app/core/auth/user-route-access-service.ts`);
if (!application.authenticationTypeSession || !(application as any).communicationSpringWebsocket) {
if (!application.authenticationTypeSession || !application.communicationSpringWebsocket) {
this.removeFile(`${application.clientSrcDir}app/core/auth/csrf.service.ts`);
}
this.removeFolder(`${application.clientSrcDir}app/core/login`);
Expand Down
2 changes: 2 additions & 0 deletions generators/angular/support/translate-angular.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ describe('generator - angular - transform', () => {
beforeEach(() => {
let value = 0;
const testImpl = (key, data) => (key === 'blank' ? '' : `translated-value-${key}-${data ? `${inspect(data)}-` : ''}${value++}`);
// @ts-ignore
replaceAngularTranslations = createTranslationReplacer(esmocha.fn().mockImplementation(testImpl), {
jhiPrefix: 'jhi',
enableTranslation: false,
});
// @ts-ignore
enabledAngularTranslations = createTranslationReplacer(esmocha.fn().mockImplementation(testImpl), {
jhiPrefix: 'jhi',
enableTranslation: true,
Expand Down
57 changes: 34 additions & 23 deletions generators/angular/support/translate-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,15 @@ export type ReplacerOptions = { jhiPrefix: string; enableTranslation: boolean };
* Replace translation key with translation values
*
* @param {import('../generator-base.js')} generator
* @param getWebappTranslation
* @param {string} content
* @param {string} regexSource regular expression to find keys
* @param {object} [options]
* @param {number} [options.keyIndex]
* @param {number} [options.replacementIndex]
* @param {any} [options.escape]
* @returns {string}
*/
function replaceTranslationKeysWithText(
getWebappTranslation,
content,
regexSource,
getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string,
content: string,
regexSource: string,
{
keyIndex = 1,
replacementIndex = 1,
Expand Down Expand Up @@ -81,7 +78,11 @@ function replaceTranslationKeysWithText(
* @param {string} jsKey
* @returns string with jsKey value replaced
*/
function replaceJSTranslation(getWebappTranslation, content, jsKey) {
function replaceJSTranslation(
getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string,
content: string,
jsKey: string,
) {
return replaceTranslationKeysWithText(
getWebappTranslation,
content,
Expand All @@ -98,14 +99,14 @@ function replaceJSTranslation(getWebappTranslation, content, jsKey) {
* @param {string} content html content
* @returns string with pageTitle replaced
*/
function replacePageTitles(getWebappTranslation, content) {
function replacePageTitles(getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string, content: string) {
return replaceJSTranslation(getWebappTranslation, content, 'title');
}

/**
* @type {function(import('../generator-base.js'), string): string}
*/
function replacePlaceholders(getWebappTranslation, content) {
function replacePlaceholders(getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string, content: string) {
return replaceTranslationKeysWithText(getWebappTranslation, content, PLACEHOLDER_REGEX, { keyIndex: 2 });
}

Expand All @@ -114,7 +115,7 @@ function replacePlaceholders(getWebappTranslation, content) {
*
* @type {function(import('../generator-base.js'), string): string}
*/
function replaceErrorMessage(getWebappTranslation, content) {
function replaceErrorMessage(getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string, content: string) {
return replaceJSTranslation(getWebappTranslation, content, 'errorMessage');
}

Expand All @@ -123,7 +124,7 @@ function replaceErrorMessage(getWebappTranslation, content) {
* Or the translation value if translation is disabled.
*/
const tagTranslation = (
getWebappTranslation: any,
getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string,
{ enableTranslation, jhiPrefix }: ReplacerOptions,
{ key, parsedInterpolate, prefix, suffix }: JHITranslateConverterOptions,
) => {
Expand All @@ -149,7 +150,7 @@ const tagTranslation = (
* Or the translation value if translation is disabled.
*/
const validationTagTranslation = (
getWebappTranslation: any,
getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string,
{ enableTranslation, jhiPrefix }: ReplacerOptions,
{ key, parsedInterpolate, prefix, suffix }: JHITranslateConverterOptions,
) => {
Expand All @@ -175,7 +176,7 @@ const validationTagTranslation = (
* Or the translation value if translation is disabled.
*/
const tagPipeTranslation = (
getWebappTranslation: any,
getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string,
{ enableTranslation, jhiPrefix }: ReplacerOptions,
{ key, parsedInterpolate, prefix, suffix }: JHITranslateConverterOptions,
) => {
Expand All @@ -201,7 +202,7 @@ const tagPipeTranslation = (
* Or the translation value if translation is disabled.
*/
const tagEnumTranslation = (
getWebappTranslation: any,
getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string,
{ enableTranslation, jhiPrefix }: ReplacerOptions,
{ key, parsedInterpolate, prefix, suffix }: JHITranslateConverterOptions,
) => {
Expand All @@ -222,7 +223,7 @@ const tagEnumTranslation = (
* Or the translation value if translation is disabled.
*/
const pipeTranslation = (
getWebappTranslation: any,
getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string,
{ enableTranslation }: ReplacerOptions,
{ key, prefix, suffix }: JHITranslateConverterOptions,
) => {
Expand All @@ -237,7 +238,7 @@ const pipeTranslation = (
* Get translation value.
*/
const valueTranslation = (
getWebappTranslation: any,
getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string,
_replacerOptions: ReplacerOptions,
{ filePath, key, prefix, suffix }: JHITranslateConverterOptions,
) => {
Expand All @@ -256,7 +257,7 @@ const valueTranslation = (
* Or the translation value if translation is disabled.
*/
const pipeEnumTranslation = (
getWebappTranslation: any,
getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string,
{ enableTranslation }: ReplacerOptions,
{ key, parsedInterpolate, prefix, suffix }: JHITranslateConverterOptions,
) => {
Expand All @@ -274,7 +275,11 @@ const pipeEnumTranslation = (

const replaceImplementations: Record<
string,
(getWebappTranslation: any, replacerOpts: ReplacerOptions, translateOpts: JHITranslateConverterOptions) => string
(
getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string,
replacerOpts: ReplacerOptions,
translateOpts: JHITranslateConverterOptions,
) => string
> = {
Tag: tagTranslation,
TagPipe: tagPipeTranslation,
Expand All @@ -291,7 +296,10 @@ const replaceImplementations: Record<
* @type {import('../generator-base.js').EditFileCallback}
* @this {import('../generator-base.js')}
*/
export const createTranslationReplacer = (getWebappTranslation, opts: ReplacerOptions | boolean) => {
export const createTranslationReplacer = (
getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string,
opts: ReplacerOptions | boolean,
) => {
const htmlJhiTranslateReplacer = createJhiTransformTranslateReplacer(getWebappTranslation, { escapeHtml: true });
const htmlJhiTranslateStringifyReplacer = createJhiTransformTranslateStringifyReplacer(getWebappTranslation);
let translationReplacer: ((content: string, filePath: string) => string) | undefined;
Expand All @@ -309,7 +317,7 @@ export const createTranslationReplacer = (getWebappTranslation, opts: ReplacerOp
{ prefixPattern: '>\\s*', suffixPattern: '\\s*<' },
);
}
return function replaceAngularTranslations(content, filePath) {
return function replaceAngularTranslations(content: string, filePath: string) {
if (filePath.endsWith('.html')) {
if (!enableTranslation) {
content = content.replace(new RegExp(TRANSLATE_REGEX, 'g'), '');
Expand All @@ -322,7 +330,7 @@ export const createTranslationReplacer = (getWebappTranslation, opts: ReplacerOp
content = htmlJhiTranslateStringifyReplacer(content);
}
if (/(:?\.html|.ts)$/.test(filePath)) {
content = translationReplacer?.(content, filePath);
content = translationReplacer ? translationReplacer?.(content, filePath) : content;
}
if (!enableTranslation) {
if (/(:?route|module)\.ts$/.test(filePath)) {
Expand All @@ -339,7 +347,10 @@ export const createTranslationReplacer = (getWebappTranslation, opts: ReplacerOp
const minimatch = new Minimatch('**/*{.html,.ts}');
export const isTranslatedAngularFile = file => minimatch.match(file.path);

export const translateAngularFilesTransform = (getWebappTranslation, opts: ReplacerOptions | boolean) => {
export const translateAngularFilesTransform = (
getWebappTranslation: (key: string, val?: Record<string, any> | undefined) => string,
opts: ReplacerOptions | boolean,
) => {
const translate = createTranslationReplacer(getWebappTranslation, opts);
return passthrough(file => {
file.contents = Buffer.from(translate(file.contents.toString(), file.path));
Expand Down
2 changes: 1 addition & 1 deletion generators/base/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ export type Control = BaseApplicationControlProperties & {
* cleanupFiles({ '6.0.0': ['file1', 'file2', [application.shouldRemove, 'file3']] })
*/
cleanupFiles: (cleanup: Record<string, (string | [boolean, ...string[]])[]>) => Promise<void>;
getWebappTranslation?: (s: string, data?: Record<string, any>) => string;
getWebappTranslation: (s: string, data?: Record<string, any>) => string;
};
12 changes: 0 additions & 12 deletions generators/server/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ exports[`generator - server composing databaseType option no with jwt should mat
"src/main/resources/config/application.yml": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
"src/main/resources/i18n/messages.properties": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -376,9 +373,6 @@ exports[`generator - server composing databaseType option no with oauth2 should
"src/main/resources/config/application.yml": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
"src/main/resources/i18n/messages.properties": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -585,9 +579,6 @@ exports[`generator - server composing databaseType option no with session should
"src/main/resources/config/application.yml": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
"src/main/resources/i18n/messages.properties": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -1022,9 +1013,6 @@ exports[`generator - server with entities should match files snapshot 1`] = `
"src/main/resources/config/liquibase/master.xml": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
"src/main/resources/i18n/messages.properties": {
"stateCleared": "modified",
},
Expand Down
3 changes: 0 additions & 3 deletions generators/server/support/__snapshots__/needles.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,6 @@ exports[`generator - server - support - needles generated project should match s
"src/main/resources/config/application.yml": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
"src/main/resources/i18n/messages.properties": {
"stateCleared": "modified",
},
Expand Down
6 changes: 0 additions & 6 deletions generators/spring-boot/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ exports[`generator - spring-boot with jwt should match generated files snapshot
"src/main/resources/config/application.yml": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
"src/main/resources/i18n/messages.properties": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -520,9 +517,6 @@ exports[`generator - spring-boot with oauth2 should match generated files snapsh
"src/main/resources/config/application.yml": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
"src/main/resources/i18n/messages.properties": {
"stateCleared": "modified",
},
Expand Down
10 changes: 5 additions & 5 deletions generators/spring-boot/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
APPLICATION_TYPE_MICROSERVICE,
applicationTypes,
cacheTypes,
clientFrameworkTypes,
databaseTypes,
fieldTypes,
messageBrokerTypes,
Expand All @@ -71,12 +72,11 @@ const { CASSANDRA, COUCHBASE, MONGODB, NEO4J, SQL } = databaseTypes;
const { MICROSERVICE, GATEWAY } = applicationTypes;
const { KAFKA, PULSAR } = messageBrokerTypes;
const { ELASTICSEARCH } = searchEngineTypes;
const { NO: NO_CLIENT } = clientFrameworkTypes;

const { BYTES: TYPE_BYTES, BYTE_BUFFER: TYPE_BYTE_BUFFER } = fieldTypes.RelationalOnlyDBTypes;
const { CUCUMBER, GATLING } = testFrameworkTypes;
export default class SpringBootGenerator extends BaseApplicationGenerator {
fakeKeytool;

async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints();
Expand Down Expand Up @@ -208,7 +208,7 @@ export default class SpringBootGenerator extends BaseApplicationGenerator {
return this.asComposingComponentTaskGroup({
async composing() {
const { clientFramework, skipClient } = this.jhipsterConfigWithDefaults;
if (!skipClient && clientFramework !== 'no') {
if (!skipClient && clientFramework !== NO_CLIENT) {
// When using prompts, clientFramework will only be known after composing priority.
await this.composeWithJHipster('jhipster:java:node');
}
Expand All @@ -228,7 +228,7 @@ export default class SpringBootGenerator extends BaseApplicationGenerator {
get preparing() {
return this.asPreparingTaskGroup({
checksWebsocket({ application }) {
const { websocket } = application as any;
const { websocket } = application;
if (websocket && websocket !== NO_WEBSOCKET) {
if (application.reactive) {
throw new Error('Spring Websocket is not supported with reactive applications.');
Expand Down Expand Up @@ -460,7 +460,7 @@ public void set${javaBeanCase(propertyName)}(${propertyType} ${propertyName}) {
},
async generateKeyStore({ application }) {
const keyStoreFile = this.destinationPath(`${application.srcMainResources}config/tls/keystore.p12`);
if (this.fakeKeytool) {
if (application.fakeKeytool) {
this.writeDestination(keyStoreFile, 'fake key-tool');
} else {
this.validateResult(await generateKeyStore(keyStoreFile, { packageName: application.packageName! }));
Expand Down
Loading

0 comments on commit 615ba66

Please sign in to comment.