Skip to content

Commit

Permalink
do not ignore java files
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 5, 2025
1 parent 546c82d commit f01d519
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
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/');
};
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

0 comments on commit f01d519

Please sign in to comment.