From 55336d28a4f8860c6d8381f750760b27bf3e6d6c Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Mon, 22 Jul 2024 13:45:14 -0300 Subject: [PATCH 1/7] enable ktlint formartting --- .github/workflows/angular.yml | 4 ++-- .github/workflows/react.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/angular.yml b/.github/workflows/angular.yml index 7e0aa1aff..157d276c7 100644 --- a/.github/workflows/angular.yml +++ b/.github/workflows/angular.yml @@ -108,7 +108,7 @@ jobs: #---------------------------------------------------------------------- # Install JHipster and generate project+entities #---------------------------------------------------------------------- - - run: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }} ${{ matrix.new-extra-args }} + - run: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }} ${{ matrix.new-extra-args }} - run: cli.cjs info #---------------------------------------------------------------------- # Detect changes against base commit @@ -120,7 +120,7 @@ jobs: !contains(github.event.pull_request.labels.*.name, 'pr: disable-compare') with: generator-path: jhipster-kotlin - cmd: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }} + cmd: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }} #---------------------------------------------------------------------- # Launch tests #---------------------------------------------------------------------- diff --git a/.github/workflows/react.yml b/.github/workflows/react.yml index c9a7a72da..84d2a5ca4 100644 --- a/.github/workflows/react.yml +++ b/.github/workflows/react.yml @@ -108,7 +108,7 @@ jobs: #---------------------------------------------------------------------- # Install JHipster and generate project+entities #---------------------------------------------------------------------- - - run: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }} ${{ matrix.new-extra-args }} + - run: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }} ${{ matrix.new-extra-args }} - run: cli.cjs info #---------------------------------------------------------------------- # Detect changes against base commit @@ -120,7 +120,7 @@ jobs: !contains(github.event.pull_request.labels.*.name, 'pr: disable-compare') with: generator-path: jhipster-kotlin - cmd: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }} + cmd: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }} #---------------------------------------------------------------------- # Launch tests #---------------------------------------------------------------------- From 0b735dddc397e78abb035a756796279d93c685ba Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 24 Jul 2024 08:02:33 -0300 Subject: [PATCH 2/7] increase workflow timeout due to ktlint format --- .github/workflows/angular.yml | 4 +++- .github/workflows/react.yml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/angular.yml b/.github/workflows/angular.yml index 157d276c7..b7fa29277 100644 --- a/.github/workflows/angular.yml +++ b/.github/workflows/angular.yml @@ -69,7 +69,9 @@ jobs: !contains(github.event.pull_request.title, '[ci skip]') && github.event.action != 'closed' && !contains(github.event.pull_request.labels.*.name, 'pr: skip-ci') - timeout-minutes: 25 + # ktlint takes 8 minutes to run, add additional 15 minutes + # https://github.com/pinterest/ktlint/issues/2754 + timeout-minutes: 40 strategy: fail-fast: false # Matrix available at https://github.com/jhipster/jhipster-kotlin/tree/main/test-integration/workflow-samples/ diff --git a/.github/workflows/react.yml b/.github/workflows/react.yml index 84d2a5ca4..c1e080682 100644 --- a/.github/workflows/react.yml +++ b/.github/workflows/react.yml @@ -69,7 +69,9 @@ jobs: !contains(github.event.pull_request.title, '[ci skip]') && github.event.action != 'closed' && !contains(github.event.pull_request.labels.*.name, 'pr: skip-ci') - timeout-minutes: 25 + # ktlint takes 8 minutes to run, add additional 15 minutes + # https://github.com/pinterest/ktlint/issues/2754 + timeout-minutes: 40 strategy: fail-fast: false # Matrix available at https://github.com/jhipster/jhipster-kotlin/tree/main/test-integration/workflow-samples/ From 06d14736b9fe956edb365f94ce398a0fdaf8fdf8 Mon Sep 17 00:00:00 2001 From: Marcelo Boveto Shima Date: Wed, 24 Jul 2024 10:37:29 -0300 Subject: [PATCH 3/7] add ktlint to dependabot --- .github/dependabot.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..7c604f89c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,26 @@ +# +# Copyright the original author or authors from the JHipster project. +# +# This file is part of the JHipster project, see https://www.jhipster.tech/ +# for more information. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +version: 2 +updates: + - package-ecosystem: 'gradle' + directory: '/generators/ktlint/resources/' + schedule: + interval: 'daily' + open-pull-requests-limit: 5 From d591ab2191a04ec7ee53002ed297659cbb41b556 Mon Sep 17 00:00:00 2001 From: Marcelo Boveto Shima Date: Mon, 22 Jul 2024 12:54:53 -0300 Subject: [PATCH 4/7] add ktlint generator --- .editorconfig | 2 +- .yo-rc.json | 9 +- .../__snapshots__/generator.spec.js.snap | 12 ++ generators/ktlint/command.js | 18 +++ generators/ktlint/generator.js | 107 ++++++++++++++++++ generators/ktlint/generator.spec.js | 26 +++++ generators/ktlint/index.js | 2 + .../ktlint-transform-using-threads.js | 38 +++++++ .../ktlint/internal/ktlint-transform.js | 34 ++++++ generators/ktlint/internal/ktlint-worker.js | 19 ++++ generators/ktlint/resources/build.gradle | 1 + .../resources/gradle/libs.versions.toml | 7 ++ .../templates/.gitignore.jhi.ktlint.ejs | 2 + generators/spring-boot/command.js | 8 +- generators/spring-boot/generator.js | 1 + generators/spring-boot/generator.spec.js | 3 +- generators/spring-boot/matrix.spec.js | 4 +- package-lock.json | 5 +- package.json | 5 +- test/app.spec.js | 90 +++++++-------- 20 files changed, 335 insertions(+), 58 deletions(-) create mode 100644 generators/ktlint/__snapshots__/generator.spec.js.snap create mode 100644 generators/ktlint/command.js create mode 100644 generators/ktlint/generator.js create mode 100644 generators/ktlint/generator.spec.js create mode 100644 generators/ktlint/index.js create mode 100644 generators/ktlint/internal/ktlint-transform-using-threads.js create mode 100644 generators/ktlint/internal/ktlint-transform.js create mode 100644 generators/ktlint/internal/ktlint-worker.js create mode 100644 generators/ktlint/resources/build.gradle create mode 100644 generators/ktlint/resources/gradle/libs.versions.toml create mode 100644 generators/ktlint/templates/.gitignore.jhi.ktlint.ejs diff --git a/.editorconfig b/.editorconfig index 4d13f069f..cb1a9d02c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,7 +14,7 @@ insert_final_newline = true # Change these settings to your own preference indent_style = space -indent_size = 2 +indent_size = 4 [*.md] trim_trailing_whitespace = false diff --git a/.yo-rc.json b/.yo-rc.json index 5093d9937..f56cf5232 100644 --- a/.yo-rc.json +++ b/.yo-rc.json @@ -1,11 +1,17 @@ { "generator-jhipster": { - "additionalSubGenerators": "", + "additionalSubGenerators": "ktlint", "baseName": "kotlin", "cli": true, "cliName": "khipster", "entities": [], "generators": { + "ktlint": { + "command": false, + "priorities": ["default"], + "sbs": null, + "written": true + }, "spring-boot": { "command": false, "priorities": ["initializing", "composing"], @@ -15,6 +21,7 @@ }, "jhipsterVersion": "8.5.0", "localBlueprint": false, + "packageJsonType": "module", "sampleWritten": true, "subGenerators": ["spring-boot"] } diff --git a/generators/ktlint/__snapshots__/generator.spec.js.snap b/generators/ktlint/__snapshots__/generator.spec.js.snap new file mode 100644 index 000000000..d307f9513 --- /dev/null +++ b/generators/ktlint/__snapshots__/generator.spec.js.snap @@ -0,0 +1,12 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`SubGenerator kotlin of kotlin JHipster blueprint > run > should succeed 1`] = ` +{ + ".yo-rc.json": { + "stateCleared": "modified", + }, + "package.json": { + "stateCleared": "modified", + }, +} +`; diff --git a/generators/ktlint/command.js b/generators/ktlint/command.js new file mode 100644 index 000000000..14419e32d --- /dev/null +++ b/generators/ktlint/command.js @@ -0,0 +1,18 @@ +/** + * @type {import('generator-jhipster').JHipsterCommandDefinition} + */ +const command = { + options: {}, + configs: { + skipKtlintFormat: { + cli: { + desc: 'Skip ktlintFormat', + type: Boolean, + }, + scope: 'generator', + }, + }, + arguments: {}, +}; + +export default command; diff --git a/generators/ktlint/generator.js b/generators/ktlint/generator.js new file mode 100644 index 000000000..09e6330fb --- /dev/null +++ b/generators/ktlint/generator.js @@ -0,0 +1,107 @@ +import { createWriteStream, existsSync } from 'node:fs'; +import { chmod, mkdir, rm } from 'node:fs/promises'; +import { platform } from 'node:os'; +import { join } from 'node:path'; +import { pipeline } from 'node:stream/promises'; +import BaseApplicationGenerator from 'generator-jhipster/generators/base-application'; +import axios from 'axios'; +import { createKtlintTransform, filterKtlintTransformFiles } from './internal/ktlint-transform.js'; + +export default class extends BaseApplicationGenerator { + ktlintFolder; + ktlintExecutable; + + constructor(args, opts, features) { + super(args, opts, { + ...features, + queueCommandTasks: true, + }); + } + + async beforeQueue() { + await this.dependsOnBootstrapApplicationServer(); + } + + get [BaseApplicationGenerator.LOADING]() { + return this.asLoadingTaskGroup({ + async loading({ application }) { + this.loadJavaDependenciesFromGradleCatalog(application.javaDependencies); + this.ktlintFolder = this.destinationPath('.ktlint', application.javaDependencies['ktlint-cli']); + this.ktlintExecutable = join(this.ktlintFolder, platform() === 'win32' ? 'ktlint.bat' : 'ktlint'); + }, + }); + } + + get [BaseApplicationGenerator.DEFAULT]() { + return this.asDefaultTaskGroup({ + async downloadKtlint({ application }) { + if (!this.options.skipKtlintFormat && !existsSync(this.ktlintExecutable)) { + await this.env.adapter.progress( + async () => { + try { + const ktlintVersion = application.javaDependencies['ktlint-cli']; + const ktlintUrl = 'https://github.com/pinterest/ktlint/releases/download/'; + + await mkdir(this.ktlintFolder, { recursive: true }); + + const response = await axios.get(`${ktlintUrl}${ktlintVersion}/ktlint`, { responseType: 'stream' }); + const ktlintFile = join(this.ktlintFolder, 'ktlint'); + await pipeline(response.data, createWriteStream(ktlintFile)); + await chmod(ktlintFile, 0o755); + + const batResponse = await axios.get(`${ktlintUrl}/${ktlintVersion}/ktlint.bat`, { responseType: 'stream' }); + await pipeline(batResponse.data, createWriteStream(join(this.ktlintFolder, 'ktlint.bat'))); + } catch (error) { + this.log.error('Failed to download ktlint'); + await rm(this.ktlintFolder, { recursive: true }); + throw error; + } + }, + { name: 'downloading ktlint' }, + ); + } + }, + async defaultTemplateTask({ control }) { + if (!this.options.skipKtlintFormat) { + const destinationPath = this.destinationPath(); + this.queueTransformStream( + { + name: 'formating using ktlint', + filter: file => filterKtlintTransformFiles(file) && file.path.startsWith(destinationPath), + refresh: false, + }, + createKtlintTransform.call(this, { + ktlintExecutable: this.ktlintExecutable, + cwd: destinationPath, + ignoreErrors: control.ignoreNeedlesError, + }), + ); + } + }, + }); + } + + get [BaseApplicationGenerator.WRITING]() { + return this.asWritingTaskGroup({ + async writing({ application }) { + await this.writeFiles({ + blocks: [{ templates: ['.gitignore.jhi.ktlint'] }], + context: application, + }); + }, + }); + } + + get [BaseApplicationGenerator.POST_WRITING]() { + return this.asPostWritingTaskGroup({ + async postWriting({ application }) { + const command = application.buildToolGradle ? './gradlew :ktlintFormat' : './mvnw ktlint:format'; + this.packageJson.merge({ + scripts: { + 'ktlint:format': command, + }, + }); + }, + }); + } +} diff --git a/generators/ktlint/generator.spec.js b/generators/ktlint/generator.spec.js new file mode 100644 index 000000000..9319b3b36 --- /dev/null +++ b/generators/ktlint/generator.spec.js @@ -0,0 +1,26 @@ +import { beforeAll, describe, expect, it } from 'vitest'; + +import { defaultHelpers as helpers, result } from 'generator-jhipster/testing'; + +const SUB_GENERATOR = 'ktlint'; +const SUB_GENERATOR_NAMESPACE = `jhipster-kotlin:${SUB_GENERATOR}`; + +describe('SubGenerator kotlin of kotlin JHipster blueprint', () => { + describe('run', () => { + beforeAll(async function () { + await helpers + .run(SUB_GENERATOR_NAMESPACE) + .withJHipsterConfig() + .withOptions({ + ignoreNeedlesError: true, + skipKtlintFormat: true, + }) + .withJHipsterLookup() + .withParentBlueprintLookup(['generators', 'generators/*/generators']); + }); + + it('should succeed', () => { + expect(result.getStateSnapshot()).toMatchSnapshot(); + }); + }); +}); diff --git a/generators/ktlint/index.js b/generators/ktlint/index.js new file mode 100644 index 000000000..3eccd6e86 --- /dev/null +++ b/generators/ktlint/index.js @@ -0,0 +1,2 @@ +export { default } from './generator.js'; +export { default as command } from './command.js'; diff --git a/generators/ktlint/internal/ktlint-transform-using-threads.js b/generators/ktlint/internal/ktlint-transform-using-threads.js new file mode 100644 index 000000000..edaa0c29f --- /dev/null +++ b/generators/ktlint/internal/ktlint-transform-using-threads.js @@ -0,0 +1,38 @@ +import { passthrough } from 'p-transform'; +import { Piscina } from 'piscina'; +import { filterKtlintTransformFiles } from './ktlint-transform.js'; + +export { filterKtlintTransformFiles }; + +/** + * Experimental transform using piscina to check performance. + */ +export const createKtlintTransform = function ({ ktlintExecutable, cwd, ignoreErrors } = {}) { + const pool = new Piscina({ + filename: new URL('../internal/ktlint-worker.js', import.meta.url).href, + }); + + return passthrough( + async file => { + if (!filterKtlintTransformFiles(file)) { + return; + } + const { result, error, info } = await pool.run({ ktlintExecutable, cwd, fileContents: file.contents.toString('utf8') }); + if (result) { + file.contents = Buffer.from(result); + } + if (info) { + this?.log?.info?.(info.replaceAll('', file.relative)); + } + if (error) { + if (!ignoreErrors) { + throw new Error(error); + } + this?.log?.warn?.(error); + } + }, + () => { + pool.destroy(); + }, + ); +}; diff --git a/generators/ktlint/internal/ktlint-transform.js b/generators/ktlint/internal/ktlint-transform.js new file mode 100644 index 000000000..c35b2e0cb --- /dev/null +++ b/generators/ktlint/internal/ktlint-transform.js @@ -0,0 +1,34 @@ +import { extname } from 'node:path'; +import os from 'node:os'; +import { OutOfOrder } from 'p-transform'; +import { isFileStateDeleted, isFileStateModified } from 'mem-fs-editor/state'; +import ktlintWorker from './ktlint-worker.js'; + +export const filterKtlintTransformFiles = file => isFileStateModified(file) && !isFileStateDeleted(file) && extname(file.path) === '.kt'; + +export const createKtlintTransform = function ({ ktlintExecutable, cwd, ignoreErrors } = {}) { + return new OutOfOrder( + async file => { + if (!filterKtlintTransformFiles(file)) { + return file; + } + const { result, error, info } = await ktlintWorker({ ktlintExecutable, cwd, fileContents: file.contents.toString('utf8') }); + if (result) { + file.contents = Buffer.from(result); + } + if (info) { + this?.log?.info?.(info.replaceAll('', file.relative)); + } + if (error) { + if (!ignoreErrors) { + throw new Error(error); + } + this?.log?.warn?.(error); + } + return file; + }, + { + concurrency: os.availableParallelism(), + }, + ).duplex(); +}; diff --git a/generators/ktlint/internal/ktlint-worker.js b/generators/ktlint/internal/ktlint-worker.js new file mode 100644 index 000000000..e54e90ecd --- /dev/null +++ b/generators/ktlint/internal/ktlint-worker.js @@ -0,0 +1,19 @@ +import { execa } from 'execa'; + +export default async ({ ktlintExecutable, fileContents, cwd }) => { + try { + const { stdout } = await execa(ktlintExecutable, ['--log-level=none', '--format', '--stdin'], { + input: fileContents, + stdio: 'pipe', + shell: false, + stripFinalNewline: false, + cwd, + }); + return { result: stdout }; + } catch (error) { + if (!error.stdout || !error.stderr) { + return { error: `${error}` }; + } + return { result: error.stdout, info: error.stderr }; + } +}; diff --git a/generators/ktlint/resources/build.gradle b/generators/ktlint/resources/build.gradle new file mode 100644 index 000000000..fd4321c8b --- /dev/null +++ b/generators/ktlint/resources/build.gradle @@ -0,0 +1 @@ +// required by dependabot diff --git a/generators/ktlint/resources/gradle/libs.versions.toml b/generators/ktlint/resources/gradle/libs.versions.toml new file mode 100644 index 000000000..b37fa597e --- /dev/null +++ b/generators/ktlint/resources/gradle/libs.versions.toml @@ -0,0 +1,7 @@ +[libraries] +ktlint-cli = { module = 'com.pinterest.ktlint:ktlint-cli', version = '1.3.1' } + +ktlint-maven = { module = 'com.github.gantsign.maven:ktlint-maven-plugin', version = '3.2.0' } + +[plugins] +ktlint-gradle = { id = 'org.jlleitschuh.gradle.ktlint', version = '11.0.0' } diff --git a/generators/ktlint/templates/.gitignore.jhi.ktlint.ejs b/generators/ktlint/templates/.gitignore.jhi.ktlint.ejs new file mode 100644 index 000000000..870e80b17 --- /dev/null +++ b/generators/ktlint/templates/.gitignore.jhi.ktlint.ejs @@ -0,0 +1,2 @@ +# Ignore ktlint executable used by jhipster-kotlint:ktlint generator +.ktlint diff --git a/generators/spring-boot/command.js b/generators/spring-boot/command.js index 1d1db6423..33b182b29 100644 --- a/generators/spring-boot/command.js +++ b/generators/spring-boot/command.js @@ -6,15 +6,9 @@ import { command as springBootCommand } from 'generator-jhipster/generators/spri const command = { ...springBootCommand, configs: { - skipKtlintFormat: { - cli: { - desc: 'Skip ktlintFormat', - type: Boolean, - }, - scope: 'generator', - }, ...springBootCommand.configs, }, + import: ['jhipster-kotlin:ktlint'], }; export default command; diff --git a/generators/spring-boot/generator.js b/generators/spring-boot/generator.js index a5c9e1aa2..795445ea5 100644 --- a/generators/spring-boot/generator.js +++ b/generators/spring-boot/generator.js @@ -89,6 +89,7 @@ export default class extends BaseApplicationGenerator { // We want to use v7 liquibase templates and keep pom.xml unsorted for easier migration generatorOptions: { skipPriorities: ['writing', 'postWriting'], sortMavenPom: false }, }); + await this.dependsOnJHipster('jhipster-kotlin:ktlint'); } get [BaseApplicationGenerator.COMPOSING]() { diff --git a/generators/spring-boot/generator.spec.js b/generators/spring-boot/generator.spec.js index 118f6f972..48bec053b 100644 --- a/generators/spring-boot/generator.spec.js +++ b/generators/spring-boot/generator.spec.js @@ -13,7 +13,8 @@ describe('SubGenerator kotlin of kotlin JHipster blueprint', () => { blueprints: 'kotlin', }) .withJHipsterLookup() - .withParentBlueprintLookup(); + .withParentBlueprintLookup() + .withMockedGenerators(['jhipster-kotlin:ktlint']); }); it('should succeed', () => { diff --git a/generators/spring-boot/matrix.spec.js b/generators/spring-boot/matrix.spec.js index fd4f40c0d..ec4c96add 100644 --- a/generators/spring-boot/matrix.spec.js +++ b/generators/spring-boot/matrix.spec.js @@ -23,9 +23,11 @@ describe('Matrix test of SubGenerator kotlin of kotlin JHipster blueprint', () = .withOptions({ ignoreNeedlesError: true, blueprints: 'kotlin', + skipKtlintFormat: true, }) .withJHipsterLookup() - .withParentBlueprintLookup(); + .withParentBlueprintLookup() + .withMockedGenerators(['jhipster-kotlin:ktlint']); }); it('should succeed', () => { diff --git a/package-lock.json b/package-lock.json index cffb0b11b..99206e933 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,11 @@ "version": "1.16.0", "license": "Apache-2.0", "dependencies": { + "execa": "^9.3.0", "generator-jhipster": "8.6.0", - "jhipster-7-templates": "npm:generator-jhipster@7.9.4" + "jhipster-7-templates": "npm:generator-jhipster@7.9.4", + "mem-fs-editor": "^11.0.1", + "p-transform": "^4.1.5" }, "bin": { "khipster": "cli/cli.cjs" diff --git a/package.json b/package.json index c9e7d55ab..55cc22fc0 100644 --- a/package.json +++ b/package.json @@ -44,8 +44,11 @@ "vitest": "vitest" }, "dependencies": { + "execa": "^9.3.0", "generator-jhipster": "8.6.0", - "jhipster-7-templates": "npm:generator-jhipster@7.9.4" + "jhipster-7-templates": "npm:generator-jhipster@7.9.4", + "mem-fs-editor": "^11.0.1", + "p-transform": "^4.1.5" }, "devDependencies": { "ejs-lint": "2.0.0", diff --git a/test/app.spec.js b/test/app.spec.js index a9deb570a..016f4455d 100644 --- a/test/app.spec.js +++ b/test/app.spec.js @@ -81,7 +81,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -131,7 +131,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -175,7 +175,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -223,7 +223,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -268,7 +268,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -316,7 +316,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -361,7 +361,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -386,7 +386,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -430,7 +430,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -478,7 +478,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -526,7 +526,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -572,7 +572,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -618,7 +618,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -661,7 +661,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -705,7 +705,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -756,7 +756,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -799,7 +799,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -843,7 +843,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -901,7 +901,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -942,7 +942,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); it('creates expected files with "Hazelcast"', () => { @@ -986,7 +986,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); it('creates expected files with "Infinispan"', () => { @@ -1031,7 +1031,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); it('creates expected files with "Infinispan and Eureka"', () => { @@ -1077,7 +1077,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); it('creates expected files with "Memcached"', () => { @@ -1122,7 +1122,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); it('creates expected files with "Redis"', () => { @@ -1173,7 +1173,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1226,7 +1226,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1279,7 +1279,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1330,7 +1330,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1373,7 +1373,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1421,7 +1421,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1463,7 +1463,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1512,7 +1512,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1556,7 +1556,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1616,7 +1616,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1662,7 +1662,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1710,7 +1710,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1755,7 +1755,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1799,7 +1799,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1845,7 +1845,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1894,7 +1894,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1944,7 +1944,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -1989,7 +1989,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -2033,7 +2033,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -2081,7 +2081,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); @@ -2124,7 +2124,7 @@ describe('JHipster generator for App generator', () => { }) .withJHipsterLookup() .withParentBlueprintLookup() - .withMockedGenerators(['jhipster:languages']) + .withMockedGenerators(['jhipster-kotlin:ktlint', 'jhipster:languages']) .run(); }); From 2cd4f52b132197f6a7576840c81d24ad5e4cf91e Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 24 Jul 2024 15:21:15 -0300 Subject: [PATCH 5/7] add ktlint dependencies in ktlint generator --- .../__snapshots__/generator.spec.js.snap | 62 ++++++++++++++++++- generators/ktlint/generator.js | 40 ++++++++++++ generators/ktlint/generator.spec.js | 37 ++++++----- generators/spring-boot/generator.js | 27 -------- generators/spring-boot/kotlin-constants.js | 4 -- 5 files changed, 123 insertions(+), 47 deletions(-) diff --git a/generators/ktlint/__snapshots__/generator.spec.js.snap b/generators/ktlint/__snapshots__/generator.spec.js.snap index d307f9513..417427b44 100644 --- a/generators/ktlint/__snapshots__/generator.spec.js.snap +++ b/generators/ktlint/__snapshots__/generator.spec.js.snap @@ -1,6 +1,66 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`SubGenerator kotlin of kotlin JHipster blueprint > run > should succeed 1`] = ` +exports[`SubGenerator kotlin of kotlin JHipster blueprint > gradle > should match source calls 1`] = ` +{ + "addGradlePluginToBuildScript": [ + { + "group": "org.jlleitschuh.gradle", + "name": "ktlint-gradle", + "version": "'KTLINT-GRADLE-VERSION'", + }, + ], +} +`; + +exports[`SubGenerator kotlin of kotlin JHipster blueprint > gradle > should succeed 1`] = ` +{ + ".yo-rc.json": { + "stateCleared": "modified", + }, + "package.json": { + "stateCleared": "modified", + }, +} +`; + +exports[`SubGenerator kotlin of kotlin JHipster blueprint > maven > should match source calls 1`] = ` +{ + "addJavaDefinition": [ + { + "versions": [ + { + "name": "ktlint-maven-plugin", + "version": "'KTLINT-MAVEN-VERSION'", + }, + ], + }, + ], + "addMavenDefinition": [ + { + "plugins": [ + { + "additionalContent": " + + check + + check + + + false + + + ", + "artifactId": "ktlint-maven-plugin", + "groupId": "com.github.gantsign.maven", + "version": "\${ktlint-maven-plugin.version}", + }, + ], + }, + ], +} +`; + +exports[`SubGenerator kotlin of kotlin JHipster blueprint > maven > should succeed 1`] = ` { ".yo-rc.json": { "stateCleared": "modified", diff --git a/generators/ktlint/generator.js b/generators/ktlint/generator.js index 09e6330fb..7ad751cae 100644 --- a/generators/ktlint/generator.js +++ b/generators/ktlint/generator.js @@ -102,6 +102,46 @@ export default class extends BaseApplicationGenerator { }, }); }, + addDependencies({ application, source }) { + if (application.buildToolGradle) { + source.addGradlePluginToBuildScript({ + group: 'org.jlleitschuh.gradle', + name: 'ktlint-gradle', + version: application.javaDependencies['ktlint-gradle'], + }); + + /* JHipster 8 based configuration + source.addGradleDependencyCatalogPlugins([{ pluginName: 'ktlint', id: 'org.jlleitschuh.gradle.ktlint', version: KTLINT_GRADLE_VERSION, addToBuild: true }]); + */ + } else { + source.addJavaDefinition({ + versions: [{ name: 'ktlint-maven-plugin', version: application.javaDependencies['ktlint-maven'] }], + }); + + const ktlintMavenOther = ` + + check + + check + + + false + + + `; + + source.addMavenDefinition({ + plugins: [ + { + groupId: 'com.github.gantsign.maven', + artifactId: 'ktlint-maven-plugin', + version: '${ktlint-maven-plugin.version}', + additionalContent: ktlintMavenOther, + }, + ], + }); + } + }, }); } } diff --git a/generators/ktlint/generator.spec.js b/generators/ktlint/generator.spec.js index 9319b3b36..15d9f9893 100644 --- a/generators/ktlint/generator.spec.js +++ b/generators/ktlint/generator.spec.js @@ -1,26 +1,33 @@ import { beforeAll, describe, expect, it } from 'vitest'; -import { defaultHelpers as helpers, result } from 'generator-jhipster/testing'; +import { fromMatrix, defaultHelpers as helpers, result } from 'generator-jhipster/testing'; const SUB_GENERATOR = 'ktlint'; const SUB_GENERATOR_NAMESPACE = `jhipster-kotlin:${SUB_GENERATOR}`; describe('SubGenerator kotlin of kotlin JHipster blueprint', () => { - describe('run', () => { - beforeAll(async function () { - await helpers - .run(SUB_GENERATOR_NAMESPACE) - .withJHipsterConfig() - .withOptions({ - ignoreNeedlesError: true, - skipKtlintFormat: true, - }) - .withJHipsterLookup() - .withParentBlueprintLookup(['generators', 'generators/*/generators']); - }); + Object.entries(fromMatrix({ buildTool: ['maven', 'gradle'] })).forEach(([name, config]) => { + describe(name, () => { + beforeAll(async function () { + await helpers + .run(SUB_GENERATOR_NAMESPACE) + .withJHipsterConfig(config) + .withOptions({ + ignoreNeedlesError: true, + skipKtlintFormat: true, + }) + .withJHipsterLookup() + .withMockedSource() + .withParentBlueprintLookup(['generators', 'generators/*/generators']); + }); + + it('should succeed', () => { + expect(result.getStateSnapshot()).toMatchSnapshot(); + }); - it('should succeed', () => { - expect(result.getStateSnapshot()).toMatchSnapshot(); + it('should match source calls', () => { + expect(result.sourceCallsArg).toMatchSnapshot(); + }); }); }); }); diff --git a/generators/spring-boot/generator.js b/generators/spring-boot/generator.js index 795445ea5..fb3555200 100644 --- a/generators/spring-boot/generator.js +++ b/generators/spring-boot/generator.js @@ -15,8 +15,6 @@ import { DETEKT_CONFIG_FILE, DETEKT_VERSION, KOTLIN_VERSION, - KTLINT_GRADLE_VERSION, - KTLINT_MAVEN_VERSION, MAPSTRUCT_VERSION, MAVEN_ANTRUN_VERSION, MOCKITO_KOTLIN_VERSION, @@ -470,11 +468,6 @@ export default class extends BaseApplicationGenerator { version: '${kotlin_version}', }); } - source.addGradlePluginToBuildScript({ - group: 'org.jlleitschuh.gradle', - name: 'ktlint-gradle', - version: KTLINT_GRADLE_VERSION, - }); source.addGradlePluginToBuildScript({ group: 'io.gitlab.arturbosch.detekt', name: 'detekt-gradle-plugin', @@ -493,7 +486,6 @@ export default class extends BaseApplicationGenerator { source.addGradleDependencyCatalogPlugins([ { pluginName: 'kotlin-jvm', id: 'org.jetbrains.kotlin.jvm', 'version.ref': 'kotlin', addToBuild: true }, { pluginName: 'detekt', id: 'io.gitlab.arturbosch.detekt', version: DETEKT_VERSION, addToBuild: true }, - { pluginName: 'ktlint', id: 'org.jlleitschuh.gradle.ktlint', version: KTLINT_GRADLE_VERSION, addToBuild: true }, { pluginName: 'kotlin-allopen', id: 'org.jetbrains.kotlin.plugin.allopen', @@ -530,7 +522,6 @@ export default class extends BaseApplicationGenerator { versions: [ { name: 'kotlin', version: KOTLIN_VERSION }, { name: 'mapstruct', version: MAPSTRUCT_VERSION }, - { name: 'ktlint-maven-plugin', version: KTLINT_MAVEN_VERSION }, { name: 'maven-antrun-plugin', version: MAVEN_ANTRUN_VERSION }, { name: 'detekt', version: DETEKT_VERSION }, { name: 'modernizer-maven-plugin', version: '2.6.0' }, @@ -697,18 +688,6 @@ export default class extends BaseApplicationGenerator { none `; - const ktlintMavenOther = ` - - check - - check - - - false - - - `; - const antRunOther = ` @@ -770,12 +749,6 @@ export default class extends BaseApplicationGenerator { version: '${maven-compiler-plugin.version}', additionalContent: defaultCompileOther, }, - { - groupId: 'com.github.gantsign.maven', - artifactId: 'ktlint-maven-plugin', - version: '${ktlint-maven-plugin.version}', - additionalContent: ktlintMavenOther, - }, { groupId: 'org.apache.maven.plugins', artifactId: 'maven-antrun-plugin', diff --git a/generators/spring-boot/kotlin-constants.js b/generators/spring-boot/kotlin-constants.js index c5c1c2ae8..0684c35e8 100644 --- a/generators/spring-boot/kotlin-constants.js +++ b/generators/spring-boot/kotlin-constants.js @@ -21,8 +21,6 @@ import { JAVA_SERVER_TEST_RESOURCES_DIR, JAVA_MAIN_RESOURCES_DIR } from 'generat export const DETEKT_VERSION = '1.21.0'; export const KOTLIN_VERSION = '1.6.21'; -export const KTLINT_MAVEN_VERSION = '3.2.0'; -export const KTLINT_GRADLE_VERSION = '11.0.0'; export const MAPSTRUCT_VERSION = '1.5.3.Final'; export const MAVEN_ANTRUN_VERSION = '3.0.0'; export const MOCKITO_KOTLIN_VERSION = '4.0.0'; @@ -41,8 +39,6 @@ export const KOTLIN_MAIN_RES_DIR = JAVA_MAIN_RESOURCES_DIR; export const constants = { KOTLIN_VERSION, MOCKITO_KOTLIN_VERSION, - KTLINT_MAVEN_VERSION, - KTLINT_GRADLE_VERSION, DETEKT_VERSION, MAVEN_ANTRUN_VERSION, DETEKT_CONFIG_FILE, From 9b5a9f8ea0ddd0d4d0cf3bd5e3d9bfa020759a8e Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 24 Jul 2024 15:25:22 -0300 Subject: [PATCH 6/7] Revert "enable ktlint formartting" This reverts commit 55336d28a4f8860c6d8381f750760b27bf3e6d6c. --- .github/workflows/angular.yml | 4 ++-- .github/workflows/react.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/angular.yml b/.github/workflows/angular.yml index b7fa29277..bd65e820f 100644 --- a/.github/workflows/angular.yml +++ b/.github/workflows/angular.yml @@ -110,7 +110,7 @@ jobs: #---------------------------------------------------------------------- # Install JHipster and generate project+entities #---------------------------------------------------------------------- - - run: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }} ${{ matrix.new-extra-args }} + - run: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }} ${{ matrix.new-extra-args }} - run: cli.cjs info #---------------------------------------------------------------------- # Detect changes against base commit @@ -122,7 +122,7 @@ jobs: !contains(github.event.pull_request.labels.*.name, 'pr: disable-compare') with: generator-path: jhipster-kotlin - cmd: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }} + cmd: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }} #---------------------------------------------------------------------- # Launch tests #---------------------------------------------------------------------- diff --git a/.github/workflows/react.yml b/.github/workflows/react.yml index c1e080682..1e71a30ff 100644 --- a/.github/workflows/react.yml +++ b/.github/workflows/react.yml @@ -110,7 +110,7 @@ jobs: #---------------------------------------------------------------------- # Install JHipster and generate project+entities #---------------------------------------------------------------------- - - run: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }} ${{ matrix.new-extra-args }} + - run: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }} ${{ matrix.new-extra-args }} - run: cli.cjs info #---------------------------------------------------------------------- # Detect changes against base commit @@ -122,7 +122,7 @@ jobs: !contains(github.event.pull_request.labels.*.name, 'pr: disable-compare') with: generator-path: jhipster-kotlin - cmd: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }} + cmd: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }} #---------------------------------------------------------------------- # Launch tests #---------------------------------------------------------------------- From 29b0cf4cc4ea61dff5104089231e929d108ad00e Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 24 Jul 2024 15:25:22 -0300 Subject: [PATCH 7/7] add migration generator --- .prettierrc.yml | 5 +-- .yo-rc.json | 9 ++++- .../__snapshots__/generator.spec.js.snap | 9 +++++ generators/migration/generator.js | 39 +++++++++++++++++++ generators/migration/generator.spec.js | 25 ++++++++++++ generators/migration/index.js | 1 + generators/spring-boot/generator.js | 20 +--------- 7 files changed, 84 insertions(+), 24 deletions(-) create mode 100644 generators/migration/__snapshots__/generator.spec.js.snap create mode 100644 generators/migration/generator.js create mode 100644 generators/migration/generator.spec.js create mode 100644 generators/migration/index.js diff --git a/.prettierrc.yml b/.prettierrc.yml index 57a16d1ed..f87bfcbf2 100644 --- a/.prettierrc.yml +++ b/.prettierrc.yml @@ -1,9 +1,6 @@ -# Prettier configuration - printWidth: 140 singleQuote: true tabWidth: 4 useTabs: false - -# js and ts rules: arrowParens: avoid +bracketSameLine: false diff --git a/.yo-rc.json b/.yo-rc.json index f56cf5232..1493e3f79 100644 --- a/.yo-rc.json +++ b/.yo-rc.json @@ -1,6 +1,6 @@ { "generator-jhipster": { - "additionalSubGenerators": "ktlint", + "additionalSubGenerators": "ktlint,migration", "baseName": "kotlin", "cli": true, "cliName": "khipster", @@ -12,6 +12,12 @@ "sbs": null, "written": true }, + "migration": { + "command": false, + "priorities": ["postWriting"], + "sbs": null, + "written": true + }, "spring-boot": { "command": false, "priorities": ["initializing", "composing"], @@ -22,6 +28,7 @@ "jhipsterVersion": "8.5.0", "localBlueprint": false, "packageJsonType": "module", + "prettierTabWidth": 4, "sampleWritten": true, "subGenerators": ["spring-boot"] } diff --git a/generators/migration/__snapshots__/generator.spec.js.snap b/generators/migration/__snapshots__/generator.spec.js.snap new file mode 100644 index 000000000..7c2aa9afa --- /dev/null +++ b/generators/migration/__snapshots__/generator.spec.js.snap @@ -0,0 +1,9 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`SubGenerator migration of kotlin JHipster blueprint > run > should succeed 1`] = ` +{ + ".yo-rc.json": { + "stateCleared": "modified", + }, +} +`; diff --git a/generators/migration/generator.js b/generators/migration/generator.js new file mode 100644 index 000000000..9dcae9ecf --- /dev/null +++ b/generators/migration/generator.js @@ -0,0 +1,39 @@ +import BaseApplicationGenerator from 'generator-jhipster/generators/base-application'; +import { createNeedleCallback } from 'generator-jhipster/generators/base/support'; + +export default class extends BaseApplicationGenerator { + get [BaseApplicationGenerator.PREPARING]() { + return this.asPreparingTaskGroup({ + async source({ application, source }) { + if (application.buildToolGradle) { + // Add a noop needles for spring-gateway generator + source.addJavaDefinition = () => {}; + source.addJavaDependencies = () => {}; + + // JHipster 7 does not support buildScript add for migration + source.addGradlePluginToBuildScript = ({ group, name, version }) => { + this.editFile( + 'build.gradle', + createNeedleCallback({ + needle: 'gradle-buildscript-dependency', + contentToAdd: `classpath "${group}:${name}:${version}"`, + }), + ); + }; + } + }, + }); + } + + get [BaseApplicationGenerator.POST_WRITING]() { + return this.asPostWritingTaskGroup({ + async postWritingTemplateTask({ application }) { + if (application.buildToolGradle) { + // JHipster 8 have needles fixed + this.editFile('build.gradle', contents => contents.replaceAll('//jhipster', '// jhipster')); + this.editFile('settings.gradle', contents => contents.replaceAll('//jhipster', '// jhipster')); + } + }, + }); + } +} diff --git a/generators/migration/generator.spec.js b/generators/migration/generator.spec.js new file mode 100644 index 000000000..23f8c5903 --- /dev/null +++ b/generators/migration/generator.spec.js @@ -0,0 +1,25 @@ +import { beforeAll, describe, expect, it } from 'vitest'; + +import { defaultHelpers as helpers, result } from 'generator-jhipster/testing'; + +const SUB_GENERATOR = 'migration'; +const SUB_GENERATOR_NAMESPACE = `jhipster-kotlin:${SUB_GENERATOR}`; + +describe('SubGenerator migration of kotlin JHipster blueprint', () => { + describe('run', () => { + beforeAll(async function () { + await helpers + .run(SUB_GENERATOR_NAMESPACE) + .withJHipsterConfig() + .withOptions({ + ignoreNeedlesError: true, + }) + .withJHipsterLookup() + .withParentBlueprintLookup(); + }); + + it('should succeed', () => { + expect(result.getStateSnapshot()).toMatchSnapshot(); + }); + }); +}); diff --git a/generators/migration/index.js b/generators/migration/index.js new file mode 100644 index 000000000..01e9dc34d --- /dev/null +++ b/generators/migration/index.js @@ -0,0 +1 @@ +export { default } from './generator.js'; diff --git a/generators/spring-boot/generator.js b/generators/spring-boot/generator.js index fb3555200..3a14f154c 100644 --- a/generators/spring-boot/generator.js +++ b/generators/spring-boot/generator.js @@ -2,7 +2,6 @@ import { dirname, join } from 'path'; import { fileURLToPath } from 'url'; import { transform, passthrough } from '@yeoman/transform'; import BaseApplicationGenerator from 'generator-jhipster/generators/spring-boot'; -import { createNeedleCallback } from 'generator-jhipster/generators/base/support'; import { prepareSqlApplicationProperties } from 'generator-jhipster/generators/spring-data-relational/support'; import { files as entityServerFiles } from 'jhipster-7-templates/esm/generators/entity-server'; import { getEnumInfo } from 'generator-jhipster/generators/base-application/support'; @@ -87,6 +86,7 @@ export default class extends BaseApplicationGenerator { // We want to use v7 liquibase templates and keep pom.xml unsorted for easier migration generatorOptions: { skipPriorities: ['writing', 'postWriting'], sortMavenPom: false }, }); + await this.dependsOnJHipster('jhipster-kotlin:migration'); await this.dependsOnJHipster('jhipster-kotlin:ktlint'); } @@ -425,14 +425,6 @@ export default class extends BaseApplicationGenerator { }, async customizeGradle({ application, source }) { if (application.buildToolGradle) { - // Add a noop needles for spring-gateway generator - source.addJavaDefinition = () => {}; - source.addJavaDependencies = () => {}; - - // JHipster 8 have needles fixed - this.editFile('build.gradle', contents => contents.replaceAll('//jhipster', '// jhipster')); - this.editFile('settings.gradle', contents => contents.replaceAll('//jhipster', '// jhipster')); - source.applyFromGradle({ script: 'gradle/kotlin.gradle', }); @@ -441,16 +433,6 @@ export default class extends BaseApplicationGenerator { source.addGradleProperty({ property: 'mapstruct_version', value: MAPSTRUCT_VERSION }); source.addGradleProperty({ property: 'detekt_version', value: DETEKT_VERSION }); - // JHipster 7 does not support buildScript add for migration - source.addGradlePluginToBuildScript = ({ group, name, version }) => { - this.editFile( - 'build.gradle', - createNeedleCallback({ - needle: 'gradle-buildscript-dependency', - contentToAdd: `classpath "${group}:${name}:${version}"`, - }), - ); - }; source.addGradlePluginToBuildScript({ group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin',