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 #412

Merged
merged 12 commits into from
Jul 30, 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: 2 additions & 0 deletions generators/kotlin/support/files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const convertToKotlinFile = file =>
file.replace('.java', '.kt').replace('src/main/java/', 'src/main/kotlin/').replace('src/test/java/', 'src/test/kotlin/');
1 change: 1 addition & 0 deletions generators/kotlin/support/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './constants.js';
export * from './files.js';
54 changes: 0 additions & 54 deletions generators/spring-boot/__snapshots__/matrix.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3150,9 +3150,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > gatew
"src/main/resources/config/cql/drop-keyspace.cql": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -3689,9 +3686,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > gatew
"src/main/resources/config/couchmove/changelog/V20220129002000__entitywithcustomid.n1ql": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -4270,9 +4264,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > gatew
"src/main/resources/config/bootstrap.yml": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -4812,9 +4803,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > gatew
"src/main/resources/config/bootstrap.yml": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/neo4j/migrations/user__admin.json": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -5363,12 +5351,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > gatew
"src/main/resources/config/liquibase/data/authority.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user_authority.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/fake-data/another_simple.csv": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -21580,9 +21562,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol
"src/main/resources/config/cql/drop-keyspace.cql": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -22140,9 +22119,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol
"src/main/resources/config/cql/drop-keyspace.cql": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -22712,9 +22688,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol
"src/main/resources/config/couchmove/changelog/V20220129002000__entitywithcustomid.n1ql": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -23272,9 +23245,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol
"src/main/resources/config/couchmove/changelog/V20220129002000__entitywithcustomid.n1ql": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -23841,9 +23811,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol
"src/main/resources/config/bootstrap.yml": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -24338,9 +24305,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol
"src/main/resources/config/application.yml": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/tls/keystore.p12": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -24886,9 +24850,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol
"src/main/resources/config/bootstrap.yml": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/neo4j/migrations/user__admin.json": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -25392,9 +25353,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol
"src/main/resources/config/application.yml": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/neo4j/migrations/user__admin.json": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -25940,12 +25898,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol
"src/main/resources/config/liquibase/data/authority.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user_authority.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/fake-data/another_simple.csv": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -26551,12 +26503,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol
"src/main/resources/config/liquibase/data/authority.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/data/user_authority.csv": {
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/fake-data/another_simple.csv": {
"stateCleared": "modified",
},
Expand Down
141 changes: 71 additions & 70 deletions generators/spring-boot/generator.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { dirname, join } from 'path';
import { basename, dirname, join } from 'path';
import { fileURLToPath } from 'url';
import BaseApplicationGenerator from 'generator-jhipster/generators/spring-boot';
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';
import { files as serverFiles } from 'jhipster-7-templates/esm/generators/server';

import { convertToKotlinFile } from '../kotlin/support/files.js';
import migration from './migration.cjs';
import { serverFiles as sqlFiles } from './files-sql.js';
import { entityCouchbaseFiles } from './entity-files-couchbase.js';
Expand All @@ -25,8 +26,6 @@ const {
DOCKER_ELASTICSEARCH_CONTAINER,
ELASTICSEARCH_VERSION,
MAIN_DIR,
SERVER_MAIN_SRC_DIR,
SERVER_TEST_SRC_DIR,
TEST_DIR,
} = jhipsterConstants;

Expand All @@ -37,12 +36,6 @@ const jhipster7TemplatesPackage = dirname(fileURLToPath(import.meta.resolve('jhi
const SERVER_MAIN_SRC_KOTLIN_DIR = `${MAIN_DIR}kotlin/`;
const SERVER_TEST_SRC_KOTLIN_DIR = `${TEST_DIR}kotlin/`;

const convertToKotlinFile = file =>
file
.replace('.java', '.kt')
.replace(SERVER_MAIN_SRC_DIR, SERVER_MAIN_SRC_KOTLIN_DIR)
.replace(SERVER_TEST_SRC_DIR, SERVER_TEST_SRC_KOTLIN_DIR);

const JAVA_VERSION = '11';

export default class extends BaseApplicationGenerator {
Expand Down Expand Up @@ -104,10 +97,41 @@ export default class extends BaseApplicationGenerator {
syncUserWithIdp: application.authenticationType === 'oauth2',
});

application.customizeTemplatePaths.push(file => {
const { resolvedSourceFile, sourceFile, destinationFile, namespace } = file;
if (
sourceFile.includes('package-info.java') ||
const isKotlinGeneratorFile = file => file.namespace === 'jhipster-kotlin:spring-boot';

application.customizeTemplatePaths.unshift(
// Remove package-info.java files
file => (file.sourceFile.includes('package-info.java') ? undefined : file),
file => {
// Don't use liquibase.gradle from liquibase generator
if (['gradle/liquibase.gradle'].includes(file.sourceFile)) return undefined;
// Passthrough non liquibase files
if (!file.sourceFile.includes('src/main/resources/config/liquibase')) return file;
// Use master.xml from jhipster 7 templates
if (file.sourceFile.includes('master.xml')) return file.namespace === 'jhipster:liquibase' ? undefined : file;
// Use liquibase templates from liquibase generator
return file.namespace === 'jhipster:liquibase' ? file : undefined;
},
// Use docker-compose files from docker generator
file =>
isKotlinGeneratorFile(file) &&
file.sourceFile.includes('src/main/docker') &&
!file.sourceFile.includes('src/main/docker/jhipster-control-center.yml') &&
!file.sourceFile.includes('src/main/docker/jib') &&
!file.sourceFile.includes('src/main/docker/grafana') &&
!file.sourceFile.includes('src/main/docker/monitoring.yml')
? undefined
: file,
// Use wrappers scripts from maven/gradle generators
file =>
isKotlinGeneratorFile(file) &&
([('mvnw', 'mvnw.cmd', 'gradlew', 'gradlew.bat')].includes(file.sourceFile) ||
file.sourceFile.includes('.mvnw') ||
file.sourceFile.includes('gradle/wrapper/'))
? undefined
: file,
// Ignore files from generators
file =>
[
'jhipster:java:domain',
'jhipster:spring-cloud:gateway',
Expand All @@ -116,69 +140,36 @@ export default class extends BaseApplicationGenerator {
'jhipster:spring-data-mongodb',
'jhipster:spring-data-neo4j',
'jhipster:spring-data-relational',
].includes(namespace)
) {
return undefined;
}

// Use master.xml from jhipster 7 templates
if (sourceFile.includes('master.xml')) {
return namespace === 'jhipster:liquibase' ? undefined : file;
}

if (namespace === 'jhipster-kotlin:spring-boot') {
].includes(file.namespace)
? undefined
: file,
// Kotling blueprint does not implements these files
file => {
const sourceBasename = basename(file.sourceFile);
return ['_persistClass_Asserts.java', '_persistClass_TestSamples.java'].includes(sourceBasename) ? undefined : file;
},
file => {
let { resolvedSourceFile, sourceFile, destinationFile, namespace } = file;
// Already resolved kotlin files
if (resolvedSourceFile.endsWith('.kt') || resolvedSourceFile.includes('.kt.')) {
return file;
}

// Use docker-compose files from docker generator
if (
sourceFile.includes('src/main/docker') &&
!sourceFile.includes('src/main/docker/jhipster-control-center.yml') &&
!sourceFile.includes('src/main/docker/jib') &&
!sourceFile.includes('src/main/docker/grafana') &&
!sourceFile.includes('src/main/docker/monitoring.yml')
) {
return undefined;
}

// Use wrappers scripts from maven/gradle generators
if (
['mvnw', 'mvnw.cmd', 'gradlew', 'gradlew.bat'].includes(sourceFile) ||
sourceFile.includes('.mvnw') ||
sourceFile.includes('gradle/wrapper/')
) {
return undefined;
}

// Use liquibase templates from liquibase generator
if (sourceFile.includes('src/main/resources/liquibase')) {
return undefined;
if (sourceFile.includes('.java')) {
sourceFile = isKotlinGeneratorFile(file)
? convertToKotlinFile(sourceFile)
: join(namespace.split(':').pop(), convertToKotlinFile(sourceFile));
return {
...file,
sourceFile,
javaResolvedSourceFile: resolvedSourceFile,
resolvedSourceFile: this.templatePath(sourceFile),
destinationFile: convertToKotlinFile(destinationFile),
};
}
}

// Don't use liquibase.gradle from liquibase generator
if (['gradle/liquibase.gradle'].includes(sourceFile)) {
return undefined;
}

/*
// Ignore convention plugins
if (sourceFile.includes('buildSrc')) {
return undefined;
}
*/

if (sourceFile.includes('.java')) {
return {
...file,
resolvedSourceFile: this.templatePath(convertToKotlinFile(sourceFile)),
destinationFile: convertToKotlinFile(destinationFile),
};
}
return file;
});
return file;
},
);
},
async migration({ application, applicationDefaults }) {
// Downgrade elasticsearch to 7.17.4
Expand Down Expand Up @@ -284,6 +275,16 @@ export default class extends BaseApplicationGenerator {
entity.jpaMetamodelFiltering = false;
}
},
prepareEntityForKotlin({ entity }) {
const { primaryKey } = entity;
if (primaryKey && primaryKey.name === 'id') {
// Kotlin does not support string ids specifications.
primaryKey.javaBuildSpecification = 'buildRangeSpecification';
for (const field of primaryKey.fields) {
field.fieldJavaBuildSpecification = 'buildRangeSpecification';
}
}
},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package <%= packageName %>.repository

import <%= packageName %>.domain.PersistentToken
import <%= packageName %>.domain.<%= asEntity('User') %>
import <%= packageName %>.domain.<%= user.persistClass %>
import org.springframework.data.couchbase.repository.CouchbaseRepository
import java.util.List
import java.util.Optional
Expand All @@ -37,7 +37,7 @@ interface PersistentTokenRepository: CouchbaseRepository<PersistentToken, String
fun deleteBySeries(series: String) = deleteById(series)

@JvmDefault
fun findByUser(user: <%= asEntity('User') %>) = findByLogin(user.login)
fun findByUser(user: <%= user.persistClass %>) = findByLogin(user.login)

fun findByLogin(login: String): List<PersistentToken>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ webTestClient
.expectStatus()
.isOk
<%_ } else { _%>
rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, partialUpdated<%= persistClass %>.<%= primaryKey.name %>)<% if (testsNeedCsrf) { %>.with(csrf())<% }%>
rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, partialUpdated<%= persistClass %>.<%= primaryKey.name %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%>
.contentType("application/merge-patch+json")
.content(convertObjectToJsonBytes(<%= 'partialUpdated' + persistClass %>)))
.andExpect(status().isOk)
Expand Down
Loading
Loading