Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into spring-boot-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Aug 8, 2024
2 parents 01e56e4 + bb35169 commit 510195a
Show file tree
Hide file tree
Showing 15 changed files with 430 additions and 116 deletions.
4 changes: 4 additions & 0 deletions .blueprint/cli/commands.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const defaultCommands = {
desc: 'Generate a test sample',
blueprint: '@jhipster/jhipster-dev',
},
synchronize: {
desc: 'Synchronize templates from generator-jhipster',
blueprint: '@jhipster/jhipster-dev',
},
};

export default defaultCommands;
40 changes: 40 additions & 0 deletions .blueprint/synchronize/command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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.
*/
const command = {
configs: {
newFiles: {
description: 'Add new files only',
cli: {
type: Boolean,
},
scope: 'generator',
},
convert: {
description: 'Apply Partial Java files to Kotlin files convertion',
cli: {
type: Boolean,
alias: 'c',
},
scope: 'generator',
},
},
import: [],
};

export default command;
88 changes: 88 additions & 0 deletions .blueprint/synchronize/generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* 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.
*/
import { basename, dirname, join, relative } from 'path';
import { fileURLToPath } from 'url';
import { existsSync } from 'fs';
import BaseGenerator from 'generator-jhipster/generators/base';
import { globby } from 'globby';
import { passthrough } from '@yeoman/transform';
import { convertToKotlinFile } from '../../generators/kotlin/support/index.js';

const __dirname = dirname(fileURLToPath(import.meta.url));
const jhipster8Generators = join(__dirname, '../../node_modules/generator-jhipster/dist/generators');

