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

generate-samples adjusts #470

Merged
merged 6 commits into from
Feb 19, 2025
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
15 changes: 6 additions & 9 deletions .blueprint/generate-sample/command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { existsSync, readdirSync } from 'node:fs';
import { readdirSync } from 'node:fs';
import { entitiesByType, workflowSamples } from '../generate-sample/support/index.mjs';
import { getSamples } from './get-samples.mjs';

/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/
const command = {
arguments: {
sampleName: {
type: String,
},
},
configs: {
sampleName: {
argument: {
type: String,
},
prompt: gen => ({
when: !gen.jdlSamples && !gen.appSample && !gen.all && existsSync(gen.templatePath(gen.samplesFolder)),
when: !gen.jdlSamples && !gen.appSample && !gen.all,
type: 'list',
message: 'which sample do you want to generate?',
choices: async () => getSamples(gen.templatePath(gen.samplesFolder)),
}),
choices: Object.keys(workflowSamples),
configure: gen => {
const sample = workflowSamples[gen.sampleName];
if (!sample) {
Expand Down
11 changes: 0 additions & 11 deletions .blueprint/generate-sample/get-samples.mjs

This file was deleted.

7 changes: 1 addition & 6 deletions .github/workflows/angular.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,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 }}
env:
JHI_APP: ${{ matrix.app-sample || 'jdl' }}
JHI_ENTITY: ${{ matrix.entity || 'none' }}
JHI_JDL_ENTITY: ${{ matrix.jdl-entity || '' }}
JHI_JDL_APP: ${{ matrix.jdl-samples || '' }}
cmd: cli.cjs generate-sample ${{ matrix.sample }} --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }}
#----------------------------------------------------------------------
# Launch tests
#----------------------------------------------------------------------
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,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 }}
env:
JHI_APP: ${{ matrix.app-sample || 'jdl' }}
JHI_ENTITY: ${{ matrix.entity || 'none' }}
JHI_JDL_ENTITY: ${{ matrix.jdl-entity || '' }}
JHI_JDL_APP: ${{ matrix.jdl-samples || '' }}
cmd: cli.cjs generate-sample ${{ matrix.sample }} --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }}
#----------------------------------------------------------------------
# Launch tests
#----------------------------------------------------------------------
Expand Down
14 changes: 1 addition & 13 deletions generators/kotlin/generator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BaseApplicationGenerator from 'generator-jhipster/generators/base-application';
import { passthrough, transform } from '@yeoman/transform';
import { passthrough } from '@yeoman/transform';
import { getPrimaryKeyValue } from 'generator-jhipster/generators/server/support';
import { SERVER_MAIN_SRC_KOTLIN_DIR, SERVER_TEST_SRC_KOTLIN_DIR } from './support/index.js';

Expand Down Expand Up @@ -28,18 +28,6 @@ export default class extends BaseApplicationGenerator {

get [BaseApplicationGenerator.DEFAULT]() {
return this.asDefaultTaskGroup({
async checkForJavaFiles() {
this.queueTransformStream(
{
name: 'removing remaining java files',
filter: file => file.path.endsWith('.java'),
refresh: true,
},
transform(file => {
this.log.warn(`Remaining java file ${file.path} removed`);
}),
);
},
async convertGradleScripts({ application }) {
if (application.buildToolGradle) {
this.queueTransformStream(
Expand Down
8 changes: 6 additions & 2 deletions generators/kotlin/support/files.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
export const convertToKotlinFile = file =>
file.replace('.java', '.kt').replace('src/main/java/', 'src/main/kotlin/').replace('src/test/java/', 'src/test/kotlin/');
export const convertToKotlinFile = (file, replaceExtension = true) => {
if (replaceExtension) {
file = file.replace('.java', '.kt');
}
return file.replace('src/main/java/', 'src/main/kotlin/').replace('src/test/java/', 'src/test/kotlin/');
};
3 changes: 3 additions & 0 deletions generators/spring-boot-v2/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ export default class extends BaseApplicationGenerator {
if (application.user && destinationFile.endsWith('UserCallback.java')) {
return undefined;
}
if (application.generateBuiltInAuthorityEntity && destinationFile.endsWith('AuthorityRepository.java')) {
return undefined;
}

if (
sourceFile.endsWith('/TestContainersSpringContextCustomizerFactory.java') &&
Expand Down

This file was deleted.

46 changes: 30 additions & 16 deletions generators/spring-boot/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,48 @@ export default class extends BaseApplicationGenerator {
// We don't want to handle spring-boot-v2 templates here
if (file.namespace === 'jhipster-kotlin:spring-boot-v2') return file;
const { resolvedSourceFile: javaResolvedSourceFile, namespace: ns } = file;
let { sourceFile, destinationFile } = file;
const { sourceFile, destinationFile } = file;
// Already resolved kotlin files
if (javaResolvedSourceFile && (javaResolvedSourceFile.endsWith('.kt') || javaResolvedSourceFile.includes('.kt.'))) {
return file;
}

if (sourceFile.includes('.java')) {
// Kotlint User template does not implements Persistable api. Ignore for now.
if (application.user && destinationFile.endsWith('UserCallback.java')) {
return undefined;
}

sourceFile = convertToKotlinFile(sourceFile);
destinationFile = convertToKotlinFile(destinationFile);
// Kotlint User template does not implements Persistable api. Ignore for now.
if (application.user && destinationFile.endsWith('UserCallback.java')) {
return undefined;
}

const prefix = ns === 'jhipster:spring-boot' ? '' : ns.split(':').pop();
sourceFile = join(prefix, sourceFile);
let resolvedSourceFile = this.templatePath(sourceFile);
if (!existsSync(`${resolvedSourceFile}.ejs`)) {
if (resolvedSourceFile.includes('.kt')) {
// Ignore v8 file if it does not exist
const kotlinSourceFile = join(prefix, convertToKotlinFile(sourceFile));
const resolvedSourceFile = this.templatePath(kotlinSourceFile);

if (!sourceFile.includes('.java')) {
return existsSync(`${resolvedSourceFile}.ejs`) ? { ...file, resolvedSourceFile } : file;
}

if (existsSync(`${resolvedSourceFile}.ejs`)) {
return {
...file,
sourceFile: kotlinSourceFile,
resolvedSourceFile,
javaResolvedSourceFile,
destinationFile: convertToKotlinFile(destinationFile),
};
}

if (resolvedSourceFile.includes('.kt')) {
if (resolvedSourceFile.includes('src/test/')) {
// Ignore test files that are not converted to kotlin
return undefined;
}
resolvedSourceFile = javaResolvedSourceFile;
}

return { ...file, sourceFile, javaResolvedSourceFile, resolvedSourceFile, destinationFile };
return {
...file,
javaResolvedSourceFile,
resolvedSourceFile: javaResolvedSourceFile,
destinationFile: convertToKotlinFile(destinationFile, false),
};
},
);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%#
Copyright 2013-2024 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.
-%>
package <%= entityAbsolutePackage %>.repository

import <%= entityAbsolutePackage %>.domain.<%= persistClass %>

import org.springframework.data.r2dbc.repository.R2dbcRepository
import org.springframework.stereotype.Repository
<%_ if (primaryKey.typeUUID) { _%>

import java.util.UUID
<%_ } _%>

/**
* <%= springDataDescription %> repository for the [<%= persistClass %>] entity.
*/
@Repository
interface <%= entityClass %>Repository : R2dbcRepository<<%= persistClass %>, <%= primaryKey.type %>>
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ import org.elasticsearch.index.query.QueryBuilders.queryStringQuery
@Service<% if (databaseTypeSql) { %>
@Transactional<% } %>
class <%= serviceClassName %>(
<%- include('../../_partials_entity_/inject_template', {asEntity, asDto, viaService: false, constructorName: serviceClassName, queryService: false, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: false, noReturn: false}); -%>
<%- include('../../_partials_entity_/inject_template', {viaService: false, constructorName: serviceClassName, queryService: false, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: false, noReturn: false}); -%>
)<% if (serviceImpl) { %> : <%= entityClass %>Service<% } %> {

private val log = LoggerFactory.getLogger(javaClass)
Expand All @@ -101,7 +101,7 @@ class <%= serviceClassName %>(
<%_ } _%>
<% if (serviceImpl) { _%>override <% } %>fun save(<%= instanceName %>: <%= instanceType %>): <% if (reactive) { %>Mono<<% } %><%= instanceType %><% if (reactive) { %>><% } %> {
log.debug("Request to save <%= entityClass %> : $<%= instanceName %>")
<%- include('/_global_partials_entity_/save_template', {asEntity, asDto, viaService: false, returnDirectly: true, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: false, isPersisted: false, noReturn: false}); -%>
<%- include('/_global_partials_entity_/save_template', {viaService: false, returnDirectly: true, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: false, isPersisted: false, noReturn: false}); -%>
}

<%_ if (!serviceImpl) { _%>
Expand All @@ -127,7 +127,7 @@ class <%= serviceClassName %>(
<%_ } _%>
<% if (serviceImpl) { %>override <% } %>fun partialUpdate(<%= instanceName %>: <%= instanceType %>): <% if (reactive) { %>Mono<<% } else { %>Optional<<% } %><%= instanceType %>> {
log.debug("Request to partially update <%= entityClass %> : {}", <%= instanceName %>)
<%- include('../../_partials_entity_/patch_template', {asEntity, asDto, isService: true, viaService: false}); -%>
<%- include('../../_partials_entity_/patch_template', {isService: true, viaService: false}); -%>
}

<%_ if (!serviceImpl) { _%>
Expand Down Expand Up @@ -165,7 +165,7 @@ class <%= serviceClassName %>(
<%= entityInstance %>Repository.findAllWithEagerRelationships(pageable)<% if (!dtoMapstruct) { %><% } else { %>.map(<%= entityToDtoReference %>)<% } %>

<%_ } _%>
<%- include('../../_partials_entity_/get_filtered_template', {asEntity, asDto}); -%>
<%- include('../../_partials_entity_/get_filtered_template'); -%>
<%_ if (reactive) { _%>
<%_ if (!serviceImpl) { _%>
/**
Expand Down Expand Up @@ -198,7 +198,7 @@ class <%= serviceClassName %>(
@Transactional(readOnly = true)
<%_ } _%>
<% if (serviceImpl) { %>override <% } %>fun findOne(id: <%= primaryKey.type %>): <%= optionalOrMono %><<%= instanceType %>> {
log.debug("Request to get <%= entityClass %> : $id")<%- include('../../_partials_entity_/get_template', {asEntity, asDto, viaService: false, returnDirectly:true, implementsEagerLoadApis}); -%>
log.debug("Request to get <%= entityClass %> : $id")<%- include('../../_partials_entity_/get_template', {viaService: false, returnDirectly:true, implementsEagerLoadApis}); -%>
}

<%_ if (!serviceImpl) { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ _%><%- include('../../_partials_entity_/inject_template', {viaService: viaServic
<%= instanceName %>.<%= field.fieldName %> = UUID.randomUUID()
<%_ } _%>
<%_ } _%>
<%- include('/_global_partials_entity_/save_template', {asEntity, asDto, viaService: viaService, returnDirectly: false, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: true, noReturn: false}); -%>
<%- include('/_global_partials_entity_/save_template', {viaService: viaService, returnDirectly: false, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: true, noReturn: false}); -%>
<%_ if (reactive) { _%>
.map { result ->
try {
Expand Down Expand Up @@ -325,7 +325,7 @@ _%><%- include('../../_partials_entity_/inject_template', {viaService: viaServic
<%_ } _%>
<% } %>
<%_ } _%>
<%- include('../../_partials_entity_/patch_template', {asEntity, asDto, isService: false, viaService: viaService}); -%>
<%- include('../../_partials_entity_/patch_template', {isService: false, viaService: viaService}); -%>
<%_ if (reactive) { _%>
result
.switchIfEmpty(Mono.error(ResponseStatusException(HttpStatus.NOT_FOUND)))
Expand Down Expand Up @@ -360,7 +360,7 @@ _%><%- include('../../_partials_entity_/inject_template', {viaService: viaServic
*/
@GetMapping("/<%= entityApiUrl %>")<%_ if (databaseTypeSql && isUsingMapsId&& !viaService) { %>
@Transactional(readOnly = true)<%_ } _%>
<%- include('../../_partials_entity_/get_all_template', {asEntity, asDto, viaService}); -%>
<%- include('../../_partials_entity_/get_all_template', {viaService}); -%>

<%_ if (reactive && paginationNo) { _%>
/**
Expand Down Expand Up @@ -392,7 +392,7 @@ _%><%- include('../../_partials_entity_/inject_template', {viaService: viaServic
@Transactional(readOnly = true)
<%_ } _%>
fun get<%= entityClass %>(@PathVariable id: <%= primaryKey.type %>): <% if (reactive) { %>Mono<<% } %>ResponseEntity<<%= instanceType %>><% if (reactive) { %>><% } %> {
log.debug("REST request to get <%= entityClass %> : $id")<%- include('../../_partials_entity_/get_template', {asEntity, asDto, viaService, returnDirectly:false, implementsEagerLoadApis}); -%>
log.debug("REST request to get <%= entityClass %> : $id")<%- include('../../_partials_entity_/get_template', {viaService, returnDirectly:false, implementsEagerLoadApis}); -%>
return ResponseUtil.wrapOrNotFound(<%= instanceName %>)
}
<%_ if (!readOnly) { _%>
Expand Down Expand Up @@ -437,6 +437,6 @@ _%><%- include('../../_partials_entity_/inject_template', {viaService: viaServic
<%_ } _%>
* @return the result of the search.
*/
@GetMapping("/_search/<%= entityApiUrl %>")<%- include('../../_partials_entity_/search_template', {asEntity, asDto, viaService}); -%>
@GetMapping("/_search/<%= entityApiUrl %>")<%- include('../../_partials_entity_/search_template', {viaService}); -%>
<%_ } _%>
}
Loading
Loading