@@ -4,11 +4,12 @@ import { extname } from 'node:path';
4
4
import { passthrough } from '@yeoman/transform' ;
5
5
import { isFileStateDeleted , isFileStateModified } from 'mem-fs-editor/state' ;
6
6
import ServerGenerator from 'generator-jhipster/generators/base-application' ;
7
- import { javaMainPackageTemplatesBlock , addJavaAnnotation } from 'generator-jhipster/generators/java/support' ;
7
+ import { javaMainPackageTemplatesBlock , addJavaAnnotation , addJavaImport } from 'generator-jhipster/generators/java/support' ;
8
8
import { lt as semverLessThan } from 'semver' ;
9
9
10
10
import { NATIVE_BUILDTOOLS_VERSION } from '../../lib/constants.js' ;
11
11
import { mavenDefinition } from './support/index.js' ;
12
+ import { createNeedleCallback } from 'generator-jhipster/generators/base/support' ;
12
13
13
14
export default class extends ServerGenerator {
14
15
blueprintVersion ;
@@ -31,6 +32,33 @@ export default class extends ServerGenerator {
31
32
} ) ;
32
33
}
33
34
35
+ get [ ServerGenerator . PREPARING ] ( ) {
36
+ return this . asPreparingTaskGroup ( {
37
+ addNativeHint ( { source, application } ) {
38
+ source . addNativeHint = ( { publicConstructors = [ ] , declaredConstructors = [ ] } ) => {
39
+ this . editFile (
40
+ `${ application . javaPackageSrcDir } config/NativeConfiguration.java` ,
41
+ addJavaImport ( 'org.springframework.aot.hint.MemberCategory' ) ,
42
+ createNeedleCallback ( {
43
+ contentToAdd : [
44
+ ...publicConstructors . map (
45
+ classPath =>
46
+ `hints.reflection().registerType(${ classPath } , (hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));` ,
47
+ ) ,
48
+ ...declaredConstructors . map (
49
+ classPath =>
50
+ `hints.reflection().registerType(${ classPath } , (hint) -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));` ,
51
+ ) ,
52
+ ] ,
53
+ needle : 'add-native-hints' ,
54
+ ignoreWhitespaces : true ,
55
+ } ) ,
56
+ ) ;
57
+ } ;
58
+ } ,
59
+ } ) ;
60
+ }
61
+
34
62
get [ ServerGenerator . DEFAULT ] ( ) {
35
63
return this . asDefaultTaskGroup ( {
36
64
// workaround for https://github.com/spring-projects/spring-boot/issues/32195
@@ -128,13 +156,37 @@ export default class extends ServerGenerator {
128
156
129
157
get [ ServerGenerator . POST_WRITING ] ( ) {
130
158
return this . asPostWritingTaskGroup ( {
131
- hints ( { application : { mainClass, javaPackageSrcDir, packageName } } ) {
159
+ hints ( { application, source } ) {
160
+ const { mainClass, javaPackageSrcDir, packageName } = application ;
161
+
132
162
this . editFile ( `${ javaPackageSrcDir } ${ mainClass } .java` , { assertModified : true } , contents =>
133
163
addJavaAnnotation ( contents , { package : 'org.springframework.context.annotation' , annotation : 'ImportRuntimeHints' } ) . replaceAll (
134
164
'@ImportRuntimeHints\n' ,
135
165
`@ImportRuntimeHints({ ${ packageName } .config.NativeConfiguration.JHipsterNativeRuntimeHints.class })\n` ,
136
166
) ,
137
167
) ;
168
+
169
+ if ( application . databaseMigrationLiquibase ) {
170
+ // Latest liquibase version supported by Reachability Repository is 4.23.0
171
+ // Hints may be dropped if newer version is supported
172
+ // https://github.com/oracle/graalvm-reachability-metadata/blob/master/metadata/org.liquibase/liquibase-core/index.json
173
+ source . addNativeHint ( {
174
+ publicConstructors : [ 'liquibase.ui.LoggerUIService.class' ] ,
175
+ declaredConstructors : [
176
+ 'liquibase.database.LiquibaseTableNamesFactory.class' ,
177
+ 'liquibase.report.ShowSummaryGeneratorFactory.class' ,
178
+ ] ,
179
+ } ) ;
180
+ }
181
+
182
+ if ( application . databaseTypeSql && ! application . reactive ) {
183
+ // Latest hibernate-core version supported by Reachability Repository is 6.5.0.Final
184
+ // Hints may be dropped if newer version is supported
185
+ // https://github.com/oracle/graalvm-reachability-metadata/blob/master/metadata/org.hibernate.orm/hibernate-core/index.json
186
+ source . addNativeHint ( {
187
+ publicConstructors : [ 'org.hibernate.binder.internal.BatchSizeBinder.class' ] ,
188
+ } ) ;
189
+ }
138
190
} ,
139
191
140
192
async packageJson ( { application : { buildToolMaven, buildToolGradle } } ) {
@@ -243,16 +295,14 @@ import org.springframework.security.oauth2.core.oidc.user.OidcUser;`,
243
295
// workaround for arch error in backend:unit:test caused by gradle's org.graalvm.buildtools.native plugin
244
296
technicalStructureTest ( { application : { buildToolGradle, javaPackageTestDir } } ) {
245
297
if ( ! buildToolGradle ) return ;
246
- this . editFile ( `${ javaPackageTestDir } /TechnicalStructureTest.java` , { assertModified : true } , contents =>
247
- contents . includes ( '__BeanFactoryRegistrations' )
248
- ? contents
249
- : contents
250
- . replace (
251
- 'import static com.tngtech.archunit.core.domain.JavaClass.Predicates.belongToAnyOf;' ,
252
- `import static com.tngtech.archunit.core.domain.JavaClass.Predicates.belongToAnyOf;
253
- import static com.tngtech.archunit.core.domain.JavaClass.Predicates.simpleNameEndingWith;` ,
254
- )
255
- . replace (
298
+ this . editFile (
299
+ `${ javaPackageTestDir } /TechnicalStructureTest.java` ,
300
+ { assertModified : true } ,
301
+ addJavaImport ( 'com.tngtech.archunit.core.domain.JavaClass.Predicates.simpleNameEndingWith' ) ,
302
+ contents =>
303
+ contents . includes ( '__BeanFactoryRegistrations' )
304
+ ? contents
305
+ : contents . replace (
256
306
'.ignoreDependency(belongToAnyOf' ,
257
307
`.ignoreDependency(simpleNameEndingWith("_BeanFactoryRegistrations"), alwaysTrue())
258
308
.ignoreDependency(belongToAnyOf` ,
0 commit comments