export default class SynchronizeGenerator extends BaseGenerator {
constructor(args, options, features) {
super(args, options, { queueCommandTasks: true, ...features });
}

get [BaseGenerator.DEFAULT]() {
return this.asDefaultTaskGroup({
default() {
if (this.options.convert === false) {
return;
}
this.queueTransformStream(
{
name: 'convert to kt file',
filter: file => file.path.endsWith('.kt.ejs'),
},
passthrough(file => {
file.contents = Buffer.from(
file.contents
.toString()
.replaceAll(';\n', '\n')
.replaceAll('\nimport static ', '\nimport ')
.replaceAll('public class ', 'class ')
.replaceAll('.class', '::class')
.replaceAll(/ (?:extends|implements) (\w+)/g, ' : $1')
.replaceAll(/ (?:extends|implements) /g, ' : ')
.replaceAll(/@Override\n(\s*)/g, 'override ')
.replaceAll(/\n( {4})(private |)?(?:final )?(\w+) (\w+)(\n| = )/g, '\n$1$2lateinit var $4: $3$5')
.replaceAll(/private static final (\w+) /g, 'private val ')
.replaceAll(/(?:public |protected )?(\w+) (\w+)\((.*)\) {/g, 'fun $2($3): $1 {')
.replaceAll(': void', ''),
);
}),
);
},
});
}

get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async writing() {
const files = await globby(`${jhipster8Generators}/**/*.java.ejs`);
const ktTemplatesPath = this.destinationPath('generators/spring-boot/templates');
for (const file of files.filter(
file => !file.includes('/spring-data-couchbase/') && !['GeneratedByJHipster.java.ejs'].includes(basename(file)),
)) {
const relativeDestinationFile = convertToKotlinFile(relative(jhipster8Generators, file))
.replace('spring-boot/templates/', '')
.replace('server/templates/', '')
.replace(/(?:(?:.*)\/generators\/)?(.*)\/templates/, '$1');
const destinationFile = join(ktTemplatesPath, relativeDestinationFile);
if (this.options.newFiles !== true || !existsSync(destinationFile)) {
this.copyTemplate(file, destinationFile);
}
}
},
});
}
}
20 changes: 20 additions & 0 deletions .blueprint/synchronize/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* 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.
*/
export { default } from './generator.js';
export { default as command } from './command.js';
2 changes: 1 addition & 1 deletion .yo-resolve
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
generators/**
generators/*.*
.prettierrc.yml skip
cli/cli.cjs skip
README.md skip
21 changes: 15 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

## To run the application in development

### Step 1 👍 : install [yeoman](https://yeoman.io/)

`npm install -g yo | yarn global add yo`

### Step 2 ✌️ : to setup JHipster-Kotlin generator
### Step 1 ✌️ : to setup JHipster-Kotlin generator

`git clone https://github.com/jhipster/jhipster-kotlin`

Expand All @@ -18,7 +14,7 @@

( 🏁 Kudos, you just setup JHipster-Kotlin and linked to it locally )

### Step 3 🤟 : before generating your application, go to your application folder
### Step 2 🤟 : before generating your application, go to your application folder

`yarn link "generator-jhipster-kotlin"`

Expand All @@ -32,6 +28,19 @@ or

Fix / Code / Document and create a pull request 💯

### Synchronizing generator-jhipster templates

Run:

```sh
khipster synchronize
```

In the conflict resolution, check diff and press `i` if the template is synchronized.
`i` choice will add that file to be ignored in `.yo-resolve` file.

When synchronization is done revert `.yo-resolve` file to the initial previous state.

### Regular Contributor Guidelines

These are some of the guidelines that we would like you to follow if you are a regular contributor to the project
Expand Down
3 changes: 2 additions & 1 deletion generators/spring-boot-v2/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,14 @@ export default class extends BaseApplicationGenerator {
{
templates: [
{
file: `${SERVER_MAIN_SRC_KOTLIN_DIR}_package_/domain/enumeration/Enum.kt`,
file: `${SERVER_MAIN_SRC_KOTLIN_DIR}_package_/_entityPackage_/domain/enumeration/_enumName_.kt`,
renameTo: () =>
`${SERVER_MAIN_SRC_KOTLIN_DIR}${entity.entityAbsoluteFolder}/domain/enumeration/${field.fieldType}.kt`,
},
],
},
],
rootTemplatesPath: ['../../spring-boot/templates/domain/'],
context: enumInfo,
});
}
Expand Down
3 changes: 0 additions & 3 deletions generators/spring-boot/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ export default class extends BaseApplicationGenerator {

const isCommonFile = filename => {
const sourceBasename = basename(filename);
if (['_entityClass_Repository.kt', '_entityClass_Repository_reactive.kt'].includes(sourceBasename)) {
return ns !== 'spring-data-couchbase';
}
return ['TestContainersSpringContextCustomizerFactory.kt'].includes(sourceBasename);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%#
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 "
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://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.cassandra.repository.<% if (reactive) { %>Reactive<% } %>CassandraRepository
import org.springframework.stereotype.Repository
<%_ if (primaryKey.typeUUID) { _%>
import java.util.UUID
<%_ } _%>
/**
* <%= springDataDescription %> repository for the <%= persistClass %> entity.
*/
@Repository
interface <%= entityClass %>Repository: <% if (reactive) { %>Reactive<% } %>CassandraRepository<<%= persistClass %>, <%= primaryKey.type %>> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<%#
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 "
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://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 %>
<%_ if (implementsEagerLoadApis) { _%>
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
<%_ } _%>
import org.springframework.data.mongodb.repository.Query
import org.springframework.data.mongodb.repository.MongoRepository
import org.springframework.stereotype.Repository
<%_ if (implementsEagerLoadApis) { _%>
import java.util.Optional
<%_ } _%>
<%_ if (primaryKey.typeUUID) { _%>
import java.util.UUID
<%_ } _%>
/**
* <%= springDataDescription %> repository for the <%= persistClass %> entity.
*/
<%_ if (!implementsEagerLoadApis) { _%>
@Suppress("unused")
<%_ } _%>
@Repository
interface <%=entityClass%>Repository : MongoRepository<<%=persistClass%>, <%= primaryKey.type %>> {
<%_ if (implementsEagerLoadApis) { _%>
@Query("{}")
fun findAllWithEagerRelationships(pageable: Pageable): Page<<%= persistClass %>>
@Query("{}")
fun findAllWithEagerRelationships(): MutableList<<%= persistClass %>>
@Query("{'id': ?0}")
fun findOneWithEagerRelationships(id: <%= primaryKey.type %>): Optional<<%= persistClass %>>
<%_ } _%>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<%#
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 "
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://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 %>
<%_ if (!paginationNo || implementsEagerLoadApis) { _%>
import org.springframework.data.domain.Pageable
<%_ } _%>
<%_ if (implementsEagerLoadApis) { _%>
import org.springframework.data.mongodb.repository.Query
<%_ } _%>
import org.springframework.data.mongodb.repository.ReactiveMongoRepository
import org.springframework.stereotype.Repository
<%_ if (!paginationNo || implementsEagerLoadApis) { _%>
import reactor.core.publisher.Flux
<%_ } _%>
<%_ if (implementsEagerLoadApis) { _%>
import reactor.core.publisher.Mono
<%_ } _%>
<%_ if (primaryKey.typeUUID) { _%>
import java.util.UUID
<%_ } _%>
/**
* <%= springDataDescription %> repository for the <%= persistClass %> entity.
*/
@SuppressWarnings("unused")
@Repository
interface <%= entityClass %>Repository: ReactiveMongoRepository<<%= persistClass %>, <%= primaryKey.type %>> {
<%_ if (!paginationNo) { _%>
fun findAllBy(pageable: Pageable?): Flux<<%= persistClass %>>
<%_ } _%>
<%_ if (implementsEagerLoadApis) { _%>
@Query("{}")
fun findAllWithEagerRelationships(pageable: Pageable): Flux<<%= persistClass %>>
@Query("{}")
fun findAllWithEagerRelationships(): Flux<<%= persistClass %>>
@Query("{'id': ?0}")
fun findOneWithEagerRelationships(id: <%= primaryKey.type %>): Mono<<%= persistClass %>>
<%_ } _%>
}
Loading

0 comments on commit 510195a

Please sign in to comment